public boolean hasPrivileges ( SecurityContext sc , Privilege [ ] privileges ) { for ( AccessControlEntryImpl ace : principals . values ( ) ) { // check access list for everyone if ( ace . getPrincipal ( ) . getName ( ) . equals ( SimplePrincipal . EVERYONE . getName ( ) ) ) { if ( ace . hasPrivileges ( privileges ) ) { return true ; } } // check user principal if ( ace . getPrincipal ( ) . getName ( ) . equals ( username ( sc . getUserName ( ) ) ) ) { if ( ace . hasPrivileges ( privileges ) ) { return true ; } } // check group/role principal if ( sc . hasRole ( ace . getPrincipal ( ) . getName ( ) ) ) { if ( ace . hasPrivileges ( privileges ) ) { return true ; } } } return false ; }
Tests privileges relatively to the given security context .