Search in sources :

Example 1 with OIDCRegistrationRequestProfile

use of org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationRequestProfile in project identity-inbound-auth-oauth by wso2-extensions.

the class OIDCRegistrationRequestFactory method create.

@Override
public void create(IdentityRequest.IdentityRequestBuilder builder, HttpServletRequest request, HttpServletResponse response) throws FrameworkClientException {
    OIDCRegistrationRequest.OIDCRegistrationRequestBuilder registerRequestBuilder = null;
    if (builder instanceof OIDCRegistrationRequest.OIDCRegistrationRequestBuilder) {
        registerRequestBuilder = (OIDCRegistrationRequest.OIDCRegistrationRequestBuilder) builder;
        OIDCRegistrationRequestProfile oidcRegistrationRequestProfile = new OIDCRegistrationRequestProfile();
        registerRequestBuilder.setRegistrationRequestProfile(oidcRegistrationRequestProfile);
        super.create(registerRequestBuilder, request, response);
    } else {
        // This else part will not be reached from application logic.
        log.error("Can't create registerRequestBuilder. builder is not an instance of " + "OIDCRegistrationRequest.OIDCRegistrationRequestBuilder");
    }
}
Also used : OIDCRegistrationRequest(org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationRequest) OIDCRegistrationRequestProfile(org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationRequestProfile)

Example 2 with OIDCRegistrationRequestProfile

use of org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationRequestProfile in project identity-inbound-auth-oauth by wso2-extensions.

the class OIDCRegistrationRequestFactoryTest method testCreate.

@Test(dataProvider = "OIDCRequestBuilderCreationData")
public void testCreate(String request, String sectorIdUrl, String subjectType, String tokenSignAlg, String tokenEncrAlg, String tokenEncrEnc, String userInfoRespSignAlg, String userInfoRespEncrAlg, String userInfoRespEnceEnc, String reqObjSignAlg, String reqObjEncrAlg, String reqObjEncrEnc, String tokenEPAuthSignAlg, String defaultMaxAge, String requireAuthTime, String defaultAcrValues, String initLoginUrl, List<String> requestUris) throws Exception {
    HttpServletRequest mockRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockResponse = mock(HttpServletResponse.class);
    when(mockRequest.getReader()).thenReturn(new BufferedReader(new StringReader(request)));
    when(mockRequest.getHeaderNames()).thenReturn(Collections.<String>emptyEnumeration());
    when(mockRequest.getAttributeNames()).thenReturn(Collections.<String>emptyEnumeration());
    OIDCRegistrationRequest.OIDCRegistrationRequestBuilder requestBuilder = testedRegistrationRequestFactory.create(mockRequest, mockResponse);
    RegistrationRequest registrationRequest = requestBuilder.build();
    RegistrationRequestProfile requestProfile = registrationRequest.getRegistrationRequestProfile();
    assertTrue(requestProfile instanceof OIDCRegistrationRequestProfile, "Request profile should be an instance " + "of OIDCRegistrationRequestProfile");
    OIDCRegistrationRequestProfile oidcRegRequestProfile = (OIDCRegistrationRequestProfile) requestProfile;
    assertEquals(requestBuilder.getRequest(), mockRequest, "Builder should have the provided request.");
    assertEquals(requestBuilder.getResponse(), mockResponse, "Builder should have the provided response.");
    assertEquals(oidcRegRequestProfile.getSectorIdentifierUri(), sectorIdUrl, "Invalid Sector Id URL");
    assertEquals(oidcRegRequestProfile.getSubjectType(), subjectType, "Invalid subject type");
    assertEquals(oidcRegRequestProfile.getIdTokenSignedResponseAlg(), tokenSignAlg, "Invalid token sign " + "algorithm");
    assertEquals(oidcRegRequestProfile.getIdTokenEncryptedResponseAlg(), tokenEncrAlg, "Invalid token encryption" + " alg");
    assertEquals(oidcRegRequestProfile.getIdTokenEncryptedResponseEnc(), tokenEncrEnc, "Invalid token encryption" + " enc");
    assertEquals(oidcRegRequestProfile.getUserinfoSignedResponseAlg(), userInfoRespSignAlg, "Invalid userinfo " + "response sign alg");
    assertEquals(oidcRegRequestProfile.getUserinfoencryptedResponseAlg(), userInfoRespEncrAlg, "Invalid userinfo " + "response encr alg");
    assertEquals(oidcRegRequestProfile.getUserinfoEncryptedResponseEnc(), userInfoRespEnceEnc, "Invalid userinfo " + "response encr enc");
    assertEquals(oidcRegRequestProfile.getRequestObjectSigningAlg(), reqObjSignAlg, "Invalid request obj sign " + "alg");
    assertEquals(oidcRegRequestProfile.getRequestObjectEncryptionAlg(), reqObjEncrAlg, "Invalid request obj encr" + " alg");
    assertEquals(oidcRegRequestProfile.getRequestObjectEncryptionEnc(), reqObjEncrEnc, "Invalid request obj encr" + " enc");
    assertEquals(oidcRegRequestProfile.getTokenEndpointAuthSigningAlg(), tokenEPAuthSignAlg, "Invalid token " + "endpoint auth response alg.");
    assertEquals(oidcRegRequestProfile.getDefaultMaxAge(), defaultMaxAge, "Invalid default max age");
    assertEquals(oidcRegRequestProfile.getRequireAuthTime(), requireAuthTime, "Invalid require auth time");
    assertEquals(oidcRegRequestProfile.getDefaultAcrValues(), defaultAcrValues, "Invalid default acr values");
    assertEquals(oidcRegRequestProfile.getInitiateLoginUri(), initLoginUrl, "Invalid initiate login uri");
    assertTrue(CollectionUtils.isEqualCollection(oidcRegRequestProfile.getRequestUris(), requestUris), "Invalid " + "request URLs ");
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) OIDCRegistrationRequest(org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationRequest) RegistrationRequestProfile(org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequestProfile) OIDCRegistrationRequestProfile(org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationRequestProfile) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) OIDCRegistrationRequestProfile(org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationRequestProfile) HttpServletResponse(javax.servlet.http.HttpServletResponse) RegistrationRequest(org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequest) OIDCRegistrationRequest(org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationRequest) Test(org.testng.annotations.Test) IdentityBaseTest(org.wso2.carbon.identity.testutil.IdentityBaseTest)

