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);
}
}
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);
}
}
}
}
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 } };
}
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));
}
}
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;
}
Aggregations