private void redirectBackToConsumerVersion1a(HttpServletRequest request, HttpServletResponse response, ServiceProviderToken token) throws IOException { URI callback = token.getCallback() == null ? token.getConsumer().getCallback() : token.getCallback(); if (callback == null) { response.setContentType("text/html"); if (token.getAuthorization() == Authorization.AUTHORIZED) { // no call back, display the verification code so the user can enter it manually templateRenderer.render(AUTH_NO_CALLBACK_APPROVAL_V1A_TEMPLATE, ImmutableMap.<String, Object>of("token", token), response.getWriter()); } else { templateRenderer.render(AUTH_NO_CALLBACK_DENIED_TEMPLATE, ImmutableMap.<String, Object>of("token", token), response.getWriter()); } } else { // add the token and verifier parameters to the callback and send the redirect // if the token was denied, then the verifier is set to a placeholder value in case consumers don't handle // a blank or missing verifier parameter response.sendRedirect(addParameters(callback.toString(), OAUTH_TOKEN, token.getToken(), OAUTH_VERIFIER, token.getAuthorization() == 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()))); }
/** * 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); } } }
if (token.getVersion() == ServiceProviderToken.Version.V_1_0_A) { newCallback = OAuth.addParameters(newCallback, OAuth.OAUTH_VERIFIER, token.getAuthorization() == ServiceProviderToken .Authorization.AUTHORIZED ? token.getVerifier() : "denied");
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); } } }