Search in sources :

Example 11 with JsonMapObjectProvider

use of org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider in project testcases by coheigea.

the class ImplicitFlowTest 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());
    providers.add(new JsonWebKeysProvider());
    providers.add(new JsonMapObjectProvider());
    return providers;
}
Also used : JsonWebKeysProvider(org.apache.cxf.rs.security.jose.jaxrs.JsonWebKeysProvider) ArrayList(java.util.ArrayList) JSONProvider(org.apache.cxf.jaxrs.provider.json.JSONProvider) OAuthJSONProvider(org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider) OAuthJSONProvider(org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider) JsonMapObjectProvider(org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider) OAuthAuthorizationData(org.apache.cxf.rs.security.oauth2.common.OAuthAuthorizationData)

Example 12 with JsonMapObjectProvider

use of org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider in project testcases by coheigea.

the class JWTRequestTest 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());
    providers.add(new JsonWebKeysProvider());
    providers.add(new JsonMapObjectProvider());
    return providers;
}
Also used : JsonWebKeysProvider(org.apache.cxf.rs.security.jose.jaxrs.JsonWebKeysProvider) 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) JsonMapObjectProvider(org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider) OAuthAuthorizationData(org.apache.cxf.rs.security.oauth2.common.OAuthAuthorizationData)

Example 13 with JsonMapObjectProvider

use of org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider in project testcases by coheigea.

the class UserInfoTest method testPlainUserInfo.

