Java Code Examples for org.gluu.oxauth.client.RegisterRequest

The following examples show how to use org.gluu.oxauth.client.RegisterRequest. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: oxTrust   Source File: OpenIdClient.java    License: MIT License 6 votes vote down vote up
private RegisterResponse registerOpenIdClient() {
	logger.info("Registering OpenId client");

	String clientName = this.appConfiguration.getApplicationName() + " client";
	RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, clientName, Arrays.asList(this.appConfiguration.getOpenIdRedirectUrl()));
	registerRequest.setRequestObjectSigningAlg(SignatureAlgorithm.RS256);
	registerRequest.setTokenEndpointAuthMethod(AuthenticationMethod.CLIENT_SECRET_BASIC);

	RegisterClient registerClient = new RegisterClient(openIdConfiguration.getRegistrationEndpoint());
	registerClient.setRequest(registerRequest);
	RegisterResponse response = registerClient.exec();

	if ((response == null) || (response.getStatus() != 200)) {
		throw new ConfigurationException("Failed to register new client");
	}

	return response;
}
 
Example 2
Source Project: oxAuth   Source File: ClientWhiteListBlackListRedirectUris.java    License: MIT License 6 votes vote down vote up
@Parameters({"redirectUris", "sectorIdentifierUri"})
@Test
public void requestClientAssociate(final String redirectUris, final String sectorIdentifierUri) throws Exception {
    showTitle("requestClientAssociate");

    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
            StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setSectorIdentifierUri(sectorIdentifierUri);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(registerRequest);
    registerClient.setExecutor(clientExecutor(true));
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getClientSecretExpiresAt());
    assertNotNull(response.getClaims().get(SCOPE.toString()));

    registrationAccessToken1 = response.getRegistrationAccessToken();
    registrationClientUri1 = response.getRegistrationClientUri();
}
 
Example 3
Source Project: oxAuth   Source File: ClientWhiteListBlackListRedirectUris.java    License: MIT License 6 votes vote down vote up
@Test(dependsOnMethods = "requestClientAssociate")
public void requestClientUpdate() throws Exception {
    showTitle("requestClientUpdate");

    final String redirectUris = "https://www.attacker.com";

    final RegisterRequest registerRequest = new RegisterRequest(registrationAccessToken1);
    registerRequest.setHttpMethod(HttpMethod.PUT);
    registerRequest.setRedirectUris(StringUtils.spaceSeparatedToList(redirectUris));

    final RegisterClient registerClient = new RegisterClient(registrationClientUri1);
    registerClient.setRequest(registerRequest);
    registerClient.setExecutor(clientExecutor(true));
    final RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 400, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getEntity(), "The entity is null");
    assertNotNull(response.getErrorType(), "The error type is null");
    assertNotNull(response.getErrorDescription(), "The error description is null");
}
 
Example 4
Source Project: oxAuth   Source File: RegistrationRestWebServiceHttpTest.java    License: MIT License 6 votes vote down vote up
@Parameters({"redirectUris", "sectorIdentifierUri"})
@Test
public void requestClientAssociate3(final String redirectUris, final String sectorIdentifierUri) throws Exception {
    showTitle("requestClientAssociate3");
    String softwareId = UUID.randomUUID().toString();
    String softwareVersion = "version_3.1.5";
    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
            StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setSectorIdentifierUri(sectorIdentifierUri);
    registerRequest.setSoftwareId(softwareId);
    registerRequest.setSoftwareVersion(softwareVersion);
    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(registerRequest);
    RegisterResponse response = registerClient.exec();
    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getClientSecretExpiresAt());
    assertTrue(response.getClaims().containsKey(SOFTWARE_ID.toString()));
    assertEquals(response.getClaims().get(SOFTWARE_ID.toString()), softwareId);
    assertTrue(response.getClaims().containsKey(SOFTWARE_VERSION.toString()));
    assertEquals(response.getClaims().get(SOFTWARE_VERSION.toString()), softwareVersion);
}
 
