Search in sources :

Example 16 with JsonMapObjectProvider

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

the class OIDCDynamicRegistrationTest method testGetClientRegNotAvail.

@org.junit.Test
public void testGetClientRegNotAvail() throws Exception {
    URL busFile = OIDCDynamicRegistrationTest.class.getResource("client.xml");
    String address = "https://localhost:" + DYNREG_SERVER.getPort() + "/services/dynamic/register";
    WebClient wc = WebClient.create(address, Collections.singletonList(new JsonMapObjectProvider()), busFile.toString());
    Response r = wc.accept("application/json").path("some-client-id").get();
    assertEquals(401, r.getStatus());
}
Also used : ClientRegistrationResponse(org.apache.cxf.rs.security.oauth2.services.ClientRegistrationResponse) Response(javax.ws.rs.core.Response) JsonMapObjectProvider(org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 17 with JsonMapObjectProvider

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

the class OIDCDynamicRegistrationTest method testUpdateClient.

@org.junit.Test
public void testUpdateClient() 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));
    final ClientRegistration reg = newClientRegistrationCodeGrant();
    final ClientRegistrationResponse clientRegistrationResponse = wc.post(reg, ClientRegistrationResponse.class);
    final String regAccessToken = clientRegistrationResponse.getRegistrationAccessToken();
    assertNotNull(regAccessToken);
    reg.setScope(OidcUtils.getEmailScope());
    final ClientRegistration updatedClientRegistration = wc.path(clientRegistrationResponse.getClientId()).authorization(new ClientAccessToken(OAuthConstants.BEARER_AUTHORIZATION_SCHEME, regAccessToken)).put(reg, ClientRegistration.class);
    assertEquals(OidcUtils.getEmailScope(), updatedClientRegistration.getScope());
    // https://tools.ietf.org/html/rfc7592#section-2.2
    assertNull(updatedClientRegistration.getProperty("registration_access_token"));
    assertNull(updatedClientRegistration.getProperty("registration_client_uri"));
    assertNull(updatedClientRegistration.getProperty("client_secret_expires_at"));
    assertNull(updatedClientRegistration.getProperty("client_id_issued_at"));
    wc.authorization(null);
    assertEquals(Status.UNAUTHORIZED.getStatusCode(), wc.put(reg).getStatus());
    assertEquals(Status.UNAUTHORIZED.getStatusCode(), wc.delete().getStatus());
    wc.authorization(new ClientAccessToken(OAuthConstants.BEARER_AUTHORIZATION_SCHEME, regAccessToken));
    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