Search in sources :

Example 36 with RoleMapping

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;
}
Also used : PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) ArrayList(java.util.ArrayList) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping)

Example 37 with RoleMapping

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);
    }
}
Also used : PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.xsd.PermissionsAndRoleConfig) ServiceProvider(org.wso2.carbon.identity.application.common.model.xsd.ServiceProvider) ArrayList(java.util.ArrayList) LocalRole(org.wso2.carbon.identity.application.common.model.xsd.LocalRole) RoleMapping(org.wso2.carbon.identity.application.common.model.xsd.RoleMapping) Test(org.testng.annotations.Test)

Example 38 with RoleMapping

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;
}
Also used : RoleConfig(org.wso2.carbon.identity.api.server.application.management.v1.RoleConfig) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping)

Example 39 with RoleMapping

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(), ","));
    }
}
Also used : ArrayList(java.util.ArrayList) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping) PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) LocalRole(org.wso2.carbon.identity.application.common.model.LocalRole)

Aggregations

RoleMapping (org.wso2.carbon.identity.application.common.model.RoleMapping)29 ArrayList (java.util.ArrayList)15 LocalRole (org.wso2.carbon.identity.application.common.model.LocalRole)15 PermissionsAndRoleConfig (org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig)14 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)12 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)9 Claim (org.wso2.carbon.identity.application.common.model.Claim)8 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)8 Property (org.wso2.carbon.identity.application.common.model.Property)7 HashMap (java.util.HashMap)6 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)6 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)6 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)5 PreparedStatement (java.sql.PreparedStatement)4 RoleAliasListDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.RoleAliasListDTO)4 ResultSet (java.sql.ResultSet)3 HashSet (java.util.HashSet)3 JSONObject (org.json.simple.JSONObject)3 DataProvider (org.testng.annotations.DataProvider)3 Test (org.testng.annotations.Test)3