Search in sources :

Example 1 with FileBasedIdPMgtDAO

use of org.wso2.carbon.idp.mgt.dao.FileBasedIdPMgtDAO in project carbon-identity-framework by wso2.

the class IdentityProviderManager method getIdPById.

@Override
public IdentityProvider getIdPById(String id, String tenantDomain, boolean ignoreFileBasedIdps) throws IdentityProviderManagementException {
    if (StringUtils.isEmpty(id)) {
        String msg = "Invalid argument: Identity Provider ID value is empty";
        throw new IdentityProviderManagementException(msg);
    }
    int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
    Integer intId;
    IdentityProvider identityProvider = null;
    try {
        intId = Integer.parseInt(id);
        identityProvider = dao.getIdPById(null, intId, tenantId, tenantDomain);
    } catch (NumberFormatException e) {
    // Ignore this.
    }
    if (!ignoreFileBasedIdps) {
        if (identityProvider == null) {
            identityProvider = new FileBasedIdPMgtDAO().getIdPByName(id, tenantDomain);
        }
        if (identityProvider == null) {
            identityProvider = IdPManagementServiceComponent.getFileBasedIdPs().get(IdentityApplicationConstants.DEFAULT_IDP_CONFIG);
        }
    }
    return identityProvider;
}
Also used : FileBasedIdPMgtDAO(org.wso2.carbon.idp.mgt.dao.FileBasedIdPMgtDAO) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

Example 2 with FileBasedIdPMgtDAO

use of org.wso2.carbon.idp.mgt.dao.FileBasedIdPMgtDAO 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 3 with FileBasedIdPMgtDAO

use of org.wso2.carbon.idp.mgt.dao.FileBasedIdPMgtDAO 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 4 with FileBasedIdPMgtDAO

use of org.wso2.carbon.idp.mgt.dao.FileBasedIdPMgtDAO in project carbon-identity-framework by wso2.

the class IdentityProviderManager method getMappedLocalClaims.

/**
 * Retrieves Identity provider information about a given tenant
 *
 * @param idPName      Unique Name of the IdP to which the given IdP claim URIs need to be mapped
 * @param tenantDomain The tenant domain of whose local claim URIs to be mapped
 * @param idPClaimURIs IdP claim URIs which need to be mapped to tenant's local claim URIs
 * @throws IdentityProviderManagementException Error when getting claim mappings
 */
@Override
public Set<ClaimMapping> getMappedLocalClaims(String idPName, String tenantDomain, List<String> idPClaimURIs) 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);
    }
    ClaimConfig claimConfiguration = identityProvider.getClaimConfig();
    if (claimConfiguration != null) {
        ClaimMapping[] claimMappings = claimConfiguration.getClaimMappings();
        if (claimMappings != null && claimMappings.length > 0 && idPClaimURIs != null) {
            Set<ClaimMapping> returnSet = new HashSet<ClaimMapping>();
            for (String idpClaim : idPClaimURIs) {
                for (ClaimMapping claimMapping : claimMappings) {
                    if (claimMapping.getRemoteClaim().getClaimUri().equals(idpClaim)) {
                        returnSet.add(claimMapping);
                        break;
                    }
                }
            }
            return returnSet;
        }
    }
    return new HashSet<ClaimMapping>();
}
Also used : FileBasedIdPMgtDAO(org.wso2.carbon.idp.mgt.dao.FileBasedIdPMgtDAO) ClaimMapping(org.wso2.carbon.identity.application.common.model.ClaimMapping) ClaimConfig(org.wso2.carbon.identity.application.common.model.ClaimConfig) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) HashSet(java.util.HashSet)

Example 5 with FileBasedIdPMgtDAO

use of org.wso2.carbon.idp.mgt.dao.FileBasedIdPMgtDAO in project carbon-identity-framework by wso2.

the class IdentityProviderManager method getIdPByName.

/**
 * @param idPName
 * @param tenantDomain
 * @param ignoreFileBasedIdps
 * @return
 * @throws IdentityProviderManagementException
 */
@Override
public IdentityProvider getIdPByName(String idPName, String tenantDomain, boolean ignoreFileBasedIdps) 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 (!ignoreFileBasedIdps) {
        if (identityProvider == null) {
            identityProvider = new FileBasedIdPMgtDAO().getIdPByName(idPName, tenantDomain);
        }
        if (identityProvider == null) {
            identityProvider = IdPManagementServiceComponent.getFileBasedIdPs().get(IdentityApplicationConstants.DEFAULT_IDP_CONFIG);
        }
    }
    return identityProvider;
}
Also used : FileBasedIdPMgtDAO(org.wso2.carbon.idp.mgt.dao.FileBasedIdPMgtDAO) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

Aggregations

IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)8 FileBasedIdPMgtDAO (org.wso2.carbon.idp.mgt.dao.FileBasedIdPMgtDAO)8 HashSet (java.util.HashSet)4 ClaimConfig (org.wso2.carbon.identity.application.common.model.ClaimConfig)2 ClaimMapping (org.wso2.carbon.identity.application.common.model.ClaimMapping)2 PermissionsAndRoleConfig (org.wso2.carbon.identity.application.common.model.PermissionsAndRoleConfig)2 RoleMapping (org.wso2.carbon.identity.application.common.model.RoleMapping)2 LocalRole (org.wso2.carbon.identity.application.common.model.LocalRole)1