Example usage for org.springframework.security.oauth.consumer AccessTokenRequiredException getResource

List of usage examples for org.springframework.security.oauth.consumer AccessTokenRequiredException getResource

Introduction

In this page you can find the example usage for org.springframework.security.oauth.consumer AccessTokenRequiredException getResource.

Prototype

public ProtectedResourceDetails getResource() 

Source Link

Usage

From source file:org.springframework.security.oauth.consumer.filter.OAuthConsumerContextFilter.java

/**
 * 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./*from w  w  w  .j  a  va 2s. c om*/
 *
 * @param ex The exception.
 * @return The resource that needed authorization (never null).
 */
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;
}