Search in sources :

Example 1 with ClientRegistrationResponse

use of org.apache.cxf.rs.security.oauth2.services.ClientRegistrationResponse in project cxf by apache.

the class JAXRSOAuth2TlsTest method testRegisterClientTwoWayTLSClientIdBoundDynReg.

@Test
public void testRegisterClientTwoWayTLSClientIdBoundDynReg() throws Exception {
    String dynRegAddress = "https://localhost:" + PORT + "/oauth2Jwt/register";
    WebClient wcDynReg = createDynRegWebClient(dynRegAddress);
    wcDynReg.accept("application/json").type("application/json");
    ClientRegistration reg = newClientRegistration();
    wcDynReg.authorization(new ClientAccessToken("Bearer", "123456789"));
    ClientRegistrationResponse resp = wcDynReg.post(reg, ClientRegistrationResponse.class);
    doTestTwoWayTLSClientIdBoundJwt(resp.getClientId());
    // delete the client
    String regAccessToken = resp.getRegistrationAccessToken();
    assertNotNull(regAccessToken);
    wcDynReg.path(resp.getClientId());
    wcDynReg.authorization(new ClientAccessToken("Bearer", regAccessToken));
    assertEquals(200, wcDynReg.delete().getStatus());
    assertNotNull(regAccessToken);
}
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) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 2 with ClientRegistrationResponse

use of org.apache.cxf.rs.security.oauth2.services.ClientRegistrationResponse in project cxf by apache.

the class OIDCDynamicRegistrationTest method testRegisterClientInitialAccessTokenCodeGrant.

@org.junit.Test
public void testRegisterClientInitialAccessTokenCodeGrant() 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 = newClientRegistrationCodeGrant();
    ClientRegistrationResponse resp = null;
    assertEquals(401, wc.post(reg).getStatus());
    wc.authorization(new ClientAccessToken("Bearer", "123456789"));
    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());
    assertEquals(401, wc.get().getStatus());
    wc.authorization(new ClientAccessToken("Bearer", regAccessToken));
    ClientRegistration clientRegResp = wc.get(ClientRegistration.class);
    testCommonRegCodeGrantProperties(clientRegResp);
    assertNull(clientRegResp.getTokenEndpointAuthMethod());
    assertEquals(200, wc.delete().getStatus());
}
Also used : ClientRegistration(org.apache.cxf.rs.security.oauth2.services.ClientRegistration) ClientRegistrationResponse(org.apache.cxf.rs.security.oauth2.services.ClientRegistrationResponse) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) JsonMapObjectProvider(org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 3 with ClientRegistrationResponse

use of org.apache.cxf.rs.security.oauth2.services.ClientRegistrationResponse in project cxf by apache.

the class OIDCDynamicRegistrationTest method testRegisterClientPasswordGrantPublic.

@org.junit.Test
public void testRegisterClientPasswordGrantPublic() 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));
    reg.setTokenEndpointAuthMethod(OAuthConstants.TOKEN_ENDPOINT_AUTH_NONE);
    wc.authorization(new ClientAccessToken("Bearer", "123456789"));
    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);
    wc.reset();
    wc.path(resp.getClientId());
    wc.authorization(new ClientAccessToken("Bearer", regAccessToken));
    ClientRegistration clientRegResp = wc.get(ClientRegistration.class);
    assertEquals("native", clientRegResp.getApplicationType());
    assertEquals("dynamic_client", clientRegResp.getClientName());
    assertEquals(Collections.singletonList(OAuthConstants.RESOURCE_OWNER_GRANT), clientRegResp.getGrantTypes());
    assertEquals(OAuthConstants.TOKEN_ENDPOINT_AUTH_NONE, 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 4 with ClientRegistrationResponse

use of org.apache.cxf.rs.security.oauth2.services.ClientRegistrationResponse 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:" + PORT + "/services/dynamicWithAt/register";
    WebClient wc = WebClient.create(address, Collections.singletonList(new JsonMapObjectProvider()), busFile.toString());
    wc.accept("application/json").type("application/json");
    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 = null;
    assertEquals(401, wc.post(reg).getStatus());
    wc.authorization(new ClientAccessToken("Bearer", "123456789"));
    resp = wc.post(reg, ClientRegistrationResponse.class);
    assertNotNull(resp.getClientId());
    assertNull(resp.getClientSecret());
    assertEquals(address + "/" + resp.getClientId(), resp.getRegistrationClientUri());
    String regAccessToken = resp.getRegistrationAccessToken();
    assertNotNull(regAccessToken);
    wc.reset();
    wc.path(resp.getClientId());
    assertEquals(401, wc.get().getStatus());
    wc.authorization(new ClientAccessToken("Bearer", regAccessToken));
    ClientRegistration clientRegResp = wc.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) ClientRegistrationResponse(org.apache.cxf.rs.security.oauth2.services.ClientRegistrationResponse) ClientAccessToken(org.apache.cxf.rs.security.oauth2.common.ClientAccessToken) JsonMapObjectProvider(org.apache.cxf.jaxrs.provider.json.JsonMapObjectProvider) WebClient(org.apache.cxf.jaxrs.client.WebClient) URL(java.net.URL)

Example 5 with ClientRegistrationResponse

use of org.apache.cxf.rs.security.oauth2.services.ClientRegistrationResponse 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

WebClient (org.apache.cxf.jaxrs.client.WebClient)5 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)5 ClientRegistration (org.apache.cxf.rs.security.oauth2.services.ClientRegistration)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 Test (org.junit.Test)1