use of org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider in project cxf by apache.
the class OAuthJSONProviderTest method testWriteHawkClientAccessToken.
@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<String, String>();
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);
}
use of org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider in project cxf by apache.
the class OAuthJSONProviderTest method testReadTokenIntrospection.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testReadTokenIntrospection() throws Exception {
String response = "{\"active\":true,\"client_id\":\"WjcK94pnec7CyA\",\"username\":\"alice\",\"token_type\":\"Bearer\"" + ",\"scope\":\"a\",\"aud\":\"https://localhost:8082/service\"," + "\"iat\":1453472181,\"exp\":1453475781}";
OAuthJSONProvider provider = new OAuthJSONProvider();
TokenIntrospection t = (TokenIntrospection) provider.readFrom((Class) TokenIntrospection.class, TokenIntrospection.class, new Annotation[] {}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, String>(), new ByteArrayInputStream(response.getBytes()));
assertTrue(t.isActive());
assertEquals("WjcK94pnec7CyA", t.getClientId());
assertEquals("alice", t.getUsername());
assertEquals("a", t.getScope());
assertEquals(1, t.getAud().size());
assertEquals("https://localhost:8082/service", t.getAud().get(0));
assertEquals(1453472181L, t.getIat().longValue());
assertEquals(1453475781L, t.getExp().longValue());
}
use of org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider in project cxf by apache.
the class OAuthJSONProviderTest method testReadTokenIntrospectionSingleAudAsArray.
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testReadTokenIntrospectionSingleAudAsArray() throws Exception {
String response = "{\"active\":false,\"client_id\":\"WjcK94pnec7CyA\",\"username\":\"alice\",\"token_type\":\"Bearer\"" + ",\"scope\":\"a\",\"aud\":[\"https://localhost:8082/service\"]," + "\"iat\":1453472181,\"exp\":1453475781}";
OAuthJSONProvider provider = new OAuthJSONProvider();
TokenIntrospection t = (TokenIntrospection) provider.readFrom((Class) TokenIntrospection.class, TokenIntrospection.class, new Annotation[] {}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, String>(), new ByteArrayInputStream(response.getBytes()));
assertFalse(t.isActive());
assertEquals("WjcK94pnec7CyA", t.getClientId());
assertEquals("alice", t.getUsername());
assertEquals("a", t.getScope());
assertEquals(1, t.getAud().size());
assertEquals("https://localhost:8082/service", t.getAud().get(0));
assertEquals(1453472181L, t.getIat().longValue());
assertEquals(1453475781L, t.getExp().longValue());
}
Aggregations