Example 5
Source Project: oxAuth   Source File: RegistrationRestWebServiceHttpTest.java    License: MIT License 6 votes vote down vote up
@Test
public void failRegistration_whenRedirectUriIsNotSetForResponseTypeCode() throws Exception {
    showTitle("failRegistration_whenRedirectUriIsNotSetForResponseTypeCode");

    RegisterRequest request = new RegisterRequest();
    request.setResponseTypes(Lists.newArrayList(ResponseType.CODE));

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setExecutor(clientExecutor(true));
    registerClient.setRequest(request);
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 400, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getEntity(), "The entity is null");
    assertNotNull(response.getErrorType(), "The error type is null");
    assertNotNull(response.getErrorDescription(), "The error description is null");
}
 
Example 6
Source Project: oxAuth   Source File: RegistrationRestWebServiceHttpTest.java    License: MIT License 6 votes vote down vote up
@Parameters({"redirectUris"})
@Test
public void requestClientRegistrationFail4(final String redirectUris) throws Exception {
    showTitle("requestClientRegistrationFail4");

    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
            StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setIdTokenSignedResponseAlg(SignatureAlgorithm.NONE); // id_token signature cannot be none

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(registerRequest);
    registerClient.setExecutor(clientExecutor(true));
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 400);
    assertNotNull(response.getEntity());
    assertNotNull(response.getErrorType());
    assertNotNull(response.getErrorDescription());
}
 
Example 7
Source Project: oxAuth   Source File: RegistrationRestWebServiceHttpTest.java    License: MIT License 6 votes vote down vote up
@Parameters({"redirectUris"})
@Test
public void registerWithCustomURI(final String redirectUris) throws Exception {
    showTitle("registerWithCustomURI");

    List<String> redirectUriList = Lists.newArrayList(StringUtils.spaceSeparatedToList(redirectUris));
    redirectUriList.add("myschema://client.example.com/cb"); // URI with custom schema

    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.NATIVE, "oxAuth native test app with custom schema in URI",
            redirectUriList);
    registerRequest.setSubjectType(SubjectType.PUBLIC);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setExecutor(clientExecutor(true));
    registerClient.setRequest(registerRequest);
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getClientSecretExpiresAt());
}
 
Example 8
Source Project: oxAuth   Source File: RegistrationRestWebServiceHttpTest.java    License: MIT License 6 votes vote down vote up
@Parameters({"redirectUris", "sectorIdentifierUri"})
@Test
public void registerWithApplicationTypeNativeAndSubjectTypePairwise(
        final String redirectUris, final String sectorIdentifierUri) throws Exception {
    showTitle("registerWithApplicationTypeNativeAndSubjectTypePairwise");

    List<String> redirectUriList = Lists.newArrayList(StringUtils.spaceSeparatedToList(redirectUris));

    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.NATIVE, "oxAuth native test app",
            redirectUriList);
    registerRequest.setSubjectType(SubjectType.PAIRWISE);
    registerRequest.setSectorIdentifierUri(sectorIdentifierUri);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setExecutor(clientExecutor(true));
    registerClient.setRequest(registerRequest);
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getClientSecretExpiresAt());
}
 
Example 9
Source Project: oxAuth   Source File: RegistrationRestWebServiceHttpTest.java    License: MIT License 6 votes vote down vote up
@Parameters({"redirectUris"})
@Test
public void registerWithHttp1(final String redirectUris) throws Exception {
    showTitle("registerWithHttp1");

    List<String> redirectUriList = Lists.newArrayList(StringUtils.spaceSeparatedToList(redirectUris));
    redirectUriList.add("http://localhost/cb"); // URI with HTTP schema

    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth web test app with HTTP schema in URI",
            redirectUriList);
    registerRequest.setSubjectType(SubjectType.PUBLIC);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setExecutor(clientExecutor(true));
    registerClient.setRequest(registerRequest);
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getClientSecretExpiresAt());
}
 
Example 10
Source Project: oxAuth   Source File: RegistrationRestWebServiceHttpTest.java    License: MIT License 6 votes vote down vote up
@Parameters({"redirectUris"})
@Test
public void registerWithHttp2(final String redirectUris) throws Exception {
    showTitle("registerWithHttp2");

    List<String> redirectUriList = Lists.newArrayList(StringUtils.spaceSeparatedToList(redirectUris));
    redirectUriList.add("http://127.0.0.1/cb"); // URI with HTTP schema

    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth web test app with HTTP schema in URI",
            redirectUriList);
    registerRequest.setSubjectType(SubjectType.PUBLIC);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setExecutor(clientExecutor(true));
    registerClient.setRequest(registerRequest);
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getClientSecretExpiresAt());
}
 
