try
{
User user = securitySystem.getUserManager().findUser( principal );
if ( user == null )
{
throw new UnauthorizedException( "The security system had an internal error - please check your system logs" );
}
if ( user.isLocked() )
{
throw new UnauthorizedException( "User account is locked." );
}
AuthenticationResult authn = new AuthenticationResult( true, principal, null );
SecuritySession securitySession = new DefaultSecuritySession( authn, user );
return securitySystem.isAuthorized( securitySession, permission, repoId );
}
catch ( UserNotFoundException e )
{
throw new UnauthorizedException( e.getMessage() );
}
catch ( AuthorizationException e )
{
throw new UnauthorizedException( e.getMessage() );
}
}