protected ProtectedResourceDetails checkForResourceThatNeedsAuthorization ( Exception ex ) throws ServletException , IOException { Throwable [ ] causeChain = getThrowableAnalyzer ( ) . determineCauseChain ( ex ) ; AccessTokenRequiredException ase = ( AccessTokenRequiredException ) getThrowableAnalyzer ( ) . getFirstThrowableOfType ( AccessTokenRequiredException . class , causeChain ) ; ProtectedResourceDetails resourceThatNeedsAuthorization ; if ( ase != null ) { resourceThatNeedsAuthorization = ase . getResource ( ) ; if ( resourceThatNeedsAuthorization == null ) { throw new OAuthRequestFailedException ( ase . getMessage ( ) ) ; } } else { // Rethrow ServletExceptions and RuntimeExceptions as-is if ( ex instanceof ServletException ) { throw ( ServletException ) ex ; } if ( ex instanceof IOException ) { throw ( IOException ) ex ; } else if ( ex instanceof RuntimeException ) { throw ( RuntimeException ) ex ; } // Wrap other Exceptions. These are not expected to happen throw new RuntimeException ( ex ) ; } return resourceThatNeedsAuthorization ; }
Check the given exception for the resource that needs authorization . If the exception was not thrown because a resource needed authorization then rethrow the exception .