Search in sources :

Example 1 with DCRMessageContext

use of org.wso2.carbon.identity.oauth.dcr.context.DCRMessageContext in project identity-inbound-auth-oauth by wso2-extensions.

the class RegistrationHandler method handle.

@Override
public IdentityResponse.IdentityResponseBuilder handle(DCRMessageContext dcrMessageContext) throws DCRException {
    if (log.isDebugEnabled()) {
        log.debug("Request processing started by RegistrationRequestProcessor.");
    }
    RegistrationResponse.DCRRegisterResponseBuilder dcrRegisterResponseBuilder = null;
    RegistrationRequest registerRequest = (RegistrationRequest) dcrMessageContext.getIdentityRequest();
    RegistrationRequestProfile registrationRequestProfile = registerRequest.getRegistrationRequestProfile();
    registrationRequestProfile.setTenantDomain(registerRequest.getTenantDomain());
    RegistrationResponseProfile registrationResponseProfile = DCRManagementService.getInstance().registerOAuthApplication(registrationRequestProfile);
    dcrRegisterResponseBuilder = new RegistrationResponse.DCRRegisterResponseBuilder();
    dcrRegisterResponseBuilder.setRegistrationResponseProfile(registrationResponseProfile);
    return dcrRegisterResponseBuilder;
}
Also used : RegistrationRequestProfile(org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequestProfile) RegistrationResponseProfile(org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile) RegistrationResponse(org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse) RegistrationRequest(org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequest)

Example 2 with DCRMessageContext

use of org.wso2.carbon.identity.oauth.dcr.context.DCRMessageContext in project identity-inbound-auth-oauth by wso2-extensions.

the class DCRProcessorTest method testProcessWithException.

@Test(dataProvider = "instanceType&ErrorcodeProvider")
public void testProcessWithException(String request, Object identityRequest, String errorCode) throws Exception {
    mockHandlerManager = mock(HandlerManager.class);
    mockStatic(HandlerManager.class);
    when(HandlerManager.getInstance()).thenReturn(mockHandlerManager);
    DCRMessageContext dcrMessageContext = mock(DCRMessageContext.class);
    whenNew(DCRMessageContext.class).withArguments(identityRequest).thenReturn(dcrMessageContext);
    if (request.equals("RegistrationRequest")) {
        RegistrationHandler registrationHandler = mock(RegistrationHandler.class);
        when(mockHandlerManager.getRegistrationHandler(dcrMessageContext)).thenReturn(registrationHandler);
        if (errorCode.isEmpty()) {
            doThrow(new DCRException("")).when(registrationHandler).handle(dcrMessageContext);
        } else {
            doThrow(new DCRException(errorCode, "")).when(registrationHandler).handle(dcrMessageContext);
        }
        try {
            dcrProcessor.process((RegistrationRequest) identityRequest);
            fail("Expected exception IdentityException not thrown by process method");
        } catch (IdentityException ex) {
            if (errorCode.isEmpty()) {
                assertEquals(ex.getErrorCode(), ErrorCodes.BAD_REQUEST.toString());
            } else {
                assertEquals(ex.getErrorCode(), errorCode);
            }
        }
    } else if (request.equals("UnregistrationRequest")) {
        UnRegistrationHandler unRegistrationHandler = mock(UnRegistrationHandler.class);
        when(mockHandlerManager.getUnRegistrationHandler(dcrMessageContext)).thenReturn(unRegistrationHandler);
        if (errorCode.isEmpty()) {
            doThrow(new DCRException("")).when(unRegistrationHandler).handle(dcrMessageContext);
        } else {
            doThrow(new DCRException(errorCode, "")).when(unRegistrationHandler).handle(dcrMessageContext);
        }
        try {
            dcrProcessor.process((UnregistrationRequest) identityRequest);
            fail("Expected exception IdentityException not thrown by registerOAuthApplication");
        } catch (IdentityException ex) {
            if (errorCode.isEmpty()) {
                assertEquals(ex.getMessage(), ErrorCodes.BAD_REQUEST.toString());
            } else {
                assertEquals(ex.getMessage(), errorCode);
            }
        }
    }
}
Also used : UnRegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.UnRegistrationHandler) UnregistrationRequest(org.wso2.carbon.identity.oauth.dcr.model.UnregistrationRequest) HandlerManager(org.wso2.carbon.identity.oauth.dcr.util.HandlerManager) RegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.RegistrationHandler) UnRegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.UnRegistrationHandler) DCRMessageContext(org.wso2.carbon.identity.oauth.dcr.context.DCRMessageContext) IdentityException(org.wso2.carbon.identity.base.IdentityException) DCRException(org.wso2.carbon.identity.oauth.dcr.DCRException) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with DCRMessageContext

use of org.wso2.carbon.identity.oauth.dcr.context.DCRMessageContext in project identity-inbound-auth-oauth by wso2-extensions.

the class HandlerManagerTest method buildUnRegistrationHandlers.

