List of usage examples for org.springframework.security.oauth2.common OAuth2AccessToken getRefreshToken
OAuth2RefreshToken getRefreshToken();
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 {//from w w w .j a v a 2 s. c om 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:it.smartcommunitylab.aac.apimanager.wso2.WSO2Controller.java
@RequestMapping("/wso2/client/token_revoke/{token}") public @ResponseBody String revokeToken(@PathVariable String token) { OAuth2AccessToken accessTokenObj = tokenStore.readAccessToken(token); if (accessTokenObj != null) { if (accessTokenObj.getRefreshToken() != null) { tokenStore.removeRefreshToken(accessTokenObj.getRefreshToken()); }/*from w w w . j av a 2s . com*/ tokenStore.removeAccessToken(accessTokenObj); } return ""; }
From source file:com.cedac.security.oauth2.provider.token.store.TokenStoreBaseTests.java
@Test public void testRefreshTokenIsNotStoredDuringAccessToken() { OAuth2Authentication expectedAuthentication = new OAuth2Authentication( RequestTokenFactory.createOAuth2Request("id", false), new TestAuthentication("test2", false)); DefaultOAuth2AccessToken expectedOAuth2AccessToken = new DefaultOAuth2AccessToken("testToken"); expectedOAuth2AccessToken.setRefreshToken(new DefaultOAuth2RefreshToken("refreshToken")); getTokenStore().storeAccessToken(expectedOAuth2AccessToken, expectedAuthentication); OAuth2AccessToken actualOAuth2AccessToken = getTokenStore().readAccessToken("testToken"); assertNotNull(actualOAuth2AccessToken.getRefreshToken()); assertNull(getTokenStore().readRefreshToken("refreshToken")); }
From source file:com.mycompany.apps.oauth2.authentication.security.LogoutImpl.java
/** * ????<br>//from w ww. ja v a 2 s . co m * ????? * * @param paramHttpServletRequest * @param paramHttpServletResponse * @param paramAuthentication * @throws IOException * @throws ServletException */ @Override public void onLogoutSuccess(HttpServletRequest paramHttpServletRequest, HttpServletResponse paramHttpServletResponse, Authentication paramAuthentication) throws IOException, ServletException { String tokens = paramHttpServletRequest.getHeader("Authorization"); String values[] = StringUtils.split(tokens, " "); LOG.debug("\n\ttoken type: " + values[0]); LOG.debug("\n\ttoken: " + values[1]); String accessTokenId = null; String refreshTokenId = null; if (values.length != 2) { return; } if (values[1] != null) { accessTokenId = values[1]; } else { return; } // ? OAuth2AccessToken accessToken = tokenstore.readAccessToken(accessTokenId); if (accessToken != null) { // ??? OAuth2RefreshToken rt = accessToken.getRefreshToken(); refreshTokenId = rt.getValue(); // ? tokenstore.removeAccessToken(values[1]); LOG.info("\n\tAccess Token Removed Successfully!"); } else { LOG.info("\n\tAccess Token Not Exist(Not Removed)!"); } // ? OAuth2RefreshToken refreshToken = tokenstore.readRefreshToken(refreshTokenId); if (refreshToken != null) { // ? tokenstore.removeRefreshToken(refreshTokenId); LOG.info("\n\tRefresh Token Removed Successfully!"); } else { LOG.info("\n\tRefresh Token Not Exist(Not Removed)!"); } paramHttpServletResponse.getOutputStream().write("\n\tYou Have Logged Out successfully.".getBytes()); }
From source file:com.onedrive.api.internal.InternalTokenServices.java
public void saveAccessToken(OAuth2ProtectedResourceDetails resource, Authentication authentication, OAuth2AccessToken accessToken) { if (reference.getAccessTokenListener() != null) { AccessToken internalAccessToken = new AccessToken(); internalAccessToken.setAccessToken(accessToken.getValue()); internalAccessToken.setExpiration(accessToken.getExpiration()); internalAccessToken.setRefreshToken(accessToken.getRefreshToken().getValue()); internalAccessToken.setScope(accessToken.getScope()); internalAccessToken.setTokenType(accessToken.getTokenType()); reference.getAccessTokenListener().onAccessTokenReceived(reference, internalAccessToken); }// www . j a va 2s. co m }
From source file:com.iflytek.edu.cloud.frame.spring.RedisTokenStore.java
public void removeAccessToken(String tokenValue) { String tokenKey = extractTokenKey(tokenValue); OAuth2Authentication authentication = readAuthentication(tokenValue); OAuth2AccessToken token = readAccessToken(tokenValue); String refreshToken = token.getRefreshToken().getValue(); Jedis jedis = jedisPool.getResource(); try {//from w ww . ja v a 2 s.c om jedis.hdel(ACCESS_TOKEN_KEY, toBytes(tokenKey)); jedis.hdel(ACCESS_TOKEN_AUTH_KEY, toBytes(tokenKey)); jedis.hdel(ACCESS_REFRESH_CODE_KEY, toBytes(refreshToken)); jedis.hdel(ACCESS_AUTH_ID_KEY, toBytes(authenticationKeyGenerator.extractKey(authentication))); } finally { jedisPool.returnResource(jedis); } }
From source file:com.github.biegleux.gae.oauth.tokenstore.GaeTokenStore.java
@Override public void storeAccessToken(OAuth2AccessToken token, OAuth2Authentication authentication) { String refreshToken = null;// w w w . jav a 2 s.co m if (token.getRefreshToken() != null) { refreshToken = token.getRefreshToken().getValue(); } if (readAccessToken(token.getValue()) != null) { removeAccessToken(token.getValue()); } GaeOAuthAccessToken gaeOAuthAccessToken = new GaeOAuthAccessToken(); gaeOAuthAccessToken.setTokenId(extractTokenKey(token.getValue())); gaeOAuthAccessToken.setToken(token); gaeOAuthAccessToken.setAuthenticationId(authenticationKeyGenerator.extractKey(authentication)); gaeOAuthAccessToken.setUsername(authentication.isClientOnly() ? null : authentication.getName()); gaeOAuthAccessToken.setClientId(authentication.getOAuth2Request().getClientId()); gaeOAuthAccessToken.setAuthentication(authentication); gaeOAuthAccessToken.setRefreshToken(extractTokenKey(refreshToken)); accessTokens.save(gaeOAuthAccessToken); }
From source file:org.springframework.security.oauth2.common.OAuth2AccessTokenJackson2Serializer.java
@Override public void serialize(OAuth2AccessToken token, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonGenerationException { jgen.writeStartObject();/*from w w w.j ava2 s . c o m*/ jgen.writeStringField(OAuth2AccessToken.ACCESS_TOKEN, token.getValue()); jgen.writeStringField(OAuth2AccessToken.TOKEN_TYPE, token.getTokenType()); OAuth2RefreshToken refreshToken = token.getRefreshToken(); if (refreshToken != null) { jgen.writeStringField(OAuth2AccessToken.REFRESH_TOKEN, refreshToken.getValue()); } Date expiration = token.getExpiration(); if (expiration != null) { long now = System.currentTimeMillis(); jgen.writeNumberField(OAuth2AccessToken.EXPIRES_IN, (expiration.getTime() - now) / 1000); } Set<String> scope = token.getScope(); if (scope != null && !scope.isEmpty()) { StringBuffer scopes = new StringBuffer(); for (String s : scope) { Assert.hasLength(s, "Scopes cannot be null or empty. Got " + scope + ""); scopes.append(s); scopes.append(" "); } jgen.writeStringField(OAuth2AccessToken.SCOPE, scopes.substring(0, scopes.length() - 1)); } Map<String, Object> additionalInformation = token.getAdditionalInformation(); for (String key : additionalInformation.keySet()) { jgen.writeObjectField(key, additionalInformation.get(key)); } jgen.writeEndObject(); }
From source file:com.nagarro.core.oauth2.token.provider.HybrisOAuthTokenStore.java
@Override public void storeAccessToken(final OAuth2AccessToken token, final OAuth2Authentication authentication) { OAuthRefreshTokenModel refreshTokenModel = null; if (token.getRefreshToken() != null) { final String refreshTokenKey = extractTokenKey(token.getRefreshToken().getValue()); try {//from w w w .j a v a 2 s. c om refreshTokenModel = oauthTokenService.getRefreshToken(refreshTokenKey); } catch (final UnknownIdentifierException e) { refreshTokenModel = oauthTokenService.saveRefreshToken(refreshTokenKey, serializeRefreshToken(token.getRefreshToken()), serializeAuthentication(authentication)); } } oauthTokenService.saveAccessToken(extractTokenKey(token.getValue()), serializeAccessToken(token), authenticationKeyGenerator.extractKey(authentication), serializeAuthentication(authentication), authentication.isClientOnly() ? null : authentication.getName(), authentication.getOAuth2Request().getClientId(), refreshTokenModel); }
From source file:eu.trentorise.smartcampus.permissionprovider.controller.AuthController.java
/** * Revoke the access token and the associated refresh token. * // w w w .ja v a 2 s.c o m * @param token */ @RequestMapping("/eauth/revoke/{token}") public @ResponseBody String revokeToken(@PathVariable String token) { OAuth2AccessToken accessTokenObj = tokenStore.readAccessToken(token); if (accessTokenObj != null) { if (accessTokenObj.getRefreshToken() != null) { tokenStore.removeRefreshToken(accessTokenObj.getRefreshToken()); } tokenStore.removeAccessToken(accessTokenObj); } return ""; }