public void removeByConsumer(String consumerKey) { store.removeByConsumer(consumerKey); } }
public ServiceProviderToken put(ServiceProviderToken token) throws StoreException { return store.put(token); }
public Iterable<ServiceProviderToken> getAccessTokensForUser(String username) { return store.getAccessTokensForUser(username); }
public ServiceProviderToken get(String token) throws StoreException { try { return store.get(token); } catch (InvalidTokenException e) { store.removeAndNotify(token); throw e; } }
@Override public JobRunnerResponse runJob(JobRunnerRequest request) { tokenStore.removeExpiredTokensAndNotify(); tokenStore.removeExpiredSessionsAndNotify(); log.debug("Expired oauth sessions removed"); return JobRunnerResponse.success(); }
ServiceProviderToken token; try { token = tokenStore.get(requestMessage.getToken()); } catch (InvalidTokenException e) { throw new OAuthProblemException(TOKEN_REJECTED); accessToken = tokenStore.put(factory.generateAccessToken(token)); tokenStore.removeAndNotify(token.getToken()); } catch (Exception e) { handleException(response, e, applicationProperties.getBaseUrl(), true);
@DELETE @Path("service-provider/{applinkId}/{username}") public Response removeServiceProviderAccessTokens(@PathParam("applinkId") String applinkId, @PathParam("username") String username) throws TypeNotInstalledException { Consumer consumer = getConsumerForApplink(new ApplicationId(applinkId)); Iterable<ServiceProviderToken> tokens = serviceProviderTokenStore.getAccessTokensForUser(username); for (ServiceProviderToken token : tokens) { if (token.getConsumer().getKey().equals(consumer.getKey())) { serviceProviderTokenStore.removeAndNotify(token.getToken()); } } return Response.noContent().build(); }
public void removeAndNotify(String token) throws StoreException { store.removeAndNotify(token); }
public Object doInTransaction() { return store.get(tokenStr); } });
public void removeExpiredSessionsAndNotify() throws StoreException { store.removeExpiredSessionsAndNotify(); }
public void removeExpiredTokensAndNotify() throws StoreException { store.removeExpiredTokensAndNotify(); }
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String username = userManager.getRemoteUsername(request); if (username == null) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } String tokenParam = request.getParameter("token"); if (tokenParam == null) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); return; } ServiceProviderToken token = store.get(tokenParam); if (token == null) { return; } if (!username.equals(token.getUser().getName())) { response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } store.removeAndNotify(tokenParam); }
public ServiceProviderToken getTokenForAuthorization(HttpServletRequest request) throws OAuthProblemException, IOException { OAuthMessage requestMessage = OAuthServlet.getMessage(request, null); requestMessage.requireParameters(OAUTH_TOKEN); ServiceProviderToken token; try { token = store.get(requestMessage.getToken()); } catch (InvalidTokenException e) { throw new OAuthProblemException(TOKEN_REJECTED); } if (token == null || token.isAccessToken()) { throw new OAuthProblemException(TOKEN_REJECTED); } if (token.getAuthorization() == Authorization.AUTHORIZED || token.getAuthorization() == Authorization.DENIED) { throw new OAuthProblemException(TOKEN_USED); } if (token.hasExpired(clock)) { throw new OAuthProblemException(TOKEN_EXPIRED); } return token; }
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { ApplicationLink applicationLink; try { applicationLink = Iterables.get(applicationLinkService.getApplicationLinks(), 0); } catch (IndexOutOfBoundsException iobe) { throw new RuntimeException("Need one application link to perform the test"); } serviceProviderTokenStore.removeByConsumer(getConsumerKey(applicationLink)); resp.setContentType("text/plain"); PrintWriter out = resp.getWriter(); out.println("done"); out.close(); }
@PUT @Path("service-provider/{applinkId}/{username}") public Response createServiceProviderAccessToken(@PathParam("applinkId") String applinkId, @PathParam("username") String username) throws TypeNotInstalledException { ServiceProviderToken accessToken = ServiceProviderToken.newAccessToken(getRandomToken()) .tokenSecret(getRandomToken()) .authorizedBy(userManager.resolve(username)) .consumer(getConsumerForApplink(new ApplicationId(applinkId))) .version(ServiceProviderToken.Version.V_1_0) .build(); serviceProviderTokenStore.put(accessToken); return Response.created(URI.create("")) .entity(new RestAccessToken(accessToken)) .build(); }
private Iterable<TokenRepresentation> getTokenRepresentations(String username) { return transform(store.getAccessTokensForUser(username), toTokenRepresentation); }
public void removeConsumer(final ApplicationLink applicationLink) { final String consumerKey = getConsumerKey(applicationLink); if (consumerKey == null) { throw new IllegalStateException("No consumer configured for application link '" + applicationLink + "'."); } serviceProviderTokenStore.removeByConsumer(consumerKey); serviceProviderConsumerStore.remove(consumerKey); if (applicationLink.removeProperty(PROPERTY_INCOMING_CONSUMER_KEY) == null) { throw new IllegalStateException("Failed to remove consumer with key '" + consumerKey + "' from application link '" + applicationLink + "'"); } }
public void process(HttpServletRequest request, HttpServletResponse response, ServiceProviderToken token) throws IOException { ServiceProviderToken newToken; if (request.getParameter("approve") != null) { String verifier = randomizer.randomAlphanumericString(AuthorizeServlet.VERIFIER_LENGTH); newToken = token.authorize(getLoggedInUser(request), verifier); } else if (request.getParameter("deny") != null) { newToken = token.deny(getLoggedInUser(request)); } else { renderer.render(request, response, token); return; } redirectBackToConsumer(request, response, store.put(newToken)); }
@GET @Path("service-provider/{applinkId}/{username}") public Response getServiceProviderAccessToken(@PathParam("applinkId") String applinkId, @PathParam("username") String username) throws TypeNotInstalledException { Consumer consumer = getConsumerForApplink(new ApplicationId(applinkId)); Iterable<ServiceProviderToken> tokens = serviceProviderTokenStore.getAccessTokensForUser(username); for (ServiceProviderToken token : tokens) { if (token.getConsumer().getKey().equals(consumer.getKey())) { return Response.ok(new RestAccessToken(token)).build(); } } return Response.status(Status.NOT_FOUND).build(); }
@EventListener public void onApplicationLinkDeleted(BeforeApplicationLinkDeletedEvent beforeApplicationLinkDeletedEvent) { final ApplicationLink applicationLink = beforeApplicationLinkDeletedEvent.getApplicationLink(); final Object oConsumerKey = applicationLink.getProperty(OAUTH_INCOMING_CONSUMER_KEY); if (oConsumerKey != null) { final String consumerKey = oConsumerKey.toString(); serviceProviderTokenStore.removeByConsumer(consumerKey); serviceProviderConsumerStore.remove(consumerKey); logger.debug("Unregistered consumer with key '{}' for deleted application link {}", oConsumerKey, applicationLink); } if (configurationManager.isConfigured(applicationLink.getId(), OAuthAuthenticationProvider.class)) { final Map<String, String> configuration = configurationManager.getConfiguration(applicationLink.getId(), OAuthAuthenticationProvider.class); final String consumerKey = configuration.get(AddServiceProviderManuallyServlet.CONSUMER_KEY_OUTBOUND); if (!StringUtils.isEmpty(consumerKey)) { consumerService.removeConsumerByKey(consumerKey); logger.debug("Unregistered service provider with consumer key '{}' for deleted application link {}", consumerKey, applicationLink); } consumerTokenStoreService.removeAllConsumerTokens(applicationLink); logger.debug("Removed token for deleted application link {}", applicationLink); } }