Java Code Examples for org.apache.cxf.rs.security.oauth2.common.ClientAccessToken#setRefreshToken()
The following examples show how to use
org.apache.cxf.rs.security.oauth2.common.ClientAccessToken#setRefreshToken() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OAuthUtils.java From cxf with Apache License 2.0 | 6 votes |
public static ClientAccessToken toClientAccessToken(ServerAccessToken serverToken, boolean supportOptionalParams) { String tokenKey = serverToken.getEncodedToken() != null ? serverToken.getEncodedToken() : serverToken.getTokenKey(); ClientAccessToken clientToken = new ClientAccessToken(serverToken.getTokenType(), tokenKey); clientToken.setRefreshToken(serverToken.getRefreshToken()); if (supportOptionalParams) { clientToken.setExpiresIn(serverToken.getExpiresIn()); List<OAuthPermission> perms = serverToken.getScopes(); String scopeString = OAuthUtils.convertPermissionsToScope(perms); if (!StringUtils.isEmpty(scopeString)) { clientToken.setApprovedScope(scopeString); } clientToken.setParameters(new HashMap<String, String>(serverToken.getParameters())); } return clientToken; }
Example 2
Source File: OAuthJSONProviderTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testWriteBearerClientAccessToken() throws Exception { ClientAccessToken token = new ClientAccessToken(OAuthConstants.BEARER_TOKEN_TYPE, "1234"); token.setExpiresIn(12345); token.setRefreshToken("5678"); token.setApprovedScope("read"); token.setParameters(Collections.singletonMap("my_parameter", "http://abc")); OAuthJSONProvider provider = new OAuthJSONProvider(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); provider.writeTo(token, ClientAccessToken.class, ClientAccessToken.class, new Annotation[]{}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), bos); doReadClientAccessToken(bos.toString(), OAuthConstants.BEARER_TOKEN_TYPE, token.getParameters()); }
Example 3
Source File: OAuthJSONProviderTest.java From cxf with Apache License 2.0 | 6 votes |
@Test public void testWriteHawkClientAccessToken() throws Exception { ClientAccessToken token = new ClientAccessToken("hawk", "1234"); token.setExpiresIn(12345); token.setRefreshToken("5678"); token.setApprovedScope("read"); Map<String, String> params = new LinkedHashMap<>(); params.put(OAuthConstants.HAWK_TOKEN_KEY, "test_mac_secret"); params.put(OAuthConstants.HAWK_TOKEN_ALGORITHM, OAuthConstants.HMAC_ALGO_SHA_1); params.put("my_parameter", "http://abc"); token.setParameters(params); OAuthJSONProvider provider = new OAuthJSONProvider(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); provider.writeTo(token, ClientAccessToken.class, ClientAccessToken.class, new Annotation[] {}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, Object>(), bos); doReadClientAccessToken(bos.toString(), OAuthConstants.HAWK_TOKEN_TYPE, params); }
Example 4
Source File: OAuthClientUtils.java From cxf with Apache License 2.0 | 5 votes |
public static ClientAccessToken fromMapToClientToken(Map<String, String> map, String defaultTokenType) { final String tokenKey = map.remove(OAuthConstants.ACCESS_TOKEN); if (tokenKey != null) { String tokenType = map.remove(OAuthConstants.ACCESS_TOKEN_TYPE); if (tokenType == null) { tokenType = defaultTokenType; } if (tokenType != null) { ClientAccessToken token = new ClientAccessToken(tokenType, tokenKey); String refreshToken = map.remove(OAuthConstants.REFRESH_TOKEN); if (refreshToken != null) { token.setRefreshToken(refreshToken); } String expiresInStr = map.remove(OAuthConstants.ACCESS_TOKEN_EXPIRES_IN); if (expiresInStr != null) { token.setExpiresIn(Long.parseLong(expiresInStr)); } String issuedAtStr = map.remove(OAuthConstants.ACCESS_TOKEN_ISSUED_AT); token.setIssuedAt(issuedAtStr != null ? Long.parseLong(issuedAtStr) : System.currentTimeMillis() / 1000); String scope = map.remove(OAuthConstants.SCOPE); if (scope != null) { token.setApprovedScope(scope); } token.setParameters(map); return token; } } return null; }