Search in sources :

Example 51 with IdentityProvider

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

the class IdentityProviderManager method getResidentIDPMetadata.

public String getResidentIDPMetadata(String tenantDomain) throws IdentityProviderManagementException {
    if (IdpMgtServiceComponentHolder.getInstance().getMetadataConverters().isEmpty()) {
        throw new IdentityProviderManagementException("Error receiving Metadata object for tenant: " + tenantDomain);
    }
    IdentityProvider residentIdentityProvider = this.getResidentIdP(tenantDomain);
    FederatedAuthenticatorConfig[] federatedAuthenticatorConfigs = residentIdentityProvider.getFederatedAuthenticatorConfigs();
    FederatedAuthenticatorConfig samlFederatedAuthenticatorConfig = null;
    for (int i = 0; i < federatedAuthenticatorConfigs.length; i++) {
        if (federatedAuthenticatorConfigs[i].getName().equals(IdentityApplicationConstants.Authenticator.SAML2SSO.NAME)) {
            samlFederatedAuthenticatorConfig = federatedAuthenticatorConfigs[i];
            break;
        }
    }
    if (samlFederatedAuthenticatorConfig != null) {
        try {
            for (int t = 0; t < IdpMgtServiceComponentHolder.getInstance().getMetadataConverters().size(); t++) {
                MetadataConverter converter = IdpMgtServiceComponentHolder.getInstance().getMetadataConverters().get(t);
                if (converter.canHandle(samlFederatedAuthenticatorConfig)) {
                    return converter.getMetadataString(samlFederatedAuthenticatorConfig);
                }
            }
        } catch (IdentityProviderSAMLException e) {
            throw new IdentityProviderManagementException("Error in retrieving metadata string for tenant:" + tenantDomain, e.getMessage());
        }
    }
    return null;
}
Also used : FederatedAuthenticatorConfig(org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig) MetadataConverter(org.wso2.carbon.idp.mgt.util.MetadataConverter) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

Example 52 with IdentityProvider

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

the class IdentityProviderManager method deleteIdP.

/**
 * Deletes an Identity Provider from a given tenant
 *
 * @param idPName Name of the IdP to be deleted
 * @throws IdentityProviderManagementException Error when deleting Identity Provider
 *                                             information
 * @deprecated use {@link IdentityProviderManager#deleteIdPByResourceId(String, String)} instead.
 */
@Deprecated
@Override
public void deleteIdP(String idPName, String tenantDomain) throws IdentityProviderManagementException {
    // Invoking the pre listeners.
    Collection<IdentityProviderMgtListener> listeners = IdPManagementServiceComponent.getIdpMgtListeners();
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPreDeleteIdP(idPName, tenantDomain)) {
            return;
        }
    }
    if (StringUtils.isEmpty(idPName)) {
        String data = "IdP name is empty.";
        throw IdPManagementUtil.handleClientException(IdPManagementConstants.ErrorMessage.ERROR_CODE_IDP_NAME_INVALID, data);
    }
    IdentityProvider identityProvider = this.getIdPByName(idPName, tenantDomain, true);
    if (identityProvider == null) {
        return;
    }
    deleteIDP(identityProvider.getResourceId(), idPName, tenantDomain);
    // Invoking the post listeners.
    for (IdentityProviderMgtListener listener : listeners) {
        if (listener.isEnable() && !listener.doPostDeleteIdP(idPName, tenantDomain)) {
            return;
        }
    }
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderMgtListener(org.wso2.carbon.idp.mgt.listener.IdentityProviderMgtListener)

Example 53 with IdentityProvider

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider 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 54 with IdentityProvider

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider 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 55 with IdentityProvider

use of org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider 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)190 Test (org.testng.annotations.Test)103 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)65 ArrayList (java.util.ArrayList)64 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)54 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.IdentityProviderProperty)53 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)47 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.FederatedAuthenticatorConfig)47 API (org.wso2.carbon.apimgt.core.models.API)43 IdentityProvider (org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProvider)37 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)35 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)34 Property (org.wso2.carbon.identity.application.common.model.Property)29 FederatedAuthenticatorConfig (org.wso2.carbon.identity.application.common.model.idp.xsd.FederatedAuthenticatorConfig)29 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)27 Connection (java.sql.Connection)25 IdentityProviderProperty (org.wso2.carbon.identity.application.common.model.idp.xsd.IdentityProviderProperty)22 Property (org.wso2.carbon.identity.application.common.model.idp.xsd.Property)22 HashMap (java.util.HashMap)20 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)20