for ( CUserRoleMapping roleMapping : roleMappings ) if ( !SOURCE.equals( roleMapping.getSource() ) ) if ( matchesCriteria( roleMapping.getUserId(), roleMapping.getSource(), roleMapping.getRoles(), criteria ) ) User user = getSecuritySystem().getUser( roleMapping.getUserId(), roleMapping.getSource() ); users.add( user ); logger.debug( "User: '" + roleMapping.getUserId() + "' of source: '" + roleMapping.getSource() + "' could not be found.", e ); logger.warn( "User: '" + roleMapping.getUserId() + "' of source: '" + roleMapping.getSource() + "' could not be found.", e );
private CUserRoleMapping buildUserRoleMapping( String userId, Set<String> roles ) { CUserRoleMapping roleMapping = new CUserRoleMapping(); roleMapping.setUserId( userId ); roleMapping.setSource( SecurityXmlUserManager.SOURCE ); roleMapping.setRoles( new ArrayList<String>( roles ) ); return roleMapping; }
public void roleRemoved( EnhancedConfiguration configuration, String roleId ) { logger.debug( "Cleaning role id {} from users and roles.", roleId ); List<CRole> roles = configuration.getRoles(); for ( CRole role : roles ) { if ( role.getRoles().contains( roleId ) ) { logger.debug( "removing ref to role {} from role {}", roleId, role.getId() ); role.getRoles().remove( roleId ); configuration.removeRoleById( role.getId() ); configuration.addRole( role ); } } List<CUserRoleMapping> mappings = configuration.getUserRoleMappings(); for ( CUserRoleMapping mapping : mappings ) { if ( mapping.getRoles().contains( roleId ) ) { logger.debug( "removing ref to role {} from user {}", mapping.getUserId() ); mapping.removeRole( roleId ); configuration.removeUserRoleMappingByUserId( mapping.getUserId(), mapping.getSource() ); configuration.addUserRoleMapping( mapping ); } } } }
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 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; }
CUserRoleMapping roleMapping = new CUserRoleMapping(); roleMapping.setUserId( userId ); roleMapping.setSource( userSource ); roleMapping.addRole( roleIdentifier.getRoleId() );
public Set<String> listUserIds() { Set<String> userIds = new HashSet<String>(); Set<User> users = new HashSet<User>(); for ( User user : users ) { userIds.add( user.getUserId() ); } List<CUserRoleMapping> userRoleMappings = this.configuration.listUserRoleMappings(); for ( CUserRoleMapping userRoleMapping : userRoleMappings ) { String userId = userRoleMapping.getUserId(); if ( StringUtils.isNotEmpty( userId ) ) { userIds.add( userId ); } } return userIds; }
public CUserRoleMapping getUserRoleMappingByUserId( final String id, final String source, final boolean clone ) { final CUserRoleMapping mapping = id2roleMappings.get( getUserRoleMappingKey( id, source ) ); if ( mapping != null ) { return clone ? mapping.clone() : mapping; } else { return null; } }
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 Set<User> listUsers() { Set<User> users = new HashSet<User>(); List<CUserRoleMapping> userRoleMappings = this.configuration.listUserRoleMappings(); for ( CUserRoleMapping userRoleMapping : userRoleMappings ) { if ( SOURCE.equals( userRoleMapping.getSource() ) ) { User user = null; if ( userRoleMapping.getRoles().contains( this.urlRealmConfiguration.getConfiguration().getDefaultRole() ) ) { user = this.toUser( userRoleMapping.getUserId(), false ); } else { user = this.toUser( userRoleMapping.getUserId(), true ); } if ( user != null ) { users.add( user ); } } } return users; }
public Set<String> listUserIds() { Set<String> userIds = new HashSet<String>(); List<CUserRoleMapping> userRoleMappings = this.configuration.listUserRoleMappings(); for ( CUserRoleMapping userRoleMapping : userRoleMappings ) { if ( SOURCE.equals( userRoleMapping.getSource() ) ) { String userId = userRoleMapping.getUserId(); if ( StringUtils.isNotEmpty( userId ) ) { userIds.add( userId ); } } } return userIds; }
public void run() throws Exception { CUserRoleMapping roleMapping; try { roleMapping = configuration.readUserRoleMapping( userId, source ); if ( roleMapping != null ) { for ( String roleId : (List<String>) roleMapping.getRoles() ) { RoleIdentifier role = toRole( roleId ); if ( role != null ) { roles.add( role ); } } } } catch ( NoSuchRoleMappingException e ) { logger.debug( "No user role mapping found for user: " + userId ); } } });
public Set<User> listUsers() { Set<User> users = new HashSet<User>(); List<CUserRoleMapping> userRoleMappings = this.configuration.listUserRoleMappings(); for ( CUserRoleMapping userRoleMapping : userRoleMappings ) { try { User user = this.getSecuritySystem().getUser( userRoleMapping.getUserId(), userRoleMapping.getSource() ); if ( user != null ) { users.add( user ); } } catch ( UserNotFoundException e ) { this.logger.warn( "User: '" + userRoleMapping.getUserId() + "' of source: '" + userRoleMapping.getSource() + "' could not be found." ); this.logger.debug( "Most likely caused by a user role mapping that is invalid.", e ); } catch ( NoSuchUserManagerException e ) { this.logger.warn( "User: '" + userRoleMapping.getUserId() + "' of source: '" + userRoleMapping.getSource() + "' could not be found.", e ); } } return users; }
if (userRoleMappings != null && userRoleMappings.size() > 0) { for (final CUserRoleMapping userRoleMapping : userRoleMappings) { final List<String> userRoleMappingRoles = userRoleMapping.getRoles(); if (userRoleMappingRoles != null && userRoleMappingRoles.size() > 0) { final List<String> newRoles = Lists.newArrayList(); userRoleMapping.getRoles().clear(); userRoleMapping.getRoles().addAll(newRoles);
private void createOrUpdateUserRoleMapping( CUserRoleMapping roleMapping ) { // delete first, ask questions later // we are always updating, its possible that this object could have already existed, because we cannot fully // sync with external realms. try { deleteUserRoleMapping( roleMapping.getUserId(), roleMapping.getSource() ); } catch ( NoSuchRoleMappingException e ) { // it didn't exist, thats ok. } // now add it getConfiguration().addUserRoleMapping( roleMapping ); }
@Override public void doUpgrade( Configuration cfg ) throws ConfigurationIsCorruptedException { for ( CRole role : cfg.getRoles() ) { updateDeprecatedRoles( role.getRoles() ); } for ( CUserRoleMapping map : cfg.getUserRoleMappings() ) { updateDeprecatedRoles( map.getRoles() ); } }
public void updateUserRoleMapping( CUserRoleMapping userRoleMapping, SecurityValidationContext context ) throws InvalidConfigurationException, NoSuchRoleMappingException { if ( context == null ) { context = initializeContext(); } if ( readUserRoleMapping( userRoleMapping.getUserId(), userRoleMapping.getSource() ) == null ) { ValidationResponse vr = new ValidationResponse(); vr.addValidationError( new ValidationMessage( "*", "No User Role Mapping found for user '" + userRoleMapping.getUserId() + "'." ) ); throw new InvalidConfigurationException( vr ); } ValidationResponse vr = validator.validateUserRoleMapping( context, userRoleMapping, true ); if ( vr.getValidationErrors().size() > 0 ) { throw new InvalidConfigurationException( vr ); } deleteUserRoleMapping( userRoleMapping.getUserId(), userRoleMapping.getSource() ); getConfiguration().addUserRoleMapping( userRoleMapping ); }