Example 3 with OIDCRegistrationRequestProfile

use of org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationRequestProfile in project identity-inbound-auth-oauth by wso2-extensions.

the class OIDCRegistrationRequestFactory method parseJson.

@Override
protected void parseJson(JSONObject jsonData, RegistrationRequest.RegistrationRequestBuilder requestBuilder) throws FrameworkClientException {
    super.parseJson(jsonData, requestBuilder);
    RegistrationRequestProfile registrationRequestProfile = requestBuilder.getRegistrationRequestProfile();
    if (registrationRequestProfile instanceof OIDCRegistrationRequestProfile) {
        OIDCRegistrationRequestProfile oidcRegistrationRequestProfile = (OIDCRegistrationRequestProfile) registrationRequestProfile;
        oidcRegistrationRequestProfile.setSectorIdentifierUri((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.SECTOR_IDENTIFIER_URI));
        oidcRegistrationRequestProfile.setSubjectType((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.SUBJECT_TYPE));
        oidcRegistrationRequestProfile.setIdTokenSignedResponseAlg((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.ID_TOKEN_SIGNED_RESPONSE_ALG));
        oidcRegistrationRequestProfile.setIdTokenEncryptedResponseAlg((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.ID_TOKEN_ENCRYPTED_RESPONSE_ALG));
        oidcRegistrationRequestProfile.setIdTokenEncryptedResponseEnc((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.ID_TOKEN_ENCRYPTED_RESPONSE_ENC));
        oidcRegistrationRequestProfile.setUserinfoSignedResponseAlg((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.USERINFO_SIGNED_RESPONSE_ALG));
        oidcRegistrationRequestProfile.setUserinfoencryptedResponseAlg((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.USERINFO_ENCRYPTED_RESPONSE_ALG));
        oidcRegistrationRequestProfile.setUserinfoEncryptedResponseEnc((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.USERINFO_ENCRYPTED_RESPONSE_ENC));
        oidcRegistrationRequestProfile.setRequestObjectSigningAlg((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.REQUEST_OBJECT_SIGNING_ALG));
        oidcRegistrationRequestProfile.setRequestObjectEncryptionAlg((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.REQUEST_OBJECT_ENCRYPTION_ALG));
        oidcRegistrationRequestProfile.setRequestObjectEncryptionEnc((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.REQUEST_OBJECT_ENCRYPTION_ENC));
        oidcRegistrationRequestProfile.setTokenEndpointAuthSigningAlg((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.TOKEN_ENDPOINT_AUTH_SIGNING_ALG));
        oidcRegistrationRequestProfile.setDefaultMaxAge((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.DEFAULT_MAX_AGE));
        oidcRegistrationRequestProfile.setRequireAuthTime((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.REQUIRE_AUTH_TIME));
        oidcRegistrationRequestProfile.setDefaultAcrValues((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.DEFAULT_ACR_VALUES));
        oidcRegistrationRequestProfile.setInitiateLoginUri((String) jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.INITIATE_LOGIN_URI));
        Object obj = jsonData.get(OIDCRegistrationRequest.OIDCRegistrationRequestConstants.REQUEST_URIS);
        if (obj instanceof JSONArray) {
            JSONArray requestURIs = (JSONArray) obj;
            for (Object requestURI : requestURIs) {
                oidcRegistrationRequestProfile.getRequestUris().add(requestURI.toString());
            }
        } else if (obj instanceof String) {
            oidcRegistrationRequestProfile.getRequestUris().add((String) obj);
        }
    }
}
Also used : RegistrationRequestProfile(org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequestProfile) OIDCRegistrationRequestProfile(org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationRequestProfile) OIDCRegistrationRequestProfile(org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationRequestProfile) JSONArray(org.json.simple.JSONArray) JSONObject(org.json.simple.JSONObject)

Aggregations

OIDCRegistrationRequestProfile (org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationRequestProfile)3 RegistrationRequestProfile (org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequestProfile)2 OIDCRegistrationRequest (org.wso2.carbon.identity.oidc.dcr.model.OIDCRegistrationRequest)2 BufferedReader (java.io.BufferedReader)1 StringReader (java.io.StringReader)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 JSONArray (org.json.simple.JSONArray)1 JSONObject (org.json.simple.JSONObject)1 Test (org.testng.annotations.Test)1 RegistrationRequest (org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequest)1 IdentityBaseTest (org.wso2.carbon.identity.testutil.IdentityBaseTest)1