Example 11
Source Project: oxAuth   Source File: RegistrationRestWebServiceHttpTest.java    License: MIT License 6 votes vote down vote up
@Parameters({"redirectUris"})
@Test
public void registerWithHttpFail(final String redirectUris) throws Exception {
    showTitle("registerWithHttpFail");

    List<String> redirectUriList = Lists.newArrayList(StringUtils.spaceSeparatedToList(redirectUris));
    redirectUriList.add("http://www.example.com/cb"); // URI with HTTP schema

    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth web test app with HTTP schema in URI",
            redirectUriList);
    registerRequest.setSubjectType(SubjectType.PUBLIC);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setExecutor(clientExecutor(true));
    registerClient.setRequest(registerRequest);
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 400);
    assertNotNull(response.getEntity());
    assertNotNull(response.getErrorType());
    assertNotNull(response.getErrorDescription());
}
 
Example 12
@Parameters({"sectorIdentifierUri"})
@Test
public void rejectsSectorIdentifierNotContainingRegisteredRedirectUriValues(final String sectorIdentifierUri) throws Exception {
    showTitle("OC5:FeatureTest-Rejects Sector Identifier Not Containing Registered redirect uri Values");

    List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE);

    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
            StringUtils.spaceSeparatedToList("https://not_registered"));
    registerRequest.setSectorIdentifierUri(sectorIdentifierUri);
    registerRequest.setResponseTypes(responseTypes);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(registerRequest);
    RegisterResponse registerResponse = registerClient.exec();

    showClient(registerClient);
    assertEquals(registerResponse.getStatus(), 400, "Unexpected response code: " + registerResponse.getStatus());
    assertNotNull(registerResponse.getErrorType(), "The error type is null");
    assertNotNull(registerResponse.getErrorDescription(), "The error description is null");
}
 
Example 13
Source Project: oxAuth   Source File: Supports3rdPartyInitLoginNoHttps.java    License: MIT License 6 votes vote down vote up
@Parameters({"redirectUri", "clientJwksUri", "postLogoutRedirectUri"})
@Test
public void supports3rdPartyInitLoginNoHttps(final String redirectUri, final String clientJwksUri, final String postLogoutRedirectUri) throws Exception {
    showTitle("supports3rdPartyInitLoginNoHttps");

    // 1. Register Client
    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
            StringUtils.spaceSeparatedToList(redirectUri));
    registerRequest.setContacts(Arrays.asList("[email protected]"));
    registerRequest.setGrantTypes(Arrays.asList(AUTHORIZATION_CODE));
    registerRequest.setResponseTypes(Arrays.asList(CODE));
    registerRequest.setInitiateLoginUri("http://client.example.com/start-3rd-party-initiated-sso");
    registerRequest.setJwksUri(clientJwksUri);
    registerRequest.setPostLogoutRedirectUris(Arrays.asList(postLogoutRedirectUri));
    registerRequest.setTokenEndpointAuthMethod(AuthenticationMethod.CLIENT_SECRET_BASIC);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(registerRequest);
    RegisterResponse registerResponse = registerClient.exec();

    showClient(registerClient);
    assertEquals(registerResponse.getStatus(), 400, "Unexpected response code: " + registerResponse.getEntity());
    assertNotNull(registerResponse.getEntity(), "The entity is null");
    assertNotNull(registerResponse.getErrorType(), "The error type is null");
    assertNotNull(registerResponse.getErrorDescription(), "The error description is null");
}
 
Example 14
@Parameters({"redirectUri"})
@Test
public void rejectRegistrationOfRedirectUriWithFragment(final String redirectUri) throws Exception {
    showTitle("OC5:FeatureTest-Reject Registration of redirect uri with Fragment");

    List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE);

    // 1. Register client
    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
            StringUtils.spaceSeparatedToList(redirectUri + "#foo1=bar"));
    registerRequest.setResponseTypes(responseTypes);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(registerRequest);
    RegisterResponse registerResponse = registerClient.exec();

    showClient(registerClient);
    assertEquals(registerResponse.getStatus(), 400, "Unexpected response code: " + registerResponse.getStatus());
    assertNotNull(registerResponse.getErrorType(), "The error type is null");
    assertNotNull(registerResponse.getErrorDescription(), "The error description is null");
}
 
