List of usage examples for org.springframework.security.oauth2.common OAuth2AccessToken getValue
String getValue();
From source file:org.eclipse.cft.server.core.internal.ssh.SshClientSupport.java
public static SshClientSupport create(final CloudFoundryOperations client, CloudCredentials creds, HttpProxyConfiguration proxyConf, boolean selfSigned) { AuthorizationHeaderProvider oauth = new AuthorizationHeaderProvider() { public String getAuthorizationHeader() { OAuth2AccessToken token = client.login(); return token.getTokenType() + " " + token.getValue(); }//w w w . j a v a 2 s . c om }; CloudInfoV2 cloudInfo = new CloudInfoV2(creds, client.getCloudControllerUrl(), proxyConf, selfSigned); return new SshClientSupport(oauth, cloudInfo, selfSigned, proxyConf); }
From source file:org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2DeserializerTests.java
private static void assertTokenEquals(OAuth2AccessToken expected, OAuth2AccessToken actual) { assertEquals(expected.getTokenType(), actual.getTokenType()); assertEquals(expected.getValue(), actual.getValue()); OAuth2RefreshToken expectedRefreshToken = expected.getRefreshToken(); if (expectedRefreshToken == null) { assertNull(actual.getRefreshToken()); } else {//w ww . ja v a 2 s . c o m assertEquals(expectedRefreshToken.getValue(), actual.getRefreshToken().getValue()); } assertEquals(expected.getScope(), actual.getScope()); Date expectedExpiration = expected.getExpiration(); if (expectedExpiration == null) { assertNull(actual.getExpiration()); } else { assertEquals(expectedExpiration.getTime(), actual.getExpiration().getTime()); } assertEquals(expected.getAdditionalInformation(), actual.getAdditionalInformation()); }
From source file:com.gopivotal.cla.github.StandardGitHubClientTest.java
@Test public void getAccessToken() { OAuth2AccessToken accessToken = mock(OAuth2AccessToken.class); when(accessToken.getValue()).thenReturn("test-access-token"); when(this.restOperations.getAccessToken()).thenReturn(accessToken); assertEquals("test-access-token", this.gitHubClient.getAccessToken()); }
From source file:org.cloudfoundry.identity.uaa.audit.event.TokenIssuedEvent.java
private String getPrincipalId() { OAuth2AccessToken token = getSource(); Jwt jwt = JwtHelper.decode(token.getValue()); try {/*from ww w . j a v a2 s. c o m*/ Map<String, Object> claims = mapper.readValue(jwt.getClaims(), new TypeReference<Map<String, Object>>() { }); return (claims.get("user_id") != null ? claims.get("user_id") : claims.get("client_id")).toString(); } catch (IOException e) { return null; } }
From source file:org.trustedanalytics.user.common.OAuth2PriviligedInterceptor.java
@Override public void apply(RequestTemplate requestTemplate) { OAuth2RestTemplate rt = new OAuth2RestTemplate(clientCredentials); OAuth2AccessToken accessToken = rt.getAccessToken(); requestTemplate.header("Authorization", "bearer " + accessToken.getValue()); }
From source file:org.appverse.web.framework.backend.security.oauth2.provider.web.session.OAuth2LogoutSucessHandler.java
@Override public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { // Token revocation OAuth2AccessToken oAuth2AccessToken = tokenServices.getAccessToken((OAuth2Authentication) authentication); tokenServices.revokeToken(oAuth2AccessToken.getValue()); // Instead of redirecting like SimpleUrlLogoutSuccessHandler, we do nothing (no redirect) - will return status 200 (OK) return;//from w ww .j a v a2s.c om }
From source file:com.epam.reportportal.auth.store.OAuth2MongoTokenStore.java
@Override public OAuth2Authentication readAuthentication(OAuth2AccessToken token) { return readAuthentication(token.getValue()); }
From source file:org.cloudfoundry.identity.api.web.AppsIntegrationTests.java
/** * tests a happy-day flow of the native application profile. *//*w w w . ja va2 s.com*/ @Test public void testHappyDay() throws Exception { RestOperations restTemplate = serverRunning.createRestTemplate(); ResponseEntity<String> response = restTemplate.getForEntity(serverRunning.getUrl("/api/apps"), String.class); // first make sure the resource is actually protected. assertNotSame(HttpStatus.OK, response.getStatusCode()); HttpHeaders approvalHeaders = new HttpHeaders(); OAuth2AccessToken accessToken = context.getAccessToken(); approvalHeaders.set("Authorization", "bearer " + accessToken.getValue()); Date oneMinuteAgo = new Date(System.currentTimeMillis() - 60000); Date expiresAt = new Date(System.currentTimeMillis() + 60000); ResponseEntity<Approval[]> approvals = serverRunning.getRestTemplate().exchange( serverRunning.getUrl("/uaa/approvals"), HttpMethod.PUT, new HttpEntity<Approval[]>((new Approval[] { new Approval(testAccounts.getUserName(), "app", "cloud_controller.read", expiresAt, ApprovalStatus.APPROVED, oneMinuteAgo), new Approval(testAccounts.getUserName(), "app", "openid", expiresAt, ApprovalStatus.APPROVED, oneMinuteAgo), new Approval(testAccounts.getUserName(), "app", "password.write", expiresAt, ApprovalStatus.APPROVED, oneMinuteAgo) }), approvalHeaders), Approval[].class); assertEquals(HttpStatus.OK, approvals.getStatusCode()); ResponseEntity<String> result = serverRunning.getForString("/api/apps"); assertEquals(HttpStatus.OK, result.getStatusCode()); String body = result.getBody(); assertTrue("Wrong response: " + body, body.contains("dsyerapi.cloudfoundry.com")); }
From source file:org.apigw.authserver.web.controller.RevocationController.java
@RequestMapping(method = RequestMethod.GET, params = { "clientId" }) public @ResponseBody String revoke(@RequestParam("clientId") String clientId) { log.debug("revoke(clientId: {})", clientId); Collection<OAuth2AccessToken> tokens = tokenServices.findTokensByClientId(clientId); for (OAuth2AccessToken token : tokens) { try {//from ww w . jav a 2 s. c om OAuth2Authentication auth = tokenServices.loadAuthentication(token.getValue()); tokenServices.revokeToken(token.getValue()); User user = (User) auth.getUserAuthentication().getPrincipal(); monitoringService.logRevokeAccessToken(System.currentTimeMillis(), token.getValue(), clientId, token.getScope(), "SUCCESS", "Appen r inte lngre godknd fr anvndning", user.getUsername()); } catch (AuthenticationException e) { log.debug("Access token is already invalid (" + e.getMessage() + ")"); } catch (Throwable e) { log.error("Error while trying to revoke access token", e); } } return "Revoked all authorizations (" + tokens.size() + ") for client: " + clientId; }
From source file:com.create.security.oauth2.provider.token.SpringCacheTokenStoreImpl.java
@Override public void removeAccessToken(final OAuth2AccessToken accessToken) { removeAccessToken(accessToken.getValue()); }