@org.junit.Test
public void testPlainUserInfo() throws Exception {
    URL busFile = UserInfoTest.class.getResource("cxf-client.xml");
    String address = "https://localhost:" + PORT + "/services/";
    WebClient client = WebClient.create(address, setupProviders(), "alice", "security", busFile.toString());
    // Save the Cookie for the second request...
    WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
    // Get Authorization Code
    String code = getAuthorizationCode(client, "openid");
    assertNotNull(code);
    // Now get the access token
    client = WebClient.create(address, setupProviders(), "consumer-id", "this-is-a-secret", busFile.toString());
    // Save the Cookie for the second request...
    WebClient.getConfig(client).getRequestContext().put(org.apache.cxf.message.Message.MAINTAIN_SESSION, Boolean.TRUE);
    ClientAccessToken accessToken = getAccessTokenWithAuthorizationCode(client, code);
    assertNotNull(accessToken.getTokenKey());
    assertTrue(accessToken.getApprovedScope().contains("openid"));
    // Now invoke on the UserInfo service with the access token
    String userInfoAddress = "https://localhost:" + USERINFO_PORT + "/services/plain/userinfo";
    WebClient userInfoClient = WebClient.create(userInfoAddress, Collections.singletonList(new JsonMapObjectProvider()), busFile.toString());
    userInfoClient.accept("application/json");
    userInfoClient.header("Authorization", "Bearer " + accessToken.getTokenKey());
    Response serviceResponse = userInfoClient.get();
    assertEquals(serviceResponse.getStatus(), 200);
    UserInfo userInfo = serviceResponse.readEntity(UserInfo.class);
    assertNotNull(userInfo);
    assertEquals("alice", userInfo.getSubject());
    assertEquals("consumer-id", userInfo.getAudience());
}
Also used : Response(javax.ws.rs.core.Response) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) UserInfo(org.apache.cxf.rs.security.oidc.common.UserInfo) JsonMapObjectProvider(org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 14 with JsonMapObjectProvider

use of org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider in project cxf by apache.

the class OIDCDynamicRegistrationTest method testRegisterClientPasswordGrant.

@org.junit.Test
public void testRegisterClientPasswordGrant() throws Exception {
    URL busFile = OIDCDynamicRegistrationTest.class.getResource("client.xml");
    String address = "https://localhost:" + DYNREG_SERVER.getPort() + "/services/dynamicWithAt/register";
    WebClient wc = WebClient.create(address, Collections.singletonList(new JsonMapObjectProvider()), busFile.toString()).accept("application/json").type("application/json").authorization(new ClientAccessToken(OAuthConstants.BEARER_AUTHORIZATION_SCHEME, ACCESS_TOKEN));
    ClientRegistration reg = new ClientRegistration();
    reg.setClientName("dynamic_client");
    reg.setGrantTypes(Collections.singletonList(OAuthConstants.RESOURCE_OWNER_GRANT));
    ClientRegistrationResponse resp = wc.post(reg, ClientRegistrationResponse.class);
    assertNotNull(resp.getClientId());
    assertNotNull(resp.getClientSecret());
    assertEquals(address + "/" + resp.getClientId(), resp.getRegistrationClientUri());
    String regAccessToken = resp.getRegistrationAccessToken();
    assertNotNull(regAccessToken);
    ClientRegistration clientRegResp = wc.path(resp.getClientId()).authorization(new ClientAccessToken(OAuthConstants.BEARER_AUTHORIZATION_SCHEME, regAccessToken)).get(ClientRegistration.class);
    assertEquals("web", clientRegResp.getApplicationType());
    assertEquals("dynamic_client", clientRegResp.getClientName());
    assertEquals(Collections.singletonList(OAuthConstants.RESOURCE_OWNER_GRANT), clientRegResp.getGrantTypes());
    assertNull(clientRegResp.getTokenEndpointAuthMethod());
    assertNull(clientRegResp.getScope());
    assertNull(clientRegResp.getRedirectUris());
    assertEquals(200, wc.delete().getStatus());
}
Also used : ClientRegistration(org.apache.cxf.rs.security.oauth2.services.ClientRegistration) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) ClientRegistrationResponse(org.apache.cxf.rs.security.oauth2.services.ClientRegistrationResponse) JsonMapObjectProvider(org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 15 with JsonMapObjectProvider

use of org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider in project cxf by apache.

the class OIDCDynamicRegistrationTest method testRegisterClientInitialAccessTokenCodeGrantTls.

@org.junit.Test
public void testRegisterClientInitialAccessTokenCodeGrantTls() throws Exception {
    URL busFile = OIDCDynamicRegistrationTest.class.getResource("client.xml");
    String address = "https://localhost:" + DYNREG_SERVER.getPort() + "/services/dynamicWithAt/register";
    WebClient wc = WebClient.create(address, Collections.singletonList(new JsonMapObjectProvider()), busFile.toString()).accept("application/json").type("application/json").authorization(new ClientAccessToken(OAuthConstants.BEARER_AUTHORIZATION_SCHEME, ACCESS_TOKEN));
    ClientRegistration reg = newClientRegistrationCodeGrant();
    reg.setTokenEndpointAuthMethod(OAuthConstants.TOKEN_ENDPOINT_AUTH_TLS);
    reg.setProperty(OAuthConstants.TLS_CLIENT_AUTH_SUBJECT_DN, "CN=whateverhost.com,OU=Morpit,O=ApacheTest,L=Syracuse,C=US");
    ClientRegistrationResponse resp = wc.post(reg, ClientRegistrationResponse.class);
    assertNotNull(resp.getClientId());
    assertNull(resp.getClientSecret());
    assertEquals(address + "/" + resp.getClientId(), resp.getRegistrationClientUri());
    String regAccessToken = resp.getRegistrationAccessToken();
    assertNotNull(regAccessToken);
    ClientRegistration clientRegResp = wc.path(resp.getClientId()).authorization(new ClientAccessToken(OAuthConstants.BEARER_AUTHORIZATION_SCHEME, regAccessToken)).get(ClientRegistration.class);
    testCommonRegCodeGrantProperties(clientRegResp);
    assertEquals(OAuthConstants.TOKEN_ENDPOINT_AUTH_TLS, clientRegResp.getTokenEndpointAuthMethod());
    assertEquals("CN=whateverhost.com,OU=Morpit,O=ApacheTest,L=Syracuse,C=US", clientRegResp.getProperty(OAuthConstants.TLS_CLIENT_AUTH_SUBJECT_DN));
    assertEquals(200, wc.delete().getStatus());
}
Also used : ClientRegistration(org.apache.cxf.rs.security.oauth2.services.ClientRegistration) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) ClientRegistrationResponse(org.apache.cxf.rs.security.oauth2.services.ClientRegistrationResponse) JsonMapObjectProvider(org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Aggregations

JsonMapObjectProvider (org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider)17 WebClient (org.apache.cxf.jaxrs.client.WebClient)10 URL (java.net.URL)9 JSONProvider (org.apache.cxf.jaxrs.provider.json.JSONProvider)7 JsonWebKeysProvider (org.apache.cxf.rs.security.jose.jaxrs.JsonWebKeysProvider)7 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)7 OAuthAuthorizationData (org.apache.cxf.rs.security.oauth2.common.OAuthAuthorizationData)7 OAuthJSONProvider (org.apache.cxf.rs.security.oauth2.provider.OAuthJSONProvider)7 ArrayList (java.util.ArrayList)6 ClientRegistrationResponse (org.apache.cxf.rs.security.oauth2.services.ClientRegistrationResponse)6 ClientRegistration (org.apache.cxf.rs.security.oauth2.services.ClientRegistration)5 Response (javax.ws.rs.core.Response)2 PrivateKey (java.security.PrivateKey)1 Bus (org.apache.cxf.Bus)1 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)1 JAXRSClientFactoryBean (org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean)1 UserInfo (org.apache.cxf.rs.security.oidc.common.UserInfo)1