public Set<String> listUserIds() { Set<String> userIds = new HashSet<String>(); for ( CUser user : configuration.listUsers() ) { userIds.add( user.getId() ); } return userIds; }
public void removeUser( final CUser cUser ) { id2users.remove( cUser.getId() ); delegate.removeUser( cUser ); }
protected void rebuildId2UsersLookupMap() { id2users.clear(); for ( CUser user : delegate.getUsers() ) { id2users.put( user.getId(), user ); } }
public void updateUser( CUser user ) throws InvalidConfigurationException, UserNotFoundException { Set<String> roles = new HashSet<String>(); try { CUserRoleMapping userRoleMapping = this.readUserRoleMapping( user.getId(), SecurityXmlUserManager.SOURCE ); roles.addAll( userRoleMapping.getRoles() ); } catch ( NoSuchRoleMappingException e ) { this.logger.debug( "User: {} has no roles", user.getId()); } this.updateUser(user, new HashSet<String>( roles )); }
public CUser getCUser(String userId) throws IOException { Configuration securityConfig = getSecurityConfig(); List<CUser> secUsers = securityConfig.getUsers(); for (Iterator<CUser> iter = secUsers.iterator(); iter.hasNext(); ) { CUser cUser = iter.next(); if (userId.equals(cUser.getId())) { return cUser; } } return null; }
public void updateUser( CUser user ) throws InvalidConfigurationException, UserNotFoundException { Set<String> roles = Sets.newHashSet(); try { CUserRoleMapping userRoleMapping = this.readUserRoleMapping( user.getId(), SecurityXmlUserManager.SOURCE ); roles.addAll( userRoleMapping.getRoles() ); } catch ( NoSuchRoleMappingException e ) { this.logger.debug( "User: {} has no roles", user.getId()); } this.updateUser( user, new HashSet<String>( roles ) ); }
public void addUser( final CUser cUser ) { final CUser cu = cUser.clone(); delegate.addUser( cu ); id2users.put( cu.getId(), cu ); }
private AuthenticationInfo createAuthenticationInfo(CUser user) { return new SimpleAuthenticationInfo( user.getId(), user.getPassword().toCharArray(), getName() ); } }
@Override public void run() throws Exception { try { user.setPassword(passwordService.encryptPassword(password)); configuration.updateUser(user); configuration.save(); } catch(Exception e) { //Update failed, rollback to previous values user.setPassword(currentPasswordHash); logger.error("Unable to update hash for user {}", user.getId()); } } });
public SecurityValidationContext initializeContext() { SecurityValidationContext context = new SecurityValidationContext(); context.addExistingUserIds(); context.addExistingRoleIds(); context.addExistingPrivilegeIds(); List<CUser> users = new ArrayList<CUser>( listUsers() ); for ( CUser user : users ) { context.getExistingUserIds().add( user.getId() ); context.getExistingEmailMap().put( user.getId(), user.getEmail() ); } List<CRole> roles = new ArrayList<CRole>( listRoles() ); for ( CRole role : roles ) { context.getExistingRoleIds().add( role.getId() ); ArrayList<String> containedRoles = new ArrayList<String>(); containedRoles.addAll( role.getRoles() ); context.getRoleContainmentMap().put( role.getId(), containedRoles ); context.getExistingRoleNameMap().put( role.getId(), role.getName() ); } List<CPrivilege> privs = new ArrayList<CPrivilege>( listPrivileges() ); for ( CPrivilege priv : privs ) { context.getExistingPrivilegeIds().add( priv.getId() ); } return context; }
protected User toUser( CUser cUser ) { if ( cUser == null ) { return null; } DefaultUser user = new DefaultUser(); user.setUserId( cUser.getId() ); user.setFirstName( cUser.getFirstName() ); user.setLastName( cUser.getLastName() ); user.setEmailAddress( cUser.getEmail() ); user.setSource( SOURCE ); user.setStatus( UserStatus.valueOf( cUser.getStatus() ) ); user.setReadOnly( false ); try { user.setRoles( this.getUsersRoles( cUser.getId(), SOURCE ) ); } catch ( UserNotFoundException e ) { // We should NEVER get here this.logger.warn( "Could not find user: '" + cUser.getId() + "' of source: '" + SOURCE + "' while looking up the users roles.", e ); } return user; }
public void updateUser( CUser user, Set<String> roles, SecurityValidationContext context ) throws InvalidConfigurationException, UserNotFoundException { if ( context == null ) { context = initializeContext(); } ValidationResponse vr = validator.validateUser( context, user, roles, true ); if ( vr.isValid() ) { deleteUser( user.getId() ); getConfiguration().addUser( user ); this.createOrUpdateUserRoleMapping( this.buildUserRoleMapping( user.getId(), roles ) ); logValidationWarnings( vr ); } else { throw new InvalidConfigurationException( vr ); } }
public SecurityValidationContext initializeContext() { SecurityValidationContext context = new SecurityValidationContext(); context.addExistingUserIds(); context.addExistingRoleIds(); context.addExistingPrivilegeIds(); for ( CUser user : listUsers() ) { context.getExistingUserIds().add( user.getId() ); context.getExistingEmailMap().put( user.getId(), user.getEmail() ); } for ( CRole role : listRoles() ) { context.getExistingRoleIds().add( role.getId() ); ArrayList<String> containedRoles = new ArrayList<String>(); containedRoles.addAll( role.getRoles() ); context.getRoleContainmentMap().put( role.getId(), containedRoles ); context.getExistingRoleNameMap().put( role.getId(), role.getName() ); } for ( CPrivilege priv : listPrivileges() ) { context.getExistingPrivilegeIds().add( priv.getId() ); } for ( CUserRoleMapping roleMappings : listUserRoleMappings() ) { context.getExistingUserRoleMap().put( roleMappings.getUserId(), roleMappings.getRoles() ); } return context; }
public void createUser( CUser user, String password, Set<String> roles, SecurityValidationContext context ) throws InvalidConfigurationException { if ( context == null ) { context = initializeContext(); } // set the password if its not null if ( password != null && password.trim().length() > 0 ) { user.setPassword(this.passwordService.encryptPassword(password)); } ValidationResponse vr = validator.validateUser( context, user, roles, false ); if ( vr.isValid() ) { getConfiguration().addUser( user ); createOrUpdateUserRoleMapping( buildUserRoleMapping( user.getId(), roles ) ); logValidationWarnings( vr ); } else { throw new InvalidConfigurationException( vr ); } }
if ( StringUtils.equals( systemConfigManager.getAnonymousUsername(), user.getId() ) )