Search in sources :

Example 21 with OAuthJSONProvider

use of org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider in project testcases by coheigea.

the class BalanceServiceTest method setupProviders.

private static List<Object> setupProviders() {
    List<Object> providers = new ArrayList<Object>();
    JSONProvider<OAuthAuthorizationData> jsonP = new JSONProvider<OAuthAuthorizationData>();
    jsonP.setNamespaceMap(Collections.singletonMap("http://org.apache.cxf.rs.security.oauth", "ns2"));
    providers.add(jsonP);
    providers.add(new OAuthJSONProvider());
    return providers;
}
Also used : ArrayList(java.util.ArrayList) OAuthJSONProvider(org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider) JSONProvider(org.apache.cxf.jaxrs.provider.json.JSONProvider) OAuthJSONProvider(org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider) OAuthAuthorizationData(org.apache.cxf.rs.security.oauth2.common.OAuthAuthorizationData)

Example 22 with OAuthJSONProvider

use of org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider in project cxf by apache.

the class OAuthJSONProviderTest method doReadClientAccessToken.

@SuppressWarnings({ "unchecked", "rawtypes" })
public ClientAccessToken doReadClientAccessToken(String response, String expectedTokenType, Map<String, String> expectedParams) throws Exception {
    OAuthJSONProvider provider = new OAuthJSONProvider();
    ClientAccessToken token = (ClientAccessToken) provider.readFrom((Class) ClientAccessToken.class, ClientAccessToken.class, new Annotation[] {}, MediaType.APPLICATION_JSON_TYPE, new MetadataMap<String, String>(), new ByteArrayInputStream(response.getBytes()));
    assertEquals("1234", token.getTokenKey());
    assertTrue(expectedTokenType.equalsIgnoreCase(token.getTokenType()));
    assertEquals("5678", token.getRefreshToken());
    assertEquals(12345, token.getExpiresIn());
    assertEquals("read", token.getApprovedScope());
    Map<String, String> extraParams = token.getParameters();
    if (expectedParams != null) {
        assertEquals(expectedParams, extraParams);
    }
    assertEquals("http://abc", extraParams.get("my_parameter"));
    return token;
}
Also used : MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) ByteArrayInputStream(java.io.ByteArrayInputStream) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) Annotation(java.lang.annotation.Annotation)

Example 23 with OAuthJSONProvider

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<>();
    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);
}
Also used : ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 24 with OAuthJSONProvider

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());
}
Also used : TokenIntrospection(org.apache.cxf.rs.security.oauth2.common.TokenIntrospection) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) ByteArrayInputStream(java.io.ByteArrayInputStream) Annotation(java.lang.annotation.Annotation) Test(org.junit.Test)

Example 25 with OAuthJSONProvider

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());
}
Also used : TokenIntrospection(org.apache.cxf.rs.security.oauth2.common.TokenIntrospection) MetadataMap(org.apache.cxf.jaxrs.impl.MetadataMap) ByteArrayInputStream(java.io.ByteArrayInputStream) Annotation(java.lang.annotation.Annotation) Test(org.junit.Test)

Aggregations

OAuthJSONProvider (org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider)21 OAuthAuthorizationData (org.apache.cxf.rs.security.oauth2.common.OAuthAuthorizationData)16 JSONProvider (org.apache.cxf.jaxrs.provider.json.JSONProvider)15 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)8 JsonMapObjectProvider (org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider)7 JsonWebKeysProvider (org.apache.cxf.rs.security.jose.jaxrs.JsonWebKeysProvider)7 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)7 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Annotation (java.lang.annotation.Annotation)4 Form (javax.ws.rs.core.Form)4 MetadataMap (org.apache.cxf.jaxrs.impl.MetadataMap)4 Client (javax.ws.rs.client.Client)3 TokenIntrospection (org.apache.cxf.rs.security.oauth2.common.TokenIntrospection)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Response (javax.ws.rs.core.Response)2 WebClient (org.apache.cxf.jaxrs.client.WebClient)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ProcessingException (javax.ws.rs.ProcessingException)1