Example 15
Source Project: oxAuth   Source File: RegistrationRestWebServiceEmbeddedTest.java    License: MIT License 6 votes vote down vote up
@Parameters({"registerPath"})
@Test
public void failRegistration_whenRedirectUriIsNotSetForResponseTypeCode(final String registerPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request();

    String registerRequestContent = null;
    try {
        RegisterRequest registerRequest = new RegisterRequest(null, null, null);
        registerRequest.setResponseTypes(Lists.newArrayList(ResponseType.CODE));

        registerRequestContent = ServerUtil.toPrettyJson(registerRequest.getJSONParameters());
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }

    Response response = request.post(Entity.json(registerRequestContent));
    String entity = response.readEntity(String.class);

    showResponse("requestClientRegistrationFail 1", response, entity);

    assertEquals(response.getStatus(), 400, "Unexpected response code. " + entity);
    TestUtil.assertErrorResponse(entity);
}
 
Example 16
Source Project: oxAuth   Source File: RegistrationRestWebServiceEmbeddedTest.java    License: MIT License 6 votes vote down vote up
@Parameters({"registerPath"})
@Test
public void requestClientRegistrationFail3(final String registerPath) throws Exception {
    Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request();

    String registerRequestContent = null;
    try {

        RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
                Arrays.asList("https://client.example.com/cb#fail_fragment"));

        registerRequestContent = ServerUtil.toPrettyJson(registerRequest.getJSONParameters());
    } catch (JSONException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }

    Response response = request.post(Entity.json(registerRequestContent));
    String entity = response.readEntity(String.class);

    showResponse("requestClientRegistrationFail3", response, entity);

    assertEquals(response.getStatus(), 400, "Unexpected response code. " + entity);
    TestUtil.assertErrorResponse(entity);
}
 
Example 17
Source Project: oxd   Source File: UpdateSiteOperation.java    License: Apache License 2.0 6 votes vote down vote up
private void updateRegisteredClient(Rp rp, RegisterRequest registerRequest) {
    if (StringUtils.isBlank(rp.getClientRegistrationClientUri())) {
        LOG.error("Registration client url is blank.");
        throw new HttpException(ErrorResponseCode.INVALID_REGISTRATION_CLIENT_URL);
    }

    final RegisterClient registerClient = new RegisterClient(rp.getClientRegistrationClientUri());
    registerClient.setRequest(registerRequest);
    registerClient.setExecutor(getHttpService().getClientExecutor());
    final RegisterResponse response = registerClient.exec();
    if (response != null) {
        if (response.getStatus() == 200) {
            LOG.trace("Client updated successfully. for rp - client_id: " + rp.getClientId());
            return;
        } else {
            LOG.error("Response is not OK (200).");
        }
    } else {
        LOG.error("RegisterClient response is null.");
    }
    if (!Strings.isNullOrEmpty(response.getErrorDescription())) {
        LOG.error(response.getErrorDescription());
    }

    throw new RuntimeException("Failed to update client for rp. Details:" + response.getEntity());
}
 
Example 18
Source Project: oxAuth   Source File: RegistrationAction.java    License: MIT License 5 votes vote down vote up
public void execClientRead() {
    try {
        RegisterRequest registerRequest = new RegisterRequest(registrationAccessToken);

        RegisterClient client = new RegisterClient(registrationClientUri);
        client.setRequest(registerRequest);
        RegisterResponse response = client.exec();

        showClientReadResults = true;

        tokenAction.setClientId(response.getClientId());
        tokenAction.setClientSecret(response.getClientSecret());

        backchannelAuthenticationAction.setClientId(response.getClientId());
        backchannelAuthenticationAction.setClientSecret(response.getClientSecret());
        if ( response.getClaims() != null && response.getClaims().containsKey(
                RegisterRequestParam.BACKCHANNEL_TOKEN_DELIVERY_MODE.toString()) ) {
            backchannelAuthenticationAction.setBackchannelTokenDeliveryMode(BackchannelTokenDeliveryMode.fromString(
                    response.getClaims().get(RegisterRequestParam.BACKCHANNEL_TOKEN_DELIVERY_MODE.toString())));
            backchannelTokenDeliveryMode = backchannelAuthenticationAction.getBackchannelTokenDeliveryMode();
        }

        clientReadRequestString = client.getRequestAsString();
        clientReadResponseString = client.getResponseAsString();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
}
 
Example 19
Source Project: oxAuth   Source File: ClientAuthenticationByAccessTokenHttpTest.java    License: MIT License 5 votes vote down vote up
@Test
public void requestClientRegistrationWithCustomAttributes() throws Exception {
    showTitle("requestClientRegistrationWithCustomAttributes");

    List<ResponseType> responseTypes = Arrays.asList(
            ResponseType.CODE,
            ResponseType.TOKEN,
            ResponseType.ID_TOKEN);
    List<GrantType> grantTypes = Arrays.asList(
            GrantType.RESOURCE_OWNER_PASSWORD_CREDENTIALS
    );

    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", Collections.singletonList(REDIRECT_URI));
    registerRequest.setResponseTypes(responseTypes);
    registerRequest.setGrantTypes(grantTypes);
    registerRequest.setAuthenticationMethod(AuthenticationMethod.CLIENT_SECRET_BASIC);
    registerRequest.addCustomAttribute("oxAuthTrustedClient", "true");

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setExecutor(clientExecutor(true));
    registerClient.setRequest(registerRequest);
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getClientSecretExpiresAt());

    clientId = response.getClientId();
    clientSecret = response.getClientSecret();
}
 
