use of org.wso2.carbon.identity.application.common.model.xsd.RoleMapping in project identity-inbound-auth-oauth by wso2-extensions.
the class SAML2BearerGrantHandler method getUpdatedRoleClaimValue.
/**
* This method will update the role claim value received from the IdP using the defined role claim configuration
* for the IdP.
* Also, if "ReturnOnlyMappedLocalRoles" configuration is enabled, then server will only return the mapped role
* values.
*
* @param identityProvider identity provider
* @param currentRoleClaimValue current role claim value.
* @return updated role claim string
*/
private String getUpdatedRoleClaimValue(IdentityProvider identityProvider, String currentRoleClaimValue) {
if (StringUtils.equalsIgnoreCase(IdentityApplicationConstants.RESIDENT_IDP_RESERVED_NAME, identityProvider.getIdentityProviderName())) {
return currentRoleClaimValue;
}
PermissionsAndRoleConfig permissionAndRoleConfig = identityProvider.getPermissionAndRoleConfig();
if (permissionAndRoleConfig != null && ArrayUtils.isNotEmpty(permissionAndRoleConfig.getRoleMappings())) {
String[] receivedRoles = currentRoleClaimValue.split(FrameworkUtils.getMultiAttributeSeparator());
List<String> updatedRoleClaimValues = new ArrayList<>();
loop: for (String receivedRole : receivedRoles) {
for (RoleMapping roleMapping : permissionAndRoleConfig.getRoleMappings()) {
if (roleMapping.getRemoteRole().equals(receivedRole)) {
updatedRoleClaimValues.add(roleMapping.getLocalRole().getLocalRoleName());
continue loop;
}
}
if (!OAuthServerConfiguration.getInstance().isReturnOnlyMappedLocalRoles()) {
updatedRoleClaimValues.add(receivedRole);
}
}
if (!updatedRoleClaimValues.isEmpty()) {
return StringUtils.join(updatedRoleClaimValues, FrameworkUtils.getMultiAttributeSeparator());
}
return null;
}
if (!OAuthServerConfiguration.getInstance().isReturnOnlyMappedLocalRoles()) {
return currentRoleClaimValue;
}
return null;
}
use of org.wso2.carbon.identity.application.common.model.xsd.RoleMapping in project product-is by wso2.
the class ApplicationManagementTestCase method testUpdateRoles.
@Test(alwaysRun = true, description = "2.1.2.10")
public void testUpdateRoles() {
String applicationName = "TestServiceProvider";
try {
ServiceProvider serviceProvider = applicationManagementServiceClient.getApplication(applicationName);
PermissionsAndRoleConfig permAndRoleConfig = new PermissionsAndRoleConfig();
List<RoleMapping> roleMappingList = new ArrayList<RoleMapping>();
RoleMapping mapping = new RoleMapping();
LocalRole localRole = new LocalRole();
localRole.setLocalRoleName(IDP_ROLE_1);
mapping.setLocalRole(localRole);
mapping.setRemoteRole("spRole_1");
roleMappingList.add(mapping);
permAndRoleConfig.setRoleMappings(roleMappingList.toArray(new RoleMapping[roleMappingList.size()]));
serviceProvider.setPermissionAndRoleConfig(permAndRoleConfig);
applicationManagementServiceClient.updateApplicationData(serviceProvider);
ServiceProvider updatedServiceProvider = applicationManagementServiceClient.getApplication(applicationName);
PermissionsAndRoleConfig updatedPermissionsAndRoleConfig = updatedServiceProvider.getPermissionAndRoleConfig();
Assert.assertEquals(updatedPermissionsAndRoleConfig.getRoleMappings()[0].getLocalRole().getLocalRoleName(), IDP_ROLE_1, "Failed update local role");
Assert.assertEquals(updatedPermissionsAndRoleConfig.getRoleMappings()[0].getRemoteRole(), "spRole_1", "Failed update remote role");
} catch (Exception e) {
Assert.fail("Error while trying to update Roles", e);
}
}
use of org.wso2.carbon.identity.application.common.model.xsd.RoleMapping in project identity-api-server by wso2.
the class ServiceProviderToApiModel method buildRoleConfig.
private RoleConfig buildRoleConfig(ServiceProvider application) {
RoleConfig roleConfig = new RoleConfig();
if (application.getClaimConfig() != null) {
String roleClaimId = application.getClaimConfig().getRoleClaimURI();
if (StringUtils.isBlank(roleClaimId)) {
if (application.getClaimConfig().isLocalClaimDialect()) {
roleConfig.claim(buildClaimModel(FrameworkConstants.LOCAL_ROLE_CLAIM_URI));
}
} else {
roleConfig.claim(buildClaimModel(roleClaimId));
}
}
if (application.getLocalAndOutBoundAuthenticationConfig() != null) {
roleConfig.includeUserDomain(application.getLocalAndOutBoundAuthenticationConfig().isUseUserstoreDomainInRoles());
}
if (application.getPermissionAndRoleConfig() != null) {
RoleMapping[] roleMappings = application.getPermissionAndRoleConfig().getRoleMappings();
arrayToStream(roleMappings).forEach(roleMapping -> roleConfig.addMappingsItem(new org.wso2.carbon.identity.api.server.application.management.v1.RoleMapping().applicationRole(roleMapping.getRemoteRole()).localRole(roleMapping.getLocalRole().getLocalRoleName())));
}
return roleConfig;
}
use of org.wso2.carbon.identity.application.common.model.xsd.RoleMapping in project identity-api-server by wso2.
the class ServerIdpManagementService method updateRoles.
private void updateRoles(IdentityProvider idp, Roles roles) {
if (roles != null) {
PermissionsAndRoleConfig permissionsAndRoleConfig = new PermissionsAndRoleConfig();
List<org.wso2.carbon.identity.api.server.idp.v1.model.RoleMapping> mappings = roles.getMappings();
List<RoleMapping> internalMappings = new ArrayList<>();
List<String> idpRoles = new ArrayList<>();
if (mappings != null) {
for (org.wso2.carbon.identity.api.server.idp.v1.model.RoleMapping mapping : mappings) {
RoleMapping internalMapping = new RoleMapping();
internalMapping.setLocalRole(new LocalRole(mapping.getLocalRole()));
internalMapping.setRemoteRole(mapping.getIdpRole());
idpRoles.add(mapping.getIdpRole());
internalMappings.add(internalMapping);
}
}
permissionsAndRoleConfig.setIdpRoles(idpRoles.toArray(new String[0]));
permissionsAndRoleConfig.setRoleMappings(internalMappings.toArray(new RoleMapping[0]));
idp.setPermissionAndRoleConfig(permissionsAndRoleConfig);
idp.setProvisioningRole(StringUtils.join(roles.getOutboundProvisioningRoles(), ","));
}
}
Aggregations