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