use of org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequestProfile in project identity-inbound-auth-oauth by wso2-extensions.
the class RegistrationRequestFactoryTest method getTestCreateData.
private JSONObject getTestCreateData() throws Exception {
String grantType = "implicit";
JSONArray redirectUrls = new JSONArray();
redirectUrls.add("redirectUrl");
JSONObject jsonObject = new JSONObject();
jsonObject.put(RegistrationRequest.RegisterRequestConstant.GRANT_TYPES, grantType);
jsonObject.put(RegistrationRequest.RegisterRequestConstant.REDIRECT_URIS, redirectUrls);
RegistrationRequestProfile registrationRequestProfile = new RegistrationRequestProfile();
whenNew(RegistrationRequestProfile.class).withNoArguments().thenReturn(registrationRequestProfile);
suppress(methodsDeclaredIn(HttpIdentityRequestFactory.class));
return jsonObject;
}
use of org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequestProfile in project identity-inbound-auth-oauth by wso2-extensions.
the class RegistrationHandlerTest method testHandle.
@Test
public void testHandle() throws Exception {
RegistrationRequestProfile mockRegistrationRequestProfile = new RegistrationRequestProfile();
when(mockDcrMessageContext.getIdentityRequest()).thenReturn(mockRegisterRequest);
when(mockRegisterRequest.getRegistrationRequestProfile()).thenReturn(mockRegistrationRequestProfile);
String testTenantDomain = "testTenantDomain";
when(mockRegisterRequest.getTenantDomain()).thenReturn(testTenantDomain);
mockStatic(DCRManagementService.class);
when(DCRManagementService.getInstance()).thenReturn(mockDCRManagementService);
when(mockDCRManagementService.registerOAuthApplication(mockRegistrationRequestProfile)).thenReturn(mockRegistrationResponseProfile);
RegistrationResponse.DCRRegisterResponseBuilder registerResponseBuilder = new RegistrationResponse.DCRRegisterResponseBuilder();
whenNew(RegistrationResponse.DCRRegisterResponseBuilder.class).withNoArguments().thenReturn(registerResponseBuilder);
assertEquals(registrationHandler.handle(mockDcrMessageContext), registerResponseBuilder, "Expected response builder is different from the actual");
assertEquals(mockRegistrationRequestProfile.getTenantDomain(), testTenantDomain, "Expected tenant domain is not equal to the actual tenant domain");
}
use of org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequestProfile in project identity-inbound-auth-oauth by wso2-extensions.
the class RegistrationRequestFactory method parseJson.
protected void parseJson(JSONObject jsonData, RegistrationRequest.RegistrationRequestBuilder registerRequestBuilder) throws FrameworkClientException {
RegistrationRequestProfile registrationRequestProfile = registerRequestBuilder.getRegistrationRequestProfile();
if (registrationRequestProfile == null) {
registrationRequestProfile = new RegistrationRequestProfile();
}
Object obj = jsonData.get(RegistrationRequest.RegisterRequestConstant.GRANT_TYPES);
if (obj instanceof JSONArray) {
JSONArray grantTypes = (JSONArray) obj;
for (Object grantType : grantTypes) {
if (grantType instanceof String && IdentityUtil.isNotBlank((String) grantType)) {
registrationRequestProfile.getGrantTypes().add((String) grantType);
}
}
} else if (obj instanceof String) {
String grantType = (String) obj;
if (IdentityUtil.isNotBlank(grantType)) {
registrationRequestProfile.getGrantTypes().add(grantType);
}
}
obj = jsonData.get(RegistrationRequest.RegisterRequestConstant.REDIRECT_URIS);
if (obj instanceof JSONArray) {
JSONArray redirectUris = (JSONArray) obj;
for (Object redirectUri : redirectUris) {
if (redirectUri instanceof String) {
registrationRequestProfile.getRedirectUris().add((String) redirectUri);
}
}
} else if (obj instanceof String) {
registrationRequestProfile.getRedirectUris().add((String) obj);
} else if (registrationRequestProfile.getGrantTypes().contains(DCRConstants.GrantTypes.AUTHORIZATION_CODE) || registrationRequestProfile.getGrantTypes().contains(DCRConstants.GrantTypes.IMPLICIT)) {
throw IdentityException.error(FrameworkClientException.class, "RedirectUris property must have at least one URI value.");
}
registrationRequestProfile.setTokenEndpointAuthMethod((String) jsonData.get(RegistrationRequest.RegisterRequestConstant.TOKEN_ENDPOINT_AUTH_METHOD));
obj = jsonData.get(RegistrationRequest.RegisterRequestConstant.RESPONSE_TYPES);
if (obj instanceof JSONArray) {
JSONArray responseTypes = (JSONArray) obj;
for (int i = 0; i < responseTypes.size(); i++) {
registrationRequestProfile.getResponseTypes().add(responseTypes.get(i).toString());
}
} else if (obj instanceof String) {
registrationRequestProfile.getResponseTypes().add((String) obj);
}
// Get client Name if not available generate a uuid
Object objClient = jsonData.get(RegistrationRequest.RegisterRequestConstant.CLIENT_NAME);
if (objClient != null) {
registrationRequestProfile.setClientName((String) objClient);
} else {
registrationRequestProfile.setClientName(UUIDGenerator.generateUUID());
}
registrationRequestProfile.setClientUri((String) jsonData.get(RegistrationRequest.RegisterRequestConstant.CLIENT_URI));
registrationRequestProfile.setLogoUri((String) jsonData.get(RegistrationRequest.RegisterRequestConstant.LOGO_URI));
obj = jsonData.get(RegistrationRequest.RegisterRequestConstant.SCOPE);
if (obj instanceof JSONArray) {
JSONArray scopes = (JSONArray) obj;
for (int i = 0; i < scopes.size(); i++) {
registrationRequestProfile.getScopes().add(scopes.get(i).toString());
}
} else if (obj instanceof String) {
registrationRequestProfile.getScopes().add((String) obj);
}
obj = jsonData.get(RegistrationRequest.RegisterRequestConstant.CONTACTS);
if (obj instanceof JSONArray) {
JSONArray redirectUris = (JSONArray) obj;
for (int i = 0; i < redirectUris.size(); i++) {
registrationRequestProfile.getContacts().add(redirectUris.get(i).toString());
}
} else if (obj instanceof String) {
registrationRequestProfile.getContacts().add((String) obj);
}
registrationRequestProfile.setTosUri((String) jsonData.get(RegistrationRequest.RegisterRequestConstant.TOS_URI));
registrationRequestProfile.setPolicyUri((String) jsonData.get(RegistrationRequest.RegisterRequestConstant.POLICY_URI));
registrationRequestProfile.setJwksUri((String) jsonData.get(RegistrationRequest.RegisterRequestConstant.JWKS_URI));
registrationRequestProfile.setJkws((String) jsonData.get(RegistrationRequest.RegisterRequestConstant.JWKS));
registrationRequestProfile.setSoftwareId((String) jsonData.get(RegistrationRequest.RegisterRequestConstant.SOFTWARE_ID));
registrationRequestProfile.setSoftwareVersion((String) jsonData.get(RegistrationRequest.RegisterRequestConstant.SOFTWARE_VERSION));
// TODO:This parameter is a custom one and we have to remove if we can collect the user name by having
// some authentication mechanism.
String username = CarbonContext.getThreadLocalCarbonContext().getUsername();
if (StringUtils.isBlank(username)) {
Object objOwner = jsonData.get(RegistrationRequest.RegisterRequestConstant.EXT_PARAM_OWNER);
if (objOwner != null) {
username = (String) objOwner;
try {
UserRealm userRealm = CarbonContext.getThreadLocalCarbonContext().getUserRealm();
if (!userRealm.getUserStoreManager().isExistingUser(username)) {
throw IdentityException.error(FrameworkClientException.class, "Invalid application " + "owner.");
}
} catch (UserStoreException e) {
String errorMessage = "Invalid application owner, " + e.getMessage();
throw IdentityException.error(FrameworkClientException.class, errorMessage, e);
}
} else {
throw IdentityException.error(FrameworkClientException.class, "Invalid application owner.");
}
}
registrationRequestProfile.setOwner(username);
registerRequestBuilder.setRegistrationRequestProfile(registrationRequestProfile);
}
use of org.wso2.carbon.identity.oauth.dcr.model.RegistrationRequestProfile 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.RegistrationRequestProfile in project identity-inbound-auth-oauth by wso2-extensions.
the class DCRManagementServiceTest method registerOAuthApplicationWithNewSPNoRedirectUri.
@Test
public void registerOAuthApplicationWithNewSPNoRedirectUri() throws Exception {
registerOAuthApplication();
registrationRequestProfile.setRedirectUris(new ArrayList<>());
mockApplicationManagementService = mock(ApplicationManagementService.class);
DCRDataHolder dcrDataHolder = DCRDataHolder.getInstance();
dcrDataHolder.setApplicationManagementService(mockApplicationManagementService);
when(mockApplicationManagementService.getServiceProvider(applicationName, tenantDomain)).thenReturn(null, new ServiceProvider());
try {
dcrManagementService.registerOAuthApplication(registrationRequestProfile);
} catch (IdentityException ex) {
assertEquals(ex.getMessage(), "RedirectUris property must have at least one URI value.");
return;
}
fail("Expected IdentityException was not thrown by registerOAuthApplication method");
}
Aggregations