private CRole getRole(String id, List<CRole> roles) { for (CRole role : roles) { if (role.getId().equals(id)) { return role; } } return null; }
protected void rebuildId2RolesLookupMap() { id2roles.clear(); for ( CRole role : delegate.getRoles() ) { id2roles.put( role.getId(), role ); } }
public void removeRole( final CRole cRole ) { id2roles.remove( cRole.getId() ); delegate.removeRole( cRole ); }
public CRole getCRole(String roleId) throws IOException { Configuration securityConfig = getSecurityConfig(); List<CRole> secRoles = securityConfig.getRoles(); for (Iterator<CRole> iter = secRoles.iterator(); iter.hasNext(); ) { CRole cRole = iter.next(); if (roleId.equals(cRole.getId())) { return cRole; } } return null; }
public void addRole( final CRole cRole ) { final CRole cr = cRole.clone(); delegate.addRole( cr ); id2roles.put( cr.getId(), cr ); }
public void privilegeRemoved( EnhancedConfiguration configuration, String privilegeId ) { logger.debug( "Cleaning privilege id {} from roles.", privilegeId ); List<CRole> roles = configuration.getRoles(); for ( CRole role : roles ) { if ( role.getPrivileges().contains( privilegeId ) ) { logger.debug( "removing privilege {} from role {}", privilegeId, role.getId() ); role.getPrivileges().remove( privilegeId ); configuration.removeRoleById( role.getId() ); configuration.addRole( role ); } } }
/** * Verify the list of roles contains all roles configured in security.xml */ public void verifyRolesComplete(List<RoleResource> roles) throws IOException { for (CRole cRole : getSecurityConfig().getRoles()) { RoleResource roleResource = getRoleResource(cRole.getId(), roles); if (cRole.getId().endsWith("-view")) { // view roles privileges are added at runtime by listening to repository events. Which it is not // possible to do here continue; } Assert.assertNotNull("Role '" + cRole.getId() + "' should be contained!", roleResource); CRole role = RoleConverter.toCRole(roleResource); assertRoleEquals(cRole, role); } }
protected RoleIdentifier toRole( String roleId ) { if ( roleId == null ) { return null; } try { CRole role = configuration.readRole( roleId ); RoleIdentifier roleIdentifier = new RoleIdentifier( SOURCE, role.getId() ); return roleIdentifier; } catch ( NoSuchRoleException e ) { return null; } }
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; }
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 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; }
protected Role toRole( CRole secRole ) { Role role = new Role(); role.setRoleId( secRole.getId() ); role.setName( secRole.getName() ); role.setSource( SOURCE ); role.setDescription( secRole.getDescription() ); role.setReadOnly( secRole.isReadOnly() ); role.setPrivileges( new HashSet<String>( secRole.getPrivileges() ) ); role.setRoles( new HashSet<String>( secRole.getRoles() ) ); return role; }
public void updateRole( CRole role, SecurityValidationContext context ) throws InvalidConfigurationException, NoSuchRoleException { if ( context == null ) { context = initializeContext(); } ValidationResponse vr = validator.validateRole( context, role, true ); if ( vr.isValid() ) { deleteRole( role.getId(), false ); getConfiguration().addRole( role ); logValidationWarnings( vr ); } else { throw new InvalidConfigurationException( vr ); } }
newRole.setId( roleA.getId() ); newRole.setRoles( new ArrayList<String>( roles ) ); newRole.setPrivileges( new ArrayList<String>( privs ) );
private void addStaticSecurity(Configuration configuration, Configuration staticConfiguration) { for (CPrivilege priv : staticConfiguration.getPrivileges()) { CPrivilege p = getPrivilege(priv.getId(), configuration.getPrivileges()); if (p == null) { configuration.addPrivilege(priv); } } for (CRole role : staticConfiguration.getRoles()) { CRole existingRole = getRole(role.getId(), configuration.getRoles()); if (existingRole != null) { for (String containedRole : role.getRoles()) { if (!existingRole.getRoles().contains(containedRole)) { existingRole.addRole(containedRole); } } for (String containedPriv : role.getPrivileges()) { if (!existingRole.getPrivileges().contains(containedPriv)) { existingRole.addPrivilege(containedPriv); } } } else { configuration.addRole(role); } } }