Example 20
Source Project: oxAuth   Source File: RegistrationRestWebServiceHttpTest.java    License: MIT License 5 votes vote down vote up
@Test(dependsOnMethods = "requestClientAssociate2")
public void requestClientUpdate() throws Exception {
    showTitle("requestClientUpdate");

    final String logoUriNewValue = "http://www.gluu.org/test/yuriy/logo.png";
    final String contact1NewValue = "[email protected]";
    final String contact2NewValue = "[email protected]";

    final RegisterRequest registerRequest = new RegisterRequest(registrationAccessToken1);
    registerRequest.setHttpMethod(HttpMethod.PUT);
    registerRequest.setContacts(Arrays.asList(contact1NewValue, contact2NewValue));
    registerRequest.setLogoUri(logoUriNewValue);

    final RegisterClient registerClient = new RegisterClient(registrationClientUri1);
    registerClient.setRequest(registerRequest);
    registerClient.setExecutor(clientExecutor(true));
    final RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());

    // check whether info is really updated
    final String responseContacts = response.getClaims().get(CONTACTS.toString());
    final String responseLogoUri = response.getClaims().get(LOGO_URI.toString());

    assertTrue(responseContacts.contains(contact1NewValue) && responseContacts.contains(contact2NewValue));
    assertNotNull(responseLogoUri.equals(logoUriNewValue));
}
 
Example 21
Source Project: oxAuth   Source File: RegistrationRestWebServiceHttpTest.java    License: MIT License 5 votes vote down vote up
@Test(dependsOnMethods = "requestClientAssociate2")
public void requestClientRead() throws Exception {
    showTitle("requestClientRead");

    RegisterRequest registerRequest = new RegisterRequest(registrationAccessToken1);

    RegisterClient registerClient = new RegisterClient(registrationClientUri1);
    registerClient.setRequest(registerRequest);
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getRegistrationClientUri());
    assertNotNull(response.getClientSecretExpiresAt());
    assertNotNull(response.getClaims().get(APPLICATION_TYPE.toString()));
    assertNotNull(response.getClaims().get(POLICY_URI.toString()));
    assertNotNull(response.getClaims().get(REQUEST_OBJECT_SIGNING_ALG.toString()));
    assertNotNull(response.getClaims().get(CONTACTS.toString()));
    assertNotNull(response.getClaims().get(SECTOR_IDENTIFIER_URI.toString()));
    assertNotNull(response.getClaims().get(SUBJECT_TYPE.toString()));
    assertNotNull(response.getClaims().get(ID_TOKEN_SIGNED_RESPONSE_ALG.toString()));
    assertNotNull(response.getClaims().get(JWKS_URI.toString()));
    assertNotNull(response.getClaims().get(CLIENT_NAME.toString()));
    assertNotNull(response.getClaims().get(LOGO_URI.toString()));
    assertNotNull(response.getClaims().get(REQUEST_URIS.toString()));
    assertNotNull(response.getClaims().get(SCOPE.toString()));
}
 
