if ( roleA.getRoles() != null ) roles.addAll( roleA.getRoles() ); if ( roleB.getRoles() != null ) roles.addAll( roleB.getRoles() ); if ( roleA.getPrivileges() != null ) privs.addAll( roleA.getPrivileges() ); if ( roleB.getPrivileges() != null ) privs.addAll( roleB.getPrivileges() ); CRole newRole = new CRole(); newRole.setId( roleA.getId() ); newRole.setRoles( new ArrayList<String>( roles ) ); newRole.setPrivileges( new ArrayList<String>( privs ) ); if ( StringUtils.isNotEmpty( roleA.getName() ) ) newRole.setName( roleA.getName() ); newRole.setName( roleB.getName() ); if ( StringUtils.isNotEmpty( roleA.getDescription() ) )
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; } }
private CRole buildRole( Entry<String, ContentClass> entry, String method ) { String content = entry.getKey(); CRole view = new CRole(); view.setId( content + "-all-" + method ); String contentClassName = entry.getValue().getName(); if ( entry.getValue() instanceof RootContentClass ) { // NXCM-3544 set name to empty string to generate 'All Repositories' role name/description contentClassName = ""; } view.setDescription( "Gives access to " + method + " ALL " + contentClassName + " Repositories in Nexus." ); method = StringUtils.capitalizeFirstLetter( method ); view.setName( "Repo: All " + contentClassName + " Repositories (" + method + ")" ); view.setSessionTimeout( 60 ); List<? extends Repository> repos = getRepositoriesWithContentClass( entry.getValue() ); for ( Repository repo : repos ) { view.addPrivilege( "repository-" + repo.getId() ); } return view; }
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; }
protected CRole toRole( Role role ) { CRole secRole = new CRole(); secRole.setId( role.getRoleId() ); secRole.setName( role.getName() ); secRole.setDescription( role.getDescription() ); secRole.setReadOnly( role.isReadOnly() ); // null check if ( role.getPrivileges() != null ) { secRole.setPrivileges( new ArrayList<String>( role.getPrivileges() ) ); } else { secRole.setPrivileges( new ArrayList<String>() ); } // null check if ( role.getRoles() != null ) { secRole.setRoles( new ArrayList<String>( role.getRoles() ) ); } else { secRole.setRoles( new ArrayList<String>() ); } return secRole; }
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 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; }
rolesToProcess.addAll( role.getRoles() ); final List<String> privilegeIds = role.getPrivileges(); for ( String privilegeId : privilegeIds )
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 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 ); } } }
private CRole getRole(String id, List<CRole> roles) { for (CRole role : roles) { if (role.getId().equals(id)) { return role; } } return null; }
@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 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); }
if (role1.getDescription() == null) { if (role2.getDescription() != null) { return -1; else if (!role1.getDescription().equals(role2.getDescription())) { return -1; if (role1.getId() == null) { if (role2.getId() != null) { return -1; else if (!role1.getId().equals(role2.getId())) { return -1; if (role1.getName() == null) { if (role2.getName() != null) { return -1; else if (!role1.getName().equals(role2.getName())) { 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 (role1.getRoles() == null || role1.getRoles().isEmpty()) {
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; }
if (roles != null && roles.size() > 0) { for (final CRole role : roles) { final List<String> roleRoles = role.getRoles(); if (roleRoles != null && roleRoles.size() > 0) { final List<String> newRoles = Lists.newArrayList(); role.getRoles().clear(); 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);
public void removeRole( final CRole cRole ) { id2roles.remove( cRole.getId() ); delegate.removeRole( cRole ); }
protected void rebuildId2RolesLookupMap() { id2roles.clear(); for ( CRole role : delegate.getRoles() ) { id2roles.put( role.getId(), role ); } }
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; }