mapJsonToObjectList(new UserRole(),s,UserRole.class);
private List<Map> updateUserRole( @ApiParam(required = true) UserRoleList userRoleList, @HeaderParam(AUTHORIZATION) @ApiParam(value = EXAMPLE_AUTHORIZATION_HEADER, required = true) String authorizationHeader) { Username subject = authorization.getUser(authorizationHeader); UserInfo admin = authorization.getUserInfo(subject); List<Map> status = newArrayList(); for (UserRole userRole : userRoleList.getRoleList()) { try { authorization.checkUserPermissions(subject, userRole.getApplicationName(), ADMIN); status.add(authorization.setUserRole(userRole, admin)); } catch (AuthenticationException e) { LOGGER.error("Unable to check user permissions", e); status.add(ImmutableMap.<String, String>builder() .put("applicationName", userRole.getApplicationName().toString()) .put("userID", userRole.getUserID().toString()) .put("role", userRole.getRole().toString()) .put("roleAssignmentStatus", "FAILED") .put("reason", "Not Authorized").build()); } } return status; }
int minPriority = -1; for (UserRole userRole : userRoles) { dbRoles.add(userRole.getRole().getRoleName()); int rolePriority = userRole.getRole().getPriority(); if (rolePriority < minPriority || minPriority == -1) { minPriority = rolePriority; } for (RoleAction ra: userRole.getRole().getRoleActions()) { System.out.println("#########"+ra.getAction().getName()); System.out.println("@@@@@@@@@"+ra.getAction().getId()); map.put(ra.getAction().getName(), ra.getAction().getId()); } }
@Override public void removeUserFromSuperAdminRole(final UserInfo candidateUserInfo, final UserInfo assigningUserInfo) { LOGGER.debug("Removing user={} from superadmin by assigningUser={}", candidateUserInfo, assigningUserInfo); List<UserRole> allSuperAdmins = getSuperAdminRoleList(); LOGGER.debug("Current superadmins {}", allSuperAdmins); Preconditions.checkArgument(allSuperAdmins.size() > 1, "Cannot delete. SuperAdmins less than 1"); boolean isSuperAdmin = allSuperAdmins.stream().anyMatch((UserRole ur) -> ur.getRole().equals(Role.SUPERADMIN) && ur.getUserID().equals(candidateUserInfo.getUsername())); Preconditions.checkArgument(isSuperAdmin, "User %s is not a superadmin", candidateUserInfo.getUsername()); authorizationRepository.removeUserFromSuperAdminRole(candidateUserInfo); eventLog.postEvent(new AuthorizationChangeEvent(assigningUserInfo, null, candidateUserInfo, Role.SUPERADMIN.toString(), null)); }
/** * Returns the email adresses of the experiment admins. * * @param appName the application we want the admins from * @return a set of their valid email addresses */ private Set<String> getAdminEmails(Application.Name appName) { Set<String> adressors = new HashSet<>(); UserRoleList usersRoles = authorizationRepository.getApplicationUsers(appName); for (UserRole user : usersRoles.getRoleList()) { if (user.getRole() == Role.ADMIN) { String email = user.getUserEmail(); if (EmailValidator.getInstance().isValid(email)) { adressors.add(email); } else { LOGGER.warn("\"" + email + "\" is not a valid email address for one of the administrators of " + appName); } } } //no admins, no email! if (adressors.isEmpty()) { throw new WasabiEmailException("No Admins with an valid email registered for this Application"); } return adressors; }
UserRole userRole = newInstance(experiment.getApplicationName(), ADMIN).withUserID(userName).build();
authorization.checkUserPermissions(userName, userRole.getApplicationName(), ADMIN); authRoles.addRole(userRole); } catch (AuthenticationException ignored) {
@Override public void setUserRole(UserRole userRole) { BatchStatement batch = new BatchStatement(); batch.add(userRoleAccessor.insertUserRoleStatement( userRole.getUserID().toString(), userRole.getApplicationName().toString(), userRole.getRole().toString() )); batch.add(appRoleAccessor.insertAppRoleStatement( userRole.getApplicationName().toString(), userRole.getUserID().toString(), userRole.getRole().toString() )); manager.getSession().execute(batch); }
userpersis.getUserRole().clear(); // Let Hibernate know that we're really removing all the references for(UserRole role : user.getUserRole()) { userpersis.getUserRole().add(new UserRole(userpersis,role.getRole())); }
allAppNamesList.stream() .map(appName -> UserRole.newInstance(Application.Name.valueOf(appName), Role.SUPERADMIN) .withUserID(userID) .withUserEmail(userInfo.getEmail()) resultList.stream() .map( r -> UserRole.newInstance( Application.Name.valueOf(r.getAppName()), Role.toRole(r.getRole())
@Override public Map setUserRole(UserRole userRole, UserInfo admin) { Map<String, String> status = new HashMap<>(); status.put("applicationName", userRole.getApplicationName().toString()); status.put("userID", userRole.getUserID().toString()); status.put("role", userRole.getRole().toString()); List<Experiment> experimentList = experiments.getExperiments(userRole.getApplicationName()); List<UserRole> userRoleList = authorizationRepository.getUserRoleList(userRole.getUserID()).getRoleList(); Role oldRole = null; for (UserRole role : userRoleList) { if (role.getApplicationName().equals(userRole.getApplicationName())) { oldRole = role.getRole(); break; UserInfo user = getUserInfo(userRole.getUserID()); eventLog.postEvent(new AuthorizationChangeEvent(admin, userRole.getApplicationName(), user, oldRole == null || "superadmin".equalsIgnoreCase(oldRole.toString()) ? null : oldRole.toString(), userRole.getRole().toString())); } catch (RepositoryException e) { LOGGER.info("RepoitoryException for setting user Role in DefaultAuthorization ", e); status.put("reason", "No application named " + userRole.getApplicationName());
@Override protected Set<String> getRoleNamesForUser(Connection conn, String username) throws SQLException { Set<String> roleNames = new LinkedHashSet<>(); Collection<UserRole> roles = /* Get roles from your DB, this example use JPA entity, **but you put here any logic you want**...*/ for(UserRole userRole:roles){ roleNames.add(userRole.getRole().getName()); } return roleNames; // return roles so Shiro is 'aware' of roles to add them to current user }
UserRole userRole = newInstance(experiment.getApplicationName(), ADMIN).withUserID(userName).build();
public void createUserRole(String role) throws RoleAlreadyExistsException { try { UserRole userRole = new UserRole(role); em.persist(userRole); em.flush(); } catch (Exception e) { throw new RoleAlreadyExistsException(); } }
Set<UserRole> roles = new HashSet<UserRole> (); // Guess for roles, should be needed to load them also from the db for(UserRole role : user.getUserRole()) { roles.add(new UserRole(userpersis,role.getRole())); } userpersis.setUserRole(roles);
private UserRole getRoleWithUserInfo(com.intuit.wasabi.repository.cassandra.pojo.UserRole userRole) { LOGGER.debug("Getting user info for user role={}", userRole); Application.Name appName = userRole.getAppName().equals(ALL_APPLICATIONS) ? WILDCARD : Application.Name.valueOf(userRole.getAppName()); UserInfo userInfo = getUserInfo(UserInfo.Username.valueOf(userRole.getUserId())); UserRole roleWithUserInfo; if (nonNull(userInfo)) { roleWithUserInfo = UserRole.newInstance( appName, Role.toRole(userRole.getRole())). withUserID(UserInfo.Username.valueOf(userRole.getUserId())). withFirstName(userInfo.getFirstName()). withLastName(userInfo.getLastName()). withUserEmail(userInfo.getEmail()).build(); } else { roleWithUserInfo = UserRole.newInstance(appName, Role.toRole(userRole.getRole())) .withUserID(UserInfo.Username.valueOf(userRole.getUserId())).build(); } LOGGER.debug("Role with user info for user role={} is {}", userRole, roleWithUserInfo); return roleWithUserInfo; }
public static void main(String[] args) { IndexedCollection<User> users = new ConcurrentIndexedCollection<>(); users.add(new User(1, "Joe")); users.add(new User(2, "Jane")); users.add(new User(3, "Jesse")); IndexedCollection<Role> roles = new ConcurrentIndexedCollection<>(); roles.add(new Role(1, "CEO")); roles.add(new Role(2, "Manager")); roles.add(new Role(3, "Employee")); IndexedCollection<UserRole> userRoles = new ConcurrentIndexedCollection<>(); userRoles.add(new UserRole(1, 3)); // Joe is an Employee userRoles.add(new UserRole(2, 2)); // Jane is a Manager userRoles.add(new UserRole(3, 2)); // Jesse is a Manager // Retrieve Users who are managers... Query<User> usersWhoAreManagers = existsIn(userRoles, User.USER_ID, UserRole.USER_ID, existsIn(roles, UserRole.ROLE_ID, Role.ROLE_ID, equal(Role.ROLE_NAME, "Manager"))); users.retrieve(usersWhoAreManagers) .forEach(u -> System.out.println(u.userName)); // ..prints: Jane, Jesse }
for(UserRole userRole : userRoles){ System.out.println("called buildUserAuthority(Set<UserRole> userRoles) method....."); setAuths.add(new SimpleGrantedAuthority(userRole.getRole()));
UserRole convertAppRoleToUserRole(Application.Name applicationName, AppRole appRole) { Role role = Role.toRole(appRole.getRole()); UserInfo.Username userID = UserInfo.Username.valueOf(appRole.getUserId()); UserInfo userInfo = getUserInfo(userID); if (userInfo == null) { userInfo = lookupUser(userID); } return UserRole.newInstance(applicationName, role) .withUserID(userID) .withUserEmail(userInfo.getEmail()) .withFirstName(userInfo.getFirstName()) .withLastName(userInfo.getLastName()) .build(); }