List of usage examples for org.springframework.security.oauth2.provider OAuth2Authentication getDetails
public Object getDetails()
From source file:org.trustedanalytics.cloud.auth.OAuth2TokenRetriever.java
@Override public String getAuthToken(Authentication auth) { OAuth2Authentication oauth2 = (OAuth2Authentication) auth; OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) oauth2.getDetails(); return details.getTokenValue(); }
From source file:org.trustedanalytics.modelcatalog.security.OAuth2TokenExtractor.java
@Override public String apply(Authentication authentication) { OAuth2Authentication oauth2 = (OAuth2Authentication) authentication; OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) oauth2.getDetails(); return details.getTokenValue(); }
From source file:com.epam.reportportal.auth.SsoEndpoint.java
@RequestMapping(value = { "/sso/me" }, method = RequestMethod.DELETE) public OperationCompletionRS revokeToken(OAuth2Authentication user) { String token = ((OAuth2AuthenticationDetails) user.getDetails()).getTokenValue(); tokenServicesFacade.revokeToken(token); return new OperationCompletionRS(String.format("Token '%s' has revoked", token)); }
From source file:com.orange.clara.cloud.services.sandbox.ElpaasoSandboxServiceApplication.java
@Bean @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) public OAuth2AccessToken getOAuth2AccessToken() { OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) SecurityContextHolder.getContext() .getAuthentication();//from w w w . ja v a 2 s .com final OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) oAuth2Authentication.getDetails(); return new DefaultOAuth2AccessToken(details.getTokenValue()); }
From source file:com.orange.clara.cloud.servicedbdumper.config.UaaConfig.java
@Bean @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS) public OAuth2AccessToken getOAuth2AccessToken() { if (!(SecurityContextHolder.getContext().getAuthentication() instanceof OAuth2Authentication)) { return null; }//from www .j a v a 2 s . c o m OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) SecurityContextHolder.getContext() .getAuthentication(); final OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) oAuth2Authentication.getDetails(); return new DefaultOAuth2AccessToken(details.getTokenValue()); }
From source file:org.mitre.openid.connect.web.ProtectedResourceRegistrationEndpoint.java
private OAuth2AccessTokenEntity fetchValidRegistrationToken(OAuth2Authentication auth, ClientDetailsEntity client) {//from ww w. j ava2s .c o m OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) auth.getDetails(); OAuth2AccessTokenEntity token = tokenService.readAccessToken(details.getTokenValue()); if (config.getRegTokenLifeTime() != null) { try { // Re-issue the token if it has been issued before [currentTime - validity] Date validToDate = new Date(System.currentTimeMillis() - config.getRegTokenLifeTime() * 1000); if (token.getJwt().getJWTClaimsSet().getIssueTime().before(validToDate)) { logger.info("Rotating the registration access token for " + client.getClientId()); tokenService.revokeAccessToken(token); OAuth2AccessTokenEntity newToken = connectTokenService.createResourceAccessToken(client); tokenService.saveAccessToken(newToken); return newToken; } else { // it's not expired, keep going return token; } } catch (ParseException e) { logger.error("Couldn't parse a known-valid token?", e); return token; } } else { // tokens don't expire, just return it return token; } }
From source file:org.mitre.openid.connect.web.ClientDynamicRegistrationEndpoint.java
/** * Get the meta information for a client. * @param clientId// w ww . j a va 2s . c o m * @param m * @param auth * @return */ @PreAuthorize("hasRole('ROLE_CLIENT') and #oauth2.hasScope('" + SystemScopeService.REGISTRATION_TOKEN_SCOPE + "')") @RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json") public String readClientConfiguration(@PathVariable("id") String clientId, Model m, OAuth2Authentication auth) { ClientDetailsEntity client = clientService.loadClientByClientId(clientId); if (client != null && client.getClientId().equals(auth.getOAuth2Request().getClientId())) { // we return the token that we got in OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) auth.getDetails(); OAuth2AccessTokenEntity token = tokenService.readAccessToken(details.getTokenValue()); try { RegisteredClient registered = new RegisteredClient(client, token.getValue(), config.getIssuer() + "register/" + UriUtils.encodePathSegment(client.getClientId(), "UTF-8")); // send it all out to the view m.addAttribute("client", registered); m.addAttribute("code", HttpStatus.OK); // http 200 return "clientInformationResponseView"; } catch (UnsupportedEncodingException e) { logger.error("Unsupported encoding", e); m.addAttribute("code", HttpStatus.INTERNAL_SERVER_ERROR); return "httpCodeView"; } } else { // client mismatch logger.error("readClientConfiguration failed, client ID mismatch: " + clientId + " and " + auth.getOAuth2Request().getClientId() + " do not match."); m.addAttribute("code", HttpStatus.FORBIDDEN); // http 403 return "httpCodeView"; } }
From source file:org.mitre.openid.connect.web.DynamicClientRegistrationEndpoint.java
private OAuth2AccessTokenEntity fetchValidRegistrationToken(OAuth2Authentication auth, ClientDetailsEntity client) {/* www .j a v a2s. c o m*/ OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) auth.getDetails(); OAuth2AccessTokenEntity token = tokenService.readAccessToken(details.getTokenValue()); if (config.getRegTokenLifeTime() != null) { try { // Re-issue the token if it has been issued before [currentTime - validity] Date validToDate = new Date(System.currentTimeMillis() - config.getRegTokenLifeTime() * 1000); if (token.getJwt().getJWTClaimsSet().getIssueTime().before(validToDate)) { logger.info("Rotating the registration access token for " + client.getClientId()); tokenService.revokeAccessToken(token); OAuth2AccessTokenEntity newToken = connectTokenService.createRegistrationAccessToken(client); tokenService.saveAccessToken(newToken); return newToken; } else { // it's not expired, keep going return token; } } catch (ParseException e) { logger.error("Couldn't parse a known-valid token?", e); return token; } } else { // tokens don't expire, just return it return token; } }
From source file:org.cloudfoundry.identity.uaa.oauth.token.UaaTokenServicesTests.java
@Test public void testLoadAuthenticationForAClient() { DefaultAuthorizationRequest authorizationRequest = new DefaultAuthorizationRequest("client", Arrays.asList(new String[] { "read", "write" })); authorizationRequest.setResourceIds(new HashSet<String>(Arrays.asList(new String[] { "scim", "clients" }))); Map<String, String> azParameters = new HashMap<String, String>( authorizationRequest.getAuthorizationParameters()); azParameters.put("grant_type", "client_credentials"); authorizationRequest.setAuthorizationParameters(azParameters); OAuth2Authentication authentication = new OAuth2Authentication(authorizationRequest, null); OAuth2AccessToken accessToken = tokenServices.createAccessToken(authentication); OAuth2Authentication loadedAuthentication = tokenServices.loadAuthentication(accessToken.getValue()); assertEquals(AuthorityUtils.commaSeparatedStringToAuthorityList("update"), loadedAuthentication.getAuthorities()); assertEquals("client", loadedAuthentication.getName()); assertEquals("client", loadedAuthentication.getPrincipal()); assertNull(loadedAuthentication.getDetails()); assertNull(loadedAuthentication.getUserAuthentication()); }