Search in sources :

Example 1 with RoleMapping

use of org.wso2.carbon.identity.application.common.model.xsd.RoleMapping in project carbon-apimgt by wso2.

the class SystemScopesApiServiceImpl method systemScopesRoleAliasesPut.

@Override
public Response systemScopesRoleAliasesPut(RoleAliasListDTO body, MessageContext messageContext) throws APIManagementException {
    RoleAliasListDTO roleAliasListDTO = new RoleAliasListDTO();
    JSONObject newRoleMappingJson = SystemScopesMappingUtil.createJsonObjectOfRoleMapping(body);
    String username = RestApiCommonUtil.getLoggedInUsername();
    String tenantDomain = MultitenantUtils.getTenantDomain(username);
    APIUtil.updateTenantConfRoleAliasMapping(newRoleMappingJson, username);
    JSONObject tenantConfig = APIUtil.getTenantConfig(tenantDomain);
    JSONObject roleMapping = (JSONObject) tenantConfig.get(APIConstants.REST_API_ROLE_MAPPINGS_CONFIG);
    if (roleMapping != null) {
        roleAliasListDTO = SystemScopesMappingUtil.fromRoleAliasListToRoleAliasListDTO(SystemScopesMappingUtil.createMapOfRoleMapping((roleMapping)));
    }
    return Response.ok().entity(roleAliasListDTO).build();
}
Also used : JSONObject(org.json.simple.JSONObject) RoleAliasListDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.RoleAliasListDTO)

Example 2 with RoleMapping

use of org.wso2.carbon.identity.application.common.model.xsd.RoleMapping in project carbon-apimgt by wso2.

the class SystemScopesMappingUtil method fromRoleAliasObjectToRoleAliasDTOList.

/**
 * Converts api scope-role mapping to RoleScopeDTO List.
 *
 * @param roleMapping Map of a Role Scope  Mapping
 * @return RoleScopeDTO list
 */
private static List<RoleAliasDTO> fromRoleAliasObjectToRoleAliasDTOList(Map<String, List<String>> roleMapping) {
    List<RoleAliasDTO> roleAliasDTOS = new ArrayList<>(roleMapping.size());
    for (Map.Entry<String, List<String>> mapping : roleMapping.entrySet()) {
        RoleAliasDTO roleAliasDTO = new RoleAliasDTO();
        roleAliasDTO.setRole(mapping.getKey());
        roleAliasDTO.setAliases(mapping.getValue());
        roleAliasDTOS.add(roleAliasDTO);
    }
    return roleAliasDTOS;
}
Also used : RoleAliasDTO(org.wso2.carbon.apimgt.rest.api.admin.v1.dto.RoleAliasDTO) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with RoleMapping

use of org.wso2.carbon.identity.application.common.model.xsd.RoleMapping in project carbon-identity-framework by wso2.

the class IdentityProviderManager method getMappedLocalRoles.

/**
 * Retrieves Identity provider information about a given tenant
 *
 * @param idPName      Unique name of the IdP to which the given IdP roles need to be mapped
 * @param tenantDomain The tenant domain of whose local roles to be mapped
 * @param idPRoles     IdP roles which need to be mapped to local roles
 * @throws IdentityProviderManagementException Error when getting role mappings
 */
@Override
public Set<RoleMapping> getMappedLocalRoles(String idPName, String tenantDomain, String[] idPRoles) throws IdentityProviderManagementException {
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    if (StringUtils.isEmpty(idPName)) {
        String msg = "Invalid argument: Identity Provider Name value is empty";
        throw new IdentityProviderManagementException(msg);
    }
    IdentityProvider identityProvider = dao.getIdPByName(null, idPName, tenantId, tenantDomain);
    if (identityProvider == null) {
        identityProvider = new FileBasedIdPMgtDAO().getIdPByName(idPName, tenantDomain);
    }
    if (identityProvider == null) {
        identityProvider = IdPManagementServiceComponent.getFileBasedIdPs().get(IdentityApplicationConstants.DEFAULT_IDP_CONFIG);
    }
    PermissionsAndRoleConfig roleConfiguration = identityProvider.getPermissionAndRoleConfig();
    if (roleConfiguration != null) {
        RoleMapping[] roleMappings = roleConfiguration.getRoleMappings();
        if (roleMappings != null && roleMappings.length > 0 && idPRoles != null) {
            Set<RoleMapping> returnSet = new HashSet<RoleMapping>();
            for (String idPRole : idPRoles) {
                for (RoleMapping roleMapping : roleMappings) {
                    if (roleMapping.getRemoteRole().equals(idPRole)) {
                        returnSet.add(roleMapping);
                        break;
                    }
                }
            }
            return returnSet;
        }
    }
    return new HashSet<RoleMapping>();
}
Also used : FileBasedIdPMgtDAO(org.wso2.carbon.idp.mgt.dao.FileBasedIdPMgtDAO) PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping) HashSet(java.util.HashSet)

