public void assertRoleEquals(CRole roleA, CRole roleB) { // sort them, to not fail on same set but different order Collections.sort(roleA.getPrivileges()); Collections.sort(roleB.getPrivileges()); XStream xStream = new XStream(); String roleStringA = xStream.toXML(roleA); String roleStringB = xStream.toXML(roleB); Assert.assertTrue("Role A:\n" + roleStringB + "\nRole B:\n" + roleStringA, new RoleComparator().compare(roleA, roleB) == 0); }
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 ); } } }
final List<String> privilegeIds = role.getPrivileges(); for ( String privilegeId : privilegeIds )
role.getRoles().addAll(newRoles); final List<String> rolePrivileges = role.getPrivileges(); if (rolePrivileges != null && rolePrivileges.size() > 0) { final List<String> newPrivileges = Lists.newArrayList(); role.getPrivileges().clear(); role.getPrivileges().addAll(newPrivileges);
return -1; if (role1.getPrivileges() == null) { if (role2.getPrivileges() != null) { return -1; Set<String> role1Privileges = new HashSet<String>(role1.getPrivileges()); Set<String> role2Privileges = new HashSet<String>(role2.getPrivileges());
if ( roleA.getPrivileges() != null ) privs.addAll( roleA.getPrivileges() ); if ( roleB.getPrivileges() != null ) privs.addAll( roleB.getPrivileges() );
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; }
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); } } }
public static CRole toCRole(RoleResource resource) { CRole role = new CRole(); role.setId(resource.getId()); role.setDescription(resource.getDescription()); role.setName(resource.getName()); role.setSessionTimeout(resource.getSessionTimeout()); role.getRoles().clear(); for (String roleId : (List<String>) resource.getRoles()) { role.addRole(roleId); } role.getPrivileges().clear(); for (String privId : (List<String>) resource.getPrivileges()) { role.addPrivilege(privId); } return role; } }