Example 22
Source Project: oxAuth   Source File: RegistrationRestWebServiceHttpTest.java    License: MIT License 5 votes vote down vote up
@Parameters({"redirectUris", "sectorIdentifierUri"})
@Test
// ATTENTION : uncomment test annotation only if 112-customAttributes.ldif (located in server test resources)
// is loaded by ldap server.
public void requestClientRegistrationWithCustomAttributes(
        final String redirectUris, final String sectorIdentifierUri) throws Exception {
    showTitle("requestClientRegistrationWithCustomAttributes");

    final RegisterRequest request = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
            StringUtils.spaceSeparatedToList(redirectUris));

    // custom attribute must be declared in oxauth-config.xml in dynamic-registration-custom-attribute tag
    request.addCustomAttribute("myCustomAttr1", "customAttrValue1");
    request.addCustomAttribute("myCustomAttr2", "customAttrValue2");
    request.setSectorIdentifierUri(sectorIdentifierUri);

    final RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(request);
    final RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getClientSecretExpiresAt());
}
 
Example 23
Source Project: oxAuth   Source File: JsonApplierTest.java    License: MIT License 5 votes vote down vote up
@Test
public void apply_forListAndJSONObjectAsTarget_shouldTransferPropertyToTarget() {
    RegisterRequest request = new RegisterRequest();
    request.setAdditionalAudience(Lists.newArrayList("aud1", "aud2"));

    JSONObject target = new JSONObject();

    JsonApplier.getInstance().apply(request, target);

    assertEquals(new JSONArray(Lists.newArrayList("aud1", "aud2")), target.getJSONArray("additional_audience"));
}
 
Example 24
Source Project: oxAuth   Source File: JsonApplierTest.java    License: MIT License 5 votes vote down vote up
@Test
public void apply_forListAndMapAsTarget_shouldTransferPropertyToTarget() {
    RegisterRequest request = new RegisterRequest();
    request.setAdditionalAudience(Lists.newArrayList("aud1", "aud2"));

    Map<String, String> target = new HashMap<>();

    JsonApplier.getInstance().apply(request, target);

    assertEquals(new JSONArray(Lists.newArrayList("aud1", "aud2")).toString(), target.get("additional_audience"));
}
 
Example 25
Source Project: oxAuth   Source File: JsonApplierTest.java    License: MIT License 5 votes vote down vote up
@Test
public void apply_forListAndJavaObjectAsTarget_shouldTransferPropertyToTarget() {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("additional_audience", new JSONArray(Lists.newArrayList("aud1", "aud2")));

    final RegisterRequest registerRequest = new RegisterRequest();
    JsonApplier.getInstance().apply(jsonObject, registerRequest);

    assertEquals(Lists.newArrayList("aud1", "aud2"), registerRequest.getAdditionalAudience());
}
 
Example 26
Source Project: oxAuth   Source File: EnablesDynamicRegistration.java    License: MIT License 5 votes vote down vote up
@Parameters({"redirectUris", "sectorIdentifierUri", "clientJwksUri"})
@Test
public void enablesDynamicRegistration(final String redirectUris, final String sectorIdentifierUri,
                                       final String clientJwksUri) throws Exception {
    showTitle("OC5:FeatureTest-Enables Dynamic Registration");

    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
            StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setContacts(Arrays.asList("[email protected]", "[email protected]"));
    registerRequest.setLogoUri("http://www.gluu.org/wp-content/themes/gluursn/images/logo.png");
    registerRequest.setTokenEndpointAuthMethod(AuthenticationMethod.CLIENT_SECRET_JWT);
    registerRequest.setPolicyUri("http://www.gluu.org/policy");
    registerRequest.setJwksUri(clientJwksUri);
    registerRequest.setSectorIdentifierUri(sectorIdentifierUri);
    registerRequest.setSubjectType(SubjectType.PUBLIC);
    registerRequest.setRequestObjectSigningAlg(SignatureAlgorithm.RS256);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(registerRequest);
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getRegistrationClientUri());
    assertNotNull(response.getClientIdIssuedAt());
    assertNotNull(response.getClientSecretExpiresAt());
}
 
