if ( username != null && username.equals( "administrators" ) ) {
return null;
}
// optimization for when running in pre-authenticated mode (i.e. Spring Security filters have setup holder with
// current user meaning we don't have to hit the back-end again)
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
if ( auth != null ) {
Object ssPrincipal = auth.getPrincipal();
if ( ssPrincipal instanceof UserDetails ) {
if ( username.equals( ( (UserDetails) ssPrincipal ).getUsername() ) ) {
return (UserDetails) ssPrincipal;
}
}
}
UserDetails user = null;
// user cache not available or user not in cache; do lookup
GrantedAuthority[] auths = null;
GrantedAuthority[] authorities = null;
UserDetails newUser = null;
if ( getUserDetailsService() != null ) {
try {
user = getUserDetailsService().loadUserByUsername( username );
// We will use the authorities from the Authentication object of SecurityContextHolder.
//Authentication object is null then we will get it from IUserRoleListService
if ( auth == null || auth.getAuthorities() == null || auth.getAuthorities().length == 0 ) {
if ( logger.isTraceEnabled() ) {
logger.trace( "Authentication object from SecurityContextHolder is null,"
+ " so getting the roles for [ " + user.getUsername() + " ] from IUserRoleListService " ); //$NON-NLS-1$
}
List<String> roles = getUserRoleListService().getRolesForUser( JcrTenantUtils.getCurrentTenant(), username );
authorities = new GrantedAuthority[ roles.size() ];
for ( int i = 0; i < roles.size(); i++ ) {
authorities[ i ] = new GrantedAuthorityImpl( roles.get( i ) );
}
} else {
authorities = auth.getAuthorities();
}
auths = new GrantedAuthority[ authorities.length ];
// cache the roles while we're here
for ( int i = 0; i < authorities.length; i++ ) {