private void redirectBackToConsumer(HttpServletRequest request, HttpServletResponse response, ServiceProviderToken token) throws IOException { if (V_1_0_A.equals(token.getVersion())) { redirectBackToConsumerVersion1a(request, response, token); } else { redirectBackToConsumerVersion1(request, response, token); } }
ServletException { URI callback = null; if (token.getVersion() == ServiceProviderToken.Version.V_1_0_A && token.getCallback() != null) { callback = token.getCallback(); } else if (token.getVersion() == ServiceProviderToken.Version.V_1_0 && request.hasParameter(OAuth.OAUTH_CALLBACK)) { callback = URI.create(request.getParameter(OAuth.OAUTH_CALLBACK)); if (token.getVersion() == ServiceProviderToken.Version.V_1_0_A) { newCallback = OAuth.addParameters(newCallback, OAuth.OAUTH_VERIFIER, token.getAuthorization() == ServiceProviderToken .Authorization.AUTHORIZED ? token.getVerifier() : "denied");
public static Matcher<? super ServiceProviderToken> equalTo(ServiceProviderToken token) { // Hamcrest's is/equalTo matcher uses Object.equals so Consumer and Session properties // need to be explicitly checked Consumer consumer = token.getConsumer(); Matcher<?> consumerMatcher = consumer == null ? nullValue() : samePropertyValuesAs(consumer); ServiceProviderToken.Session session = token.getSession(); Matcher<?> sessionMatcher = session == null ? nullValue() : samePropertyValuesAs(session); return allOf(hasProperty("consumer", consumerMatcher), hasProperty("session", sessionMatcher), hasProperty("authorization", is(token.getAuthorization())), hasProperty("callback", is(token.getCallback())), hasProperty("creationTime", is(token.getCreationTime())), hasProperty("timeToLive", is(token.getTimeToLive())), hasProperty("user", is(token.getUser())), hasProperty("verifier", is(token.getVerifier())), hasProperty("version", is(token.getVersion())), hasProperty("properties", is(token.getProperties())), hasProperty("token", is(token.getToken())), hasProperty("tokenSecret", is(token.getTokenSecret()))); }
private void checkRequestToken(OAuthMessage requestMessage, ServiceProviderToken token) throws Exception { if (token.hasExpired(clock)) { throw new OAuthProblemException(TOKEN_EXPIRED); } if (token.getAuthorization() == Authorization.NONE) { throw new OAuthProblemException(PERMISSION_UNKNOWN); } if (token.getAuthorization() == Authorization.DENIED) { throw new OAuthProblemException(PERMISSION_DENIED); } if (!token.getConsumer().getKey().equals(requestMessage.getConsumerKey())) { throw new OAuthProblemException(TOKEN_REJECTED); } if (V_1_0_A.equals(token.getVersion())) { requestMessage.requireParameters(OAUTH_VERIFIER); if (!token.getVerifier().equals(requestMessage.getParameter(OAUTH_VERIFIER))) { throw new OAuthProblemException(TOKEN_REJECTED); } } }
/** * Check the given {code token} to see if its a valid request token * * @param requestMessage the {@link net.oauth.OAuthMessage} * @param token the {@link com.atlassian.oauth.serviceprovider.ServiceProviderToken request token} * @throws OAuthProblemException * @throws IOException */ private void checkRequestToken(OAuthMessage requestMessage, ServiceProviderToken token) throws OAuthProblemException, IOException { if (token.hasExpired(clock)) { throw new OAuthProblemException(OAuth.Problems.TOKEN_EXPIRED); } if (token.getAuthorization() == ServiceProviderToken.Authorization.NONE) { throw new OAuthProblemException(OAuth.Problems.PERMISSION_UNKNOWN); } if (token.getAuthorization() == ServiceProviderToken.Authorization.DENIED) { throw new OAuthProblemException(OAuth.Problems.PERMISSION_DENIED); } if (!token.getConsumer().getKey().equals(requestMessage.getConsumerKey())) { throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED); } if (ServiceProviderToken.Version.V_1_0_A.equals(token.getVersion())) { requestMessage.requireParameters(OAuth.OAUTH_VERIFIER); if (token.getVerifier() != null && !token.getVerifier().equals(requestMessage.getParameter(OAuth.OAUTH_VERIFIER))) { throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED); } } }