Example 27
Source Project: oxAuth   Source File: Supports3rdPartyInitLogin.java    License: MIT License 5 votes vote down vote up
@Parameters({"redirectUri", "clientJwksUri", "initiateLoginUri", "postLogoutRedirectUri"})
@Test
public void supports3rdPartyInitLogin(final String redirectUri, final String clientJwksUri, final String initiateLoginUri, final String postLogoutRedirectUri) throws Exception {
    showTitle("supports3rdPartyInitLogin");

    // 1. Register Client
    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
            StringUtils.spaceSeparatedToList(redirectUri));
    registerRequest.setContacts(Arrays.asList("[email protected]"));
    registerRequest.setGrantTypes(Arrays.asList(AUTHORIZATION_CODE));
    registerRequest.setResponseTypes(Arrays.asList(CODE));
    registerRequest.setInitiateLoginUri(initiateLoginUri);
    registerRequest.setJwksUri(clientJwksUri);
    registerRequest.setPostLogoutRedirectUris(Arrays.asList(postLogoutRedirectUri));
    registerRequest.setTokenEndpointAuthMethod(AuthenticationMethod.CLIENT_SECRET_BASIC);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(registerRequest);
    RegisterResponse registerResponse = registerClient.exec();

    showClient(registerClient);
    assertEquals(registerResponse.getStatus(), 200, "Unexpected response code: " + registerResponse.getEntity());
    assertNotNull(registerResponse.getClientId());
    assertNotNull(registerResponse.getClientSecret());
    assertNotNull(registerResponse.getRegistrationAccessToken());
    assertNotNull(registerResponse.getClientSecretExpiresAt());
    assertEquals(registerResponse.getClaims().get(APPLICATION_TYPE.toString()), ApplicationType.WEB.toString());
    assertEquals(registerResponse.getClaims().get(INITIATE_LOGIN_URI.toString()), initiateLoginUri);
}
 
Example 28
Source Project: oxAuth   Source File: UsesDynamicRegistration.java    License: MIT License 5 votes vote down vote up
@Parameters({"redirectUris", "sectorIdentifierUri", "clientJwksUri"})
@Test
public void usesDynamicRegistration(final String redirectUris, final String sectorIdentifierUri,
                                       final String clientJwksUri) throws Exception {
    showTitle("OC5:FeatureTest-Uses Dynamic Registration");

    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app",
            StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setContacts(Arrays.asList("[email protected]", "[email protected]"));
    registerRequest.setLogoUri("http://www.gluu.org/wp-content/themes/gluursn/images/logo.png");
    registerRequest.setTokenEndpointAuthMethod(AuthenticationMethod.CLIENT_SECRET_JWT);
    registerRequest.setPolicyUri("http://www.gluu.org/policy");
    registerRequest.setJwksUri(clientJwksUri);
    registerRequest.setSectorIdentifierUri(sectorIdentifierUri);
    registerRequest.setSubjectType(SubjectType.PUBLIC);
    registerRequest.setRequestObjectSigningAlg(SignatureAlgorithm.RS256);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(registerRequest);
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getRegistrationClientUri());
    assertNotNull(response.getClientIdIssuedAt());
    assertNotNull(response.getClientSecretExpiresAt());
}
 
Example 29
Source Project: oxAuth   Source File: ExternalDynamicClientRegistrationService.java    License: MIT License 5 votes vote down vote up
public boolean executeExternalCreateClientMethod(CustomScriptConfiguration customScriptConfiguration, RegisterRequest registerRequest, Client client) {
    try {
        log.debug("Executing python 'createClient' method");
        ClientRegistrationType externalClientRegistrationType = (ClientRegistrationType) customScriptConfiguration.getExternalType();
        Map<String, SimpleCustomProperty> configurationAttributes = customScriptConfiguration.getConfigurationAttributes();
        return externalClientRegistrationType.createClient(registerRequest, client, configurationAttributes);
    } catch (Exception ex) {
        log.error(ex.getMessage(), ex);
        saveScriptError(customScriptConfiguration.getCustomScript(), ex);
    }
    
    return false;
}
 
Example 30
Source Project: oxAuth   Source File: ExternalDynamicClientRegistrationService.java    License: MIT License 5 votes vote down vote up
public boolean executeExternalCreateClientMethods(RegisterRequest registerRequest, Client client) {
    boolean result = true;
    for (CustomScriptConfiguration customScriptConfiguration : this.customScriptConfigurations) {
        if (customScriptConfiguration.getExternalType().getApiVersion() > 1) {
            result &= executeExternalCreateClientMethod(customScriptConfiguration, registerRequest, client);
            if (!result) {
                return result;
            }
        }
    }

    return result;
}