use of org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile 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;
}
use of org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile in project identity-inbound-auth-oauth by wso2-extensions.
the class HttpRegistrationResponseFactoryTest method testGenerateSuccessfulResponse.
@Test
public void testGenerateSuccessfulResponse() throws Exception {
grantType.add("dummyGrantType");
redirectUrl.add("dummyRedirectUrl");
RegistrationResponseProfile registrationRequestProfile = mock(RegistrationResponseProfile.class);
when(mockRegistrationResponse.getRegistrationResponseProfile()).thenReturn(registrationRequestProfile);
String dummyClientId = "dummyClientId";
when(registrationRequestProfile.getClientId()).thenReturn(dummyClientId);
String dummyClientName = "dummyClientName";
when(registrationRequestProfile.getClientName()).thenReturn(dummyClientName);
when(registrationRequestProfile.getGrantTypes()).thenReturn(grantType);
when(registrationRequestProfile.getRedirectUrls()).thenReturn(redirectUrl);
String dummySecret = "dummySecret";
when(registrationRequestProfile.getClientSecret()).thenReturn(dummySecret);
String dummyTime = "dummyTime";
when(registrationRequestProfile.getClientSecretExpiresAt()).thenReturn(dummyTime);
JSONObject jsonObject = httpRegistrationResponseFactory.generateSuccessfulResponse(mockRegistrationResponse);
assertEquals(jsonObject.get(RegistrationResponse.DCRegisterResponseConstants.CLIENT_ID), dummyClientId);
assertEquals(jsonObject.get(RegistrationResponse.DCRegisterResponseConstants.CLIENT_NAME), dummyClientName);
assertEquals(jsonObject.get(RegistrationResponse.DCRegisterResponseConstants.CLIENT_SECRET_EXPIRES_AT), dummyTime);
assertEquals(jsonObject.get(RegistrationResponse.DCRegisterResponseConstants.CLIENT_SECRET), dummySecret);
assertEquals(jsonObject.get(RegistrationResponse.DCRegisterResponseConstants.GRANT_TYPES), grantType);
assertEquals(jsonObject.get(RegistrationResponse.DCRegisterResponseConstants.REDIRECT_URIS), redirectUrl);
}
use of org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile in project identity-inbound-auth-oauth by wso2-extensions.
the class HttpRegistrationResponseFactoryTest method testCreate.
@Test(dataProvider = "instanceDataProvider")
public void testCreate(Object builder) throws Exception {
if (builder == null) {
mockHttpIdentityResponseBuilder = mock(HttpIdentityResponse.HttpIdentityResponseBuilder.class);
} else {
mockHttpIdentityResponseBuilder = (HttpIdentityResponse.HttpIdentityResponseBuilder) builder;
}
RegistrationResponseProfile registrationRequestProfile = mock(RegistrationResponseProfile.class);
whenNew(HttpIdentityResponse.HttpIdentityResponseBuilder.class).withNoArguments().thenReturn(mockHttpIdentityResponseBuilder);
when((mockRegistrationResponse).getRegistrationResponseProfile()).thenReturn(registrationRequestProfile);
final Integer[] statusCode = new Integer[1];
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
statusCode[0] = (Integer) invocation.getArguments()[0];
return null;
}
}).when(mockHttpIdentityResponseBuilder).setStatusCode(anyInt());
final String[] header = new String[1];
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
header[0] = (String) invocation.getArguments()[1];
return null;
}
}).when(mockHttpIdentityResponseBuilder).addHeader(anyString(), anyString());
if (builder == null) {
httpRegistrationResponseFactory.create(mockRegistrationResponse);
} else {
httpRegistrationResponseFactory.create((HttpIdentityResponse.HttpIdentityResponseBuilder) builder, (mockRegistrationResponse));
}
assertEquals((int) statusCode[0], HttpServletResponse.SC_CREATED);
assertEquals(header[0], MediaType.APPLICATION_JSON);
}
use of org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile in project identity-inbound-auth-oauth by wso2-extensions.
the class HttpOIDCRegistrationResponseFactoryTest method testCreate.
@Test
public void testCreate() throws Exception {
OIDCRegistrationResponseProfile registrationResponseProfile = new OIDCRegistrationResponseProfile();
registrationResponseProfile.setClientId("client_id");
registrationResponseProfile.setClientName("client_name");
registrationResponseProfile.setRedirectUrls(Arrays.asList("http://example.com", "http://foo.com"));
registrationResponseProfile.setGrantTypes(Arrays.asList("code", "implicit"));
registrationResponseProfile.setClientSecret("cl1ent_s3cr3t");
registrationResponseProfile.setClientSecretExpiresAt("dummyExpiry");
RegistrationResponse mockResponse = new RegistrationResponse.DCRRegisterResponseBuilder().setRegistrationResponseProfile(registrationResponseProfile).build();
HttpIdentityResponse identityResponse = testedResponseFactory.create(mockResponse).build();
assertEquals(identityResponse.getStatusCode(), HttpServletResponse.SC_CREATED, "Invalid status code.");
assertEquals(identityResponse.getHeaders().get(OAuthConstants.HTTP_RESP_HEADER_CACHE_CONTROL), OAuthConstants.HTTP_RESP_HEADER_VAL_CACHE_CONTROL_NO_STORE, "Invalid cache control header.");
assertEquals(identityResponse.getHeaders().get(OAuthConstants.HTTP_RESP_HEADER_PRAGMA), OAuthConstants.HTTP_RESP_HEADER_VAL_PRAGMA_NO_CACHE, "Invalid pragma header.");
assertEquals(identityResponse.getHeaders().get(HttpHeaders.CONTENT_TYPE), MediaType.APPLICATION_JSON, "Invalid content type header.");
}
use of org.wso2.carbon.identity.oauth.dcr.model.RegistrationResponseProfile in project identity-inbound-auth-oauth by wso2-extensions.
the class OIDCRegistrationHandler method handle.
@Override
@SuppressFBWarnings("BC_UNCONFIRMED_CAST_OF_RETURN_VALUE")
public IdentityResponse.IdentityResponseBuilder handle(DCRMessageContext dcrMessageContext) throws DCRException {
if (log.isDebugEnabled()) {
log.debug("Request processing started by RegistrationRequestProcessor.");
}
RegistrationResponse.DCRRegisterResponseBuilder dcrRegisterResponseBuilder;
RegistrationRequest registerRequest;
if (dcrMessageContext.getIdentityRequest() instanceof RegistrationRequest) {
registerRequest = (RegistrationRequest) dcrMessageContext.getIdentityRequest();
} else {
throw new DCRException("Error while retrieving the registration request.");
}
RegistrationRequestProfile registrationRequestProfile = registerRequest.getRegistrationRequestProfile();
registrationRequestProfile.setTenantDomain(registerRequest.getTenantDomain());
RegistrationResponseProfile registrationResponseProfile = DCRManagementService.getInstance().registerOAuthApplication(registrationRequestProfile);
dcrRegisterResponseBuilder = new RegistrationResponse.DCRRegisterResponseBuilder();
dcrRegisterResponseBuilder.setRegistrationResponseProfile(registrationResponseProfile);
return dcrRegisterResponseBuilder;
}
Aggregations