Search in sources :

Example 11 with ClientRegistration

use of org.apache.cxf.rs.security.oauth2.services.ClientRegistration 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:" + PORT + "/services/dynamicWithAt/register";
    WebClient wc = WebClient.create(address, Collections.singletonList(new JsonMapObjectProvider()), busFile.toString());
    wc.accept("application/json").type("application/json");
    ClientRegistration reg = new ClientRegistration();
    reg.setClientName("dynamic_client");
    reg.setGrantTypes(Collections.singletonList(OAuthConstants.RESOURCE_OWNER_GRANT));
    wc.authorization(new ClientAccessToken("Bearer", "123456789"));
    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);
    wc.reset();
    wc.path(resp.getClientId());
    wc.authorization(new ClientAccessToken("Bearer", regAccessToken));
    ClientRegistration clientRegResp = wc.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)

Aggregations

ClientRegistration (org.apache.cxf.rs.security.oauth2.services.ClientRegistration)8 WebClient (org.apache.cxf.jaxrs.client.WebClient)5 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)5 ClientRegistrationResponse (org.apache.cxf.rs.security.oauth2.services.ClientRegistrationResponse)5 URL (java.net.URL)4 JsonMapObjectProvider (org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider)4 Client (org.apache.cxf.rs.security.oauth2.common.Client)3 LinkedList (java.util.LinkedList)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Produces (javax.ws.rs.Produces)1 SecurityContext (javax.ws.rs.core.SecurityContext)1 UserSubject (org.apache.cxf.rs.security.oauth2.common.UserSubject)1 Test (org.junit.Test)1