Search in sources :

Example 76 with IdentityProvider

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

the class CacheBackedIdPMgtDAO method clearIdpCache.

public void clearIdpCache(String idPName, String resourceId, int tenantId, String tenantDomain) throws IdentityProviderManagementException {
    // clearing cache entries related to the IDP.
    IdentityProvider identityProvider;
    if (StringUtils.isNotBlank(resourceId)) {
        identityProvider = this.getIdPByResourceId(resourceId, tenantId, tenantDomain);
    } else {
        identityProvider = this.getIdPByName(null, idPName, tenantId, tenantDomain);
    }
    if (identityProvider != null) {
        if (log.isDebugEnabled()) {
            log.debug("Removing entry for Identity Provider " + idPName + " of tenantDomain:" + tenantDomain + " from cache.");
        }
        IdPNameCacheKey idPNameCacheKey = new IdPNameCacheKey(idPName);
        idPCacheByName.clearCacheEntry(idPNameCacheKey, tenantDomain);
        if (identityProvider.getHomeRealmId() != null) {
            IdPHomeRealmIdCacheKey idPHomeRealmIdCacheKey = new IdPHomeRealmIdCacheKey(identityProvider.getHomeRealmId());
            idPCacheByHRI.clearCacheEntry(idPHomeRealmIdCacheKey, tenantDomain);
        }
        if (StringUtils.isNotBlank(resourceId)) {
            IdPResourceIdCacheKey idPResourceIdCacheKey = new IdPResourceIdCacheKey(resourceId);
            idPCacheByResourceId.clearCacheEntry(idPResourceIdCacheKey, tenantDomain);
        }
        String idPIssuerName = getIDPIssuerName(identityProvider);
        if (StringUtils.isNotBlank(idPIssuerName)) {
            IdPMetadataPropertyCacheKey cacheKey = new IdPMetadataPropertyCacheKey(IdentityApplicationConstants.IDP_ISSUER_NAME, idPIssuerName);
            idPCacheByMetadataProperty.clearCacheEntry(cacheKey, tenantDomain);
        }
    } else {
        log.debug("Entry for Identity Provider " + idPName + " not found in cache or DB");
    }
}
Also used : IdPHomeRealmIdCacheKey(org.wso2.carbon.idp.mgt.cache.IdPHomeRealmIdCacheKey) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdPNameCacheKey(org.wso2.carbon.idp.mgt.cache.IdPNameCacheKey) IdPResourceIdCacheKey(org.wso2.carbon.idp.mgt.cache.IdPResourceIdCacheKey) IdPMetadataPropertyCacheKey(org.wso2.carbon.idp.mgt.cache.IdPMetadataPropertyCacheKey)

Example 77 with IdentityProvider

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

the class CacheBackedIdPMgtDAO method deleteIdP.

/**
 * @param idPName
 * @param tenantId
 * @param tenantDomain
 * @throws IdentityProviderManagementException
 */
public void deleteIdP(String idPName, int tenantId, String tenantDomain) throws IdentityProviderManagementException {
    if (idPMgtDAO.isIdpReferredBySP(idPName, tenantId)) {
        throw new IdentityProviderManagementException("Identity Provider '" + idPName + "' " + "cannot be deleted as it is referred by Service Providers.");
    }
    IdentityProvider identityProvider = this.getIdPByName(null, idPName, tenantId, tenantDomain);
    if (identityProvider != null) {
        idPMgtDAO.deleteIdP(idPName, tenantId, tenantDomain);
        clearIdpCache(idPName, tenantId, tenantDomain);
    } else {
        if (log.isDebugEnabled()) {
            log.debug(String.format("IDP:%s of tenantDomain:%s is not found is cache or DB", idPName, tenantDomain));
        }
    }
}
Also used : IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 78 with IdentityProvider

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

the class IdPManagementDAO method getIdPsSearch.

/**
 * Get all identity provider's Basic information along with additionally requested information depends on the
 * requiredAttributes for a given matching filter.
 *
 * @param tenantId           Tenant Id of the identity provider.
 * @param expressionNode     List of filter value for IdP search.
 * @param limit              Limit per page.
 * @param offset             Offset value.
 * @param sortOrder          Order of IdP ASC/DESC.
 * @param sortBy             The attribute need to sort.
 * @param requiredAttributes Required attributes which needs to be return.
 * @return Identity Provider's Basic Information array along with requested attribute information.
 * @throws IdentityProviderManagementServerException Error when getting list of Identity Providers.
 * @throws IdentityProviderManagementClientException Error when append the filer string.
 */
