public class AppAuthProvider implements AuthenticationProvider { private static final String PERMISSION_PREFIX = "ROLE_PERMISSION_"; // get the logging user info @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { Collection<GrantedAuthority> permissions = new HashSet<GrantedAuthority>(); for (Role role : user.getRole()) { for (Permission perm : role.getPermissions()) { GrantedAuthority permission = new SimpleGrantedAuthority(PERMISSION_PREFIX + perm.getPermissionName()); permissions.add(permission); } } UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(user, null, permissions); // user object you get from service/repository return authToken; } }
private void gatherUniquePermissions( Role role, Collection<Permission> coll ) throws RbacManagerException { if ( role.getPermissions() != null ) { for ( Permission permission : role.getPermissions() ) { if ( !coll.contains( permission ) ) { coll.add( permission ); } } } if ( role.hasChildRoles() ) { Map<String, Role> childRoles = getChildRoles( role ); Iterator<Role> it = childRoles.values().iterator(); while ( it.hasNext() ) { Role child = it.next(); gatherUniquePermissions( child, coll ); } } }
public static void assertValid( String scope, Role role ) throws RbacObjectInvalidException { if ( role == null ) { throw new RbacObjectInvalidException( scope, "Null Role object is invalid." ); } if ( StringUtils.isEmpty( role.getName() ) ) { throw new RbacObjectInvalidException( scope, "Role.name must not be empty." ); } if ( role.getPermissions() != null ) { int i = 0; for ( Permission perm : role.getPermissions() ) { assertValid( "Role.permissions[" + i + "]", perm ); i++; } } }
public Role( org.apache.archiva.redback.rbac.Role role ) { this.name = role.getName(); this.description = role.getDescription(); this.assignable = role.isAssignable(); this.childRoleNames = role.getChildRoleNames() == null ? new ArrayList<String>( 0 ) : new ArrayList<String>( role.getChildRoleNames() ); if ( role.getPermissions() == null ) { this.permissions = new ArrayList<Permission>( 0 ); } else { for ( org.apache.archiva.redback.rbac.Permission p : role.getPermissions() ) { this.permissions.add( new Permission( p ) ); } } }
public Role saveRole( Role role ) throws RbacManagerException { RBACObjectAssertions.assertValid( "Save Role", role ); triggerInit(); roles.put( role.getName(), role ); fireRbacRoleSaved( role ); if ( role.getPermissions() != null ) { for ( Permission p : role.getPermissions() ) { savePermission( p ); } } return role; }
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (Role role : employee.getRoles()) { for (Permission permission : role.getPermissions()) { authorities.add(new SimpleGrantedAuthority(permission.getName()));
for ( Permission permission : role.getPermissions() )
for ( Permission permission : permissions ) if ( !role.getPermissions().contains( permission ) ) List<Permission> oldPermissions = new ArrayList<Permission>( role.getPermissions() ); for ( Permission permission : oldPermissions )
for ( Permission permission : permissions ) if ( !role.getPermissions().contains( permission ) ) List<Permission> oldPermissions = new ArrayList<Permission>( role.getPermissions() ); for ( Permission permission : oldPermissions )