Search in sources :

Example 1 with InvalidOAuthTokenException

use of org.springframework.security.oauth.provider.token.InvalidOAuthTokenException in project spring-security-oauth by spring-projects.

the class UserAuthorizationProcessingFilter method attemptAuthentication.

public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
    String requestToken = request.getParameter(getTokenParameterName());
    if (requestToken == null) {
        throw new InvalidOAuthParametersException("An OAuth token id is required.");
    }
    OAuthProviderToken token = getTokenServices().getToken(requestToken);
    if (token == null) {
        throw new InvalidOAuthTokenException("No callback value has been provided for request token " + requestToken + ".");
    }
    String callbackURL = token.getCallbackUrl();
    if (isRequire10a() && callbackURL == null) {
        throw new InvalidOAuthTokenException("No callback value has been provided for request token " + requestToken + ".");
    }
    if (callbackURL != null) {
        request.setAttribute(CALLBACK_ATTRIBUTE, callbackURL);
    }
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication == null || !authentication.isAuthenticated()) {
        throw new InsufficientAuthenticationException("User must be authenticated before authorizing a request token.");
    }
    String verifier = getVerifierServices().createVerifier();
    request.setAttribute(VERIFIER_ATTRIBUTE, verifier);
    getTokenServices().authorizeRequestToken(requestToken, verifier, authentication);
    return authentication;
}
Also used : OAuthProviderToken(org.springframework.security.oauth.provider.token.OAuthProviderToken) InvalidOAuthParametersException(org.springframework.security.oauth.provider.InvalidOAuthParametersException) Authentication(org.springframework.security.core.Authentication) InsufficientAuthenticationException(org.springframework.security.authentication.InsufficientAuthenticationException) InvalidOAuthTokenException(org.springframework.security.oauth.provider.token.InvalidOAuthTokenException)

Aggregations

InsufficientAuthenticationException (org.springframework.security.authentication.InsufficientAuthenticationException)1 Authentication (org.springframework.security.core.Authentication)1 InvalidOAuthParametersException (org.springframework.security.oauth.provider.InvalidOAuthParametersException)1 InvalidOAuthTokenException (org.springframework.security.oauth.provider.token.InvalidOAuthTokenException)1 OAuthProviderToken (org.springframework.security.oauth.provider.token.OAuthProviderToken)1