private void checkAccessToken(OAuthMessage requestMessage, ServiceProviderToken token) throws Exception { if (token.getSession() == null) { throw new OAuthProblemException(TOKEN_REJECTED); } requestMessage.requireParameters(OAUTH_SESSION_HANDLE); if (!token.getSession().getHandle().equals(requestMessage.getParameter(OAUTH_SESSION_HANDLE))) { throw new OAuthProblemException(TOKEN_REJECTED); } if (token.getSession().hasExpired(clock)) { throw new OAuthProblemException(PERMISSION_DENIED); } } }
private Session newSession(ServiceProviderToken token) { Session.Builder builder = Session.newSession(randomizer.randomAlphanumericString(32)); if (token.getSession() != null) { builder.creationTime(token.getSession().getCreationTime()); } return builder.build(); } }
/** * Create a new {@link com.atlassian.oauth.serviceprovider.ServiceProviderToken.Session} for the given {@code token} * * @param token the {@link com.atlassian.oauth.serviceprovider.ServiceProviderToken} to create the session for * @return the new {@link com.atlassian.oauth.serviceprovider.ServiceProviderToken.Session} */ private ServiceProviderToken.Session newSession(ServiceProviderToken token) { ServiceProviderToken.Session.Builder builder = ServiceProviderToken.Session.newSession(RandomStringUtils.randomAlphanumeric(32)); if (token.getSession() != null) { builder.creationTime(token.getSession().getCreationTime()); } return builder.build(); }
/** * Check the given {code token} to see if its a valid access token * * @param requestMessage the {@link net.oauth.OAuthMessage} * @param token the {@link com.atlassian.oauth.serviceprovider.ServiceProviderToken access token} * @throws OAuthProblemException * @throws IOException */ private void checkAccessToken(OAuthMessage requestMessage, ServiceProviderToken token) throws OAuthProblemException, IOException { if (token.getSession() == null) { throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED); } requestMessage.requireParameters(Request.OAUTH_SESSION_HANDLE); if (!token.getSession().getHandle().equals(requestMessage.getParameter(Request.OAUTH_SESSION_HANDLE))) { throw new OAuthProblemException(OAuth.Problems.TOKEN_REJECTED); } if (token.getSession().hasExpired(clock)) { throw new OAuthProblemException(OAuth.Problems.PERMISSION_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()))); }
OAUTH_TOKEN_SECRET, accessToken.getTokenSecret(), OAUTH_EXPIRES_IN, Long.toString(accessToken.getTimeToLive() / 1000), OAUTH_SESSION_HANDLE, accessToken.getSession().getHandle(), OAUTH_AUTHORIZATION_EXPIRES_IN, Long.toString(accessToken.getSession().getTimeToLive() / 1000) ), out);
OAuth.OAUTH_TOKEN_SECRET, accessToken.getTokenSecret(), Request.OAUTH_EXPIRES_IN, Long.toString(accessToken.getTimeToLive() / 1000), Request.OAUTH_SESSION_HANDLE, accessToken.getSession().getHandle(), Request.OAUTH_AUTHORIZATION_EXPIRES_IN, Long.toString(accessToken.getSession().getTimeToLive() / 1000) ), response.getOutputStream());