List<IdentityProvider> getIdPsSearch(int tenantId, List<ExpressionNode> expressionNode, int limit, int offset, String sortOrder, String sortBy, List<String> requiredAttributes) throws IdentityProviderManagementServerException, IdentityProviderManagementClientException {
    FilterQueryBuilder filterQueryBuilder = new FilterQueryBuilder();
    appendFilterQuery(expressionNode, filterQueryBuilder);
    String sortedOrder = sortBy + " " + sortOrder;
    try (Connection dbConnection = IdentityDatabaseUtil.getDBConnection(false);
        ResultSet resultSet = getIdpQueryResultSet(dbConnection, sortedOrder, tenantId, offset, limit, filterQueryBuilder, requiredAttributes)) {
        return populateIdentityProviderList(resultSet, dbConnection, requiredAttributes, tenantId);
    } catch (SQLException e) {
        String message = "Error occurred while retrieving Identity Provider for tenant: " + IdentityTenantUtil.getTenantDomain(tenantId);
        throw IdPManagementUtil.handleServerException(IdPManagementConstants.ErrorMessage.ERROR_CODE_CONNECTING_DATABASE, message, e);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) FilterQueryBuilder(org.wso2.carbon.idp.mgt.model.FilterQueryBuilder)

Example 79 with IdentityProvider

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

the class IdPManagementDAO method forceDeleteIdP.

public void forceDeleteIdP(String idPName, int tenantId, String tenantDomain) throws IdentityProviderManagementException {
    Connection dbConnection = IdentityDatabaseUtil.getDBConnection();
    try {
        IdentityProvider identityProvider = getIdPByName(dbConnection, idPName, tenantId, tenantDomain);
        if (identityProvider == null) {
            String msg = "Trying to force delete non-existent Identity Provider: %s in tenantDomain: %s";
            throw new IdentityProviderManagementException(String.format(msg, idPName, tenantDomain));
        }
        if (log.isDebugEnabled()) {
            log.debug(String.format("Deleting SP Authentication Associations for IDP:%s of tenantDomain:%s", idPName, tenantDomain));
        }
        // Delete IDPs association with SPs in authentication sequences
        deleteIdpSpAuthAssociations(dbConnection, tenantId, idPName);
        // Delete IDPs association with SPs in outbound provisioning
        if (log.isDebugEnabled()) {
            log.debug(String.format("Deleting SP Provisioning Associations for IDP:%s of tenantDomain:%s", idPName, tenantDomain));
        }
        deleteIdpSpProvisioningAssociations(dbConnection, tenantId, idPName);
        deleteIdP(dbConnection, tenantId, idPName, null);
        IdentityDatabaseUtil.commitTransaction(dbConnection);
    } catch (SQLException e) {
        IdentityDatabaseUtil.rollbackTransaction(dbConnection);
        throw new IdentityProviderManagementException(String.format("Error occurred while deleting Identity Provider:%s of tenant:%s ", idPName, tenantDomain), e);
    } finally {
        IdentityDatabaseUtil.closeConnection(dbConnection);
    }
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException)

Example 80 with IdentityProvider

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

the class IdPManagementDAO method populateIdentityProviderList.

/**
 * Populate the result set.
 *
 * @param resultSet          ResultSet.
 * @param dbConnection       Database Connection.
 * @param requiredAttributes Required attributes which needs to be return.
 * @param tenantId           Tenant Id of the identity provider.
 * @return List of Identity Provider.
 * @throws SQLException Database Exception.
 */
private List<IdentityProvider> populateIdentityProviderList(ResultSet resultSet, Connection dbConnection, List<String> requiredAttributes, int tenantId) throws SQLException, IdentityProviderManagementServerException {
    List<IdentityProvider> identityProviderList = new ArrayList<>();
    while (resultSet.next()) {
        IdentityProvider identityProvider = new IdentityProvider();
        // First set the basic attributes such as id, name, description, isEnabled, image url, uuid.
        identityProvider.setId(resultSet.getString("ID"));
        identityProvider.setIdentityProviderName(resultSet.getString("NAME"));
        identityProvider.setIdentityProviderDescription(resultSet.getString("DESCRIPTION"));
        // IS_ENABLE
        if ((IdPManagementConstants.IS_TRUE_VALUE).equals(resultSet.getString("IS_ENABLED"))) {
            identityProvider.setEnable(true);
        } else {
            identityProvider.setEnable(false);
        }
        identityProvider.setImageUrl(resultSet.getString("IMAGE_URL"));
        identityProvider.setResourceId(resultSet.getString("UUID"));
        populateRequiredAttributesForIdentityProviderList(resultSet, dbConnection, requiredAttributes, tenantId, identityProvider);
        if (!IdentityApplicationConstants.RESIDENT_IDP_RESERVED_NAME.equals(identityProvider.getIdentityProviderName())) {
            identityProviderList.add(identityProvider);
        }
        List<IdentityProviderProperty> propertyList = getIdentityPropertiesByIdpId(dbConnection, Integer.parseInt(resultSet.getString("ID")));
        identityProvider.setIdpProperties(propertyList.toArray(new IdentityProviderProperty[0]));
    }
    return identityProviderList;
}
Also used : IdentityProviderProperty(org.wso2.carbon.identity.application.common.model.IdentityProviderProperty) ArrayList(java.util.ArrayList) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider)

Aggregations

IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)191 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