Search in sources :

Example 1 with RegistrationHandler

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

the class DCRServiceComponent method activate.

@SuppressWarnings("unused")
protected void activate(ComponentContext componentContext) {
    try {
        componentContext.getBundleContext().registerService(IdentityProcessor.class.getName(), new DCRProcessor(), null);
        componentContext.getBundleContext().registerService(HttpIdentityRequestFactory.class.getName(), new RegistrationRequestFactory(), null);
        componentContext.getBundleContext().registerService(HttpIdentityResponseFactory.class.getName(), new HttpRegistrationResponseFactory(), null);
        componentContext.getBundleContext().registerService(HttpIdentityRequestFactory.class.getName(), new UnregistrationRequestFactory(), null);
        componentContext.getBundleContext().registerService(HttpIdentityResponseFactory.class.getName(), new HttpUnregistrationResponseFactory(), null);
        componentContext.getBundleContext().registerService(RegistrationHandler.class.getName(), new RegistrationHandler(), null);
        componentContext.getBundleContext().registerService(UnRegistrationHandler.class.getName(), new UnRegistrationHandler(), null);
        componentContext.getBundleContext().registerService(DCRMService.class.getName(), new DCRMService(), null);
    } catch (Throwable e) {
        log.error("Error occurred while activating DCRServiceComponent", e);
    }
}
Also used : DCRMService(org.wso2.carbon.identity.oauth.dcr.service.DCRMService) HttpUnregistrationResponseFactory(org.wso2.carbon.identity.oauth.dcr.factory.HttpUnregistrationResponseFactory) UnRegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.UnRegistrationHandler) UnregistrationRequestFactory(org.wso2.carbon.identity.oauth.dcr.factory.UnregistrationRequestFactory) RegistrationRequestFactory(org.wso2.carbon.identity.oauth.dcr.factory.RegistrationRequestFactory) HttpRegistrationResponseFactory(org.wso2.carbon.identity.oauth.dcr.factory.HttpRegistrationResponseFactory) IdentityProcessor(org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityProcessor) RegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.RegistrationHandler) UnRegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.UnRegistrationHandler) DCRProcessor(org.wso2.carbon.identity.oauth.dcr.processor.DCRProcessor) HttpIdentityResponseFactory(org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponseFactory) HttpIdentityRequestFactory(org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityRequestFactory)

Example 2 with RegistrationHandler

use of org.wso2.carbon.identity.oauth.dcr.handler.RegistrationHandler 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 RegistrationHandler

use of org.wso2.carbon.identity.oauth.dcr.handler.RegistrationHandler 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 4 with RegistrationHandler

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

the class DCRProcessorTest method testProcess.

@Test(dataProvider = "instanceTypeprovider")
public void testProcess(String request, Object identityRequest) 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);
        when(registrationHandler.handle(dcrMessageContext)).thenReturn(new IdentityResponse.IdentityResponseBuilder());
        assertNotNull(dcrProcessor.process((RegistrationRequest) identityRequest));
    } else if (request.equals("UnregistrationRequest")) {
        UnRegistrationHandler unRegistrationHandler = mock(UnRegistrationHandler.class);
        when(mockHandlerManager.getUnRegistrationHandler(dcrMessageContext)).thenReturn(unRegistrationHandler);
        when(unRegistrationHandler.handle(dcrMessageContext)).thenReturn(new IdentityResponse.IdentityResponseBuilder());
        assertNotNull(dcrProcessor.process((UnregistrationRequest) identityRequest));
    }
}
Also used : UnRegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.UnRegistrationHandler) HandlerManager(org.wso2.carbon.identity.oauth.dcr.util.HandlerManager) IdentityResponse(org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityResponse) 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) RegistrationRequest(org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequest) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with RegistrationHandler

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

the class DCRProcessor method registerOAuthApplication.

protected IdentityResponse.IdentityResponseBuilder registerOAuthApplication(DCRMessageContext dcrMessageContext) throws RegistrationException {
    IdentityResponse.IdentityResponseBuilder identityResponseBuilder = null;
    try {
        RegistrationHandler registrationHandler = HandlerManager.getInstance().getRegistrationHandler(dcrMessageContext);
        identityResponseBuilder = registrationHandler.handle(dcrMessageContext);
    } catch (DCRException e) {
        if (StringUtils.isBlank(e.getErrorCode())) {
            throw IdentityException.error(RegistrationException.class, ErrorCodes.BAD_REQUEST.toString(), e.getMessage(), e);
        } else {
            throw IdentityException.error(RegistrationException.class, e.getErrorCode(), e.getMessage(), e);
        }
    }
    return identityResponseBuilder;
}
Also used : RegistrationException(org.wso2.carbon.identity.oauth.dcr.exception.RegistrationException) UnRegistrationException(org.wso2.carbon.identity.oauth.dcr.exception.UnRegistrationException) IdentityResponse(org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityResponse) RegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.RegistrationHandler) UnRegistrationHandler(org.wso2.carbon.identity.oauth.dcr.handler.UnRegistrationHandler) DCRException(org.wso2.carbon.identity.oauth.dcr.DCRException)

Aggregations

RegistrationHandler (org.wso2.carbon.identity.oauth.dcr.handler.RegistrationHandler)5 UnRegistrationHandler (org.wso2.carbon.identity.oauth.dcr.handler.UnRegistrationHandler)5 DCRMessageContext (org.wso2.carbon.identity.oauth.dcr.context.DCRMessageContext)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Test (org.testng.annotations.Test)2 IdentityResponse (org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityResponse)2 DCRException (org.wso2.carbon.identity.oauth.dcr.DCRException)2 HandlerManager (org.wso2.carbon.identity.oauth.dcr.util.HandlerManager)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 DataProvider (org.testng.annotations.DataProvider)1 HttpIdentityRequestFactory (org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityRequestFactory)1 HttpIdentityResponseFactory (org.wso2.carbon.identity.application.authentication.framework.inbound.HttpIdentityResponseFactory)1 IdentityProcessor (org.wso2.carbon.identity.application.authentication.framework.inbound.IdentityProcessor)1 IdentityException (org.wso2.carbon.identity.base.IdentityException)1 RegistrationException (org.wso2.carbon.identity.oauth.dcr.exception.RegistrationException)1 UnRegistrationException (org.wso2.carbon.identity.oauth.dcr.exception.UnRegistrationException)1 HttpRegistrationResponseFactory (org.wso2.carbon.identity.oauth.dcr.factory.HttpRegistrationResponseFactory)1 HttpUnregistrationResponseFactory (org.wso2.carbon.identity.oauth.dcr.factory.HttpUnregistrationResponseFactory)1 RegistrationRequestFactory (org.wso2.carbon.identity.oauth.dcr.factory.RegistrationRequestFactory)1