Search in sources :

Example 1 with UnRegistrationHandler

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

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

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

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

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

the class DCRProcessor method unRegisterOAuthApplication.

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

Aggregations

UnRegistrationHandler (org.wso2.carbon.identity.oauth.dcr.handler.UnRegistrationHandler)5 DCRMessageContext (org.wso2.carbon.identity.oauth.dcr.context.DCRMessageContext)3 RegistrationHandler (org.wso2.carbon.identity.oauth.dcr.handler.RegistrationHandler)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 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 UnregistrationRequestFactory (org.wso2.carbon.identity.oauth.dcr.factory.UnregistrationRequestFactory)1