@DataProvider(name = "BuildUnRegistrationHandlers")
public Object[][] buildUnRegistrationHandlers() {
    Map<String, String> param = new HashMap<String, String>();
    param.put("client_id", "N2QqQluzQuL5X6CtM3KZwqzLQhUa");
    param.put("client_secret", "4AXWrN88aEfMvq2h_G0dN05KRsUa");
    DCRMessageContext dcrMessageContext = new DCRMessageContext(param);
    UnRegistrationHandler unRegistrationHandler1 = new UnRegistrationHandler();
    UnRegistrationHandler unRegistrationHandler2 = new UnRegistrationHandler();
    List<UnRegistrationHandler> unRegistrationHandlers1 = new ArrayList<>();
    unRegistrationHandlers1.add(unRegistrationHandler1);
    unRegistrationHandlers1.add(unRegistrationHandler2);
    List<UnRegistrationHandler> unRegistrationHandlers2 = new ArrayList<>();
    unRegistrationHandlers2.add(unRegistrationHandler1);
    List<UnRegistrationHandler> unRegistrationHandlers3 = new ArrayList<>();
    return new Object[][] { { dcrMessageContext, null }, { dcrMessageContext, unRegistrationHandlers1 }, { dcrMessageContext, unRegistrationHandlers2 }, { dcrMessageContext, unRegistrationHandlers3 } };
}
Also used : UnRegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.UnRegistrationHandler) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DCRMessageContext(org.wso2.carbon.identity.oauth.dcr.context.DCRMessageContext) DataProvider(org.testng.annotations.DataProvider)

Example 4 with DCRMessageContext

use of org.wso2.carbon.identity.oauth.dcr.context.DCRMessageContext in project identity-inbound-auth-oauth by wso2-extensions.

the class HandlerManagerTest method buildRegistrationHandlers.

@DataProvider(name = "BuildRegistrationHandlers")
public Object[][] buildRegistrationHandlers() {
    Map<String, String> param = new HashMap<String, String>();
    param.put("client_id", "N2QqQluzQuL5X6CtM3KZwqzLQhUa");
    param.put("client_secret", "4AXWrN88aEfMvq2h_G0dN05KRsUa");
    DCRMessageContext dcrMessageContext = new DCRMessageContext(param);
    RegistrationHandler registrationHandler1 = new RegistrationHandler();
    RegistrationHandler registrationHandler2 = new RegistrationHandler();
    List<RegistrationHandler> registrationHandlers1 = new ArrayList<>();
    registrationHandlers1.add(registrationHandler1);
    registrationHandlers1.add(registrationHandler2);
    List<RegistrationHandler> registrationHandlers2 = new ArrayList<>();
    registrationHandlers2.add(registrationHandler1);
    List<RegistrationHandler> registrationHandlers3 = new ArrayList<>();
    return new Object[][] { { dcrMessageContext, null }, { dcrMessageContext, registrationHandlers1 }, { dcrMessageContext, registrationHandlers2 }, { dcrMessageContext, registrationHandlers3 } };
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) RegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.RegistrationHandler) UnRegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.UnRegistrationHandler) DCRMessageContext(org.wso2.carbon.identity.oauth.dcr.context.DCRMessageContext) DataProvider(org.testng.annotations.DataProvider)

Example 5 with DCRMessageContext

use of org.wso2.carbon.identity.oauth.dcr.context.DCRMessageContext in project identity-inbound-auth-oauth by wso2-extensions.

the class DCRProcessor method process.

@Override
public IdentityResponse.IdentityResponseBuilder process(IdentityRequest identityRequest) throws DCRException {
    if (log.isDebugEnabled()) {
        log.debug("Request processing started by DCRProcessor.");
    }
    DCRMessageContext dcrMessageContext = new DCRMessageContext(identityRequest);
    IdentityResponse.IdentityResponseBuilder identityResponseBuilder = null;
    if (identityRequest instanceof RegistrationRequest) {
        identityResponseBuilder = registerOAuthApplication(dcrMessageContext);
    } else if (identityRequest instanceof UnregistrationRequest) {
        identityResponseBuilder = unRegisterOAuthApplication(dcrMessageContext);
    }
    return identityResponseBuilder;
}
Also used : UnregistrationRequest(org.wso2.carbon.identity.oauth.dcr.model.UnregistrationRequest) IdentityResponse(org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityResponse) DCRMessageContext(org.wso2.carbon.identity.oauth.dcr.context.DCRMessageContext) RegistrationRequest(org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequest)

Aggregations

UnRegistrationHandler (org.wso2.carbon.identity.oauth.dcr.handler.UnRegistrationHandler)6 DCRMessageContext (org.wso2.carbon.identity.oauth.dcr.context.DCRMessageContext)5 IdentityResponse (org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityResponse)4 DCRException (org.wso2.carbon.identity.oauth.dcr.DCRException)4 RegistrationHandler (org.wso2.carbon.identity.oauth.dcr.handler.RegistrationHandler)4 RegistrationRequest (org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequest)4 UnregistrationRequest (org.wso2.carbon.identity.oauth.dcr.model.UnregistrationRequest)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 DataProvider (org.testng.annotations.DataProvider)2 Test (org.testng.annotations.Test)2 UnRegistrationException (org.wso2.carbon.identity.oauth.dcr.exception.UnRegistrationException)2 RegistrationRequestProfile (org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequestProfile)2 RegistrationResponse (org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponse)2 RegistrationResponseProfile (org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile)2 HandlerManager (org.wso2.carbon.identity.oauth.dcr.util.HandlerManager)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 IdentityException (org.wso2.carbon.identity.base.IdentityException)1 RegistrationException (org.wso2.carbon.identity.oauth.dcr.exception.RegistrationException)1