Example 4 with RoleMapping

use of org.wso2.carbon.identity.application.common.model.xsd.RoleMapping in project carbon-identity-framework by wso2.

the class IdentityProviderManager method getMappedIdPRoles.

/**
 * Retrieves Identity provider information about a given tenant
 *
 * @param idPName      Unique name of the IdP to which the given local roles need to be mapped
 * @param tenantDomain The tenant domain of whose local roles need to be mapped
 * @param localRoles   Local roles which need to be mapped to IdP roles
 * @throws IdentityProviderManagementException Error when getting role mappings
 */
@Override
public Set<RoleMapping> getMappedIdPRoles(String idPName, String tenantDomain, LocalRole[] localRoles) throws IdentityProviderManagementException {
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    if (StringUtils.isEmpty(idPName)) {
        String msg = "Invalid argument: Identity Provider Name value is empty";
        throw new IdentityProviderManagementException(msg);
    }
    IdentityProvider identityProvider = dao.getIdPByName(null, idPName, tenantId, tenantDomain);
    if (identityProvider == null) {
        identityProvider = new FileBasedIdPMgtDAO().getIdPByName(idPName, tenantDomain);
    }
    if (identityProvider == null) {
        identityProvider = IdPManagementServiceComponent.getFileBasedIdPs().get(IdentityApplicationConstants.DEFAULT_IDP_CONFIG);
    }
    PermissionsAndRoleConfig roleConfiguration = identityProvider.getPermissionAndRoleConfig();
    if (roleConfiguration != null) {
        RoleMapping[] roleMappings = roleConfiguration.getRoleMappings();
        if (roleMappings != null && roleMappings.length > 0 && localRoles != null) {
            Set<RoleMapping> returnSet = new HashSet<RoleMapping>();
            for (LocalRole localRole : localRoles) {
                for (RoleMapping roleMapping : roleMappings) {
                    if (roleMapping.getLocalRole().equals(localRole)) {
                        returnSet.add(roleMapping);
                        break;
                    }
                }
            }
            return returnSet;
        }
    }
    return new HashSet<RoleMapping>();
}
Also used : FileBasedIdPMgtDAO(org.wso2.carbon.idp.mgt.dao.FileBasedIdPMgtDAO) PermissionsAndRoleConfig(org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) LocalRole(org.wso2.carbon.identity.application.common.model.LocalRole) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping) HashSet(java.util.HashSet)

Example 5 with RoleMapping

use of org.wso2.carbon.identity.application.common.model.xsd.RoleMapping in project carbon-identity-framework by wso2.

the class IdentityProviderManager method getMappedIdPRolesMap.

/**
 * Retrieves Identity provider information about a given tenant
 *
 * @param idPName      Unique name of the IdP to which the given local roles need to be mapped
 * @param tenantDomain The tenant domain of whose local roles need to be mapped
 * @param localRoles   Local roles which need to be mapped to IdP roles
 * @throws IdentityProviderManagementException Error when getting role mappings
 */
@Override
public Map<LocalRole, String> getMappedIdPRolesMap(String idPName, String tenantDomain, LocalRole[] localRoles) throws IdentityProviderManagementException {
    Set<RoleMapping> roleMappings = getMappedIdPRoles(idPName, tenantDomain, localRoles);
    Map<LocalRole, String> returnMap = new HashMap<LocalRole, String>();
    for (RoleMapping roleMapping : roleMappings) {
        returnMap.put(roleMapping.getLocalRole(), roleMapping.getRemoteRole());
    }
    return returnMap;
}
Also used : HashMap(java.util.HashMap) LocalRole(org.wso2.carbon.identity.application.common.model.LocalRole) RoleMapping(org.wso2.carbon.identity.application.common.model.RoleMapping)

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