Search in sources :

Example 1 with IdPMetadataPropertyCacheKey

use of org.wso2.carbon.idp.mgt.cache.IdPMetadataPropertyCacheKey in project carbon-identity-framework by wso2.

the class CacheBackedIdPMgtDAO method getIdPNameByMetadataProperty.

/**
 * Retrieves the first matching IDP for the given metadata property.
 * Intended to ony be used to retrieve IDP name based on a unique metadata property.
 *
 * @param dbConnection Optional. DB connection.
 * @param property IDP metadata property name.
 * @param value Value associated with given Property.
 * @param tenantId Tenant id whose information is requested.
 * @param tenantDomain Tenant domain whose information is requested.
 * @return Identity Provider name.
 * @throws IdentityProviderManagementException IdentityProviderManagementException.
 */
public String getIdPNameByMetadataProperty(Connection dbConnection, String property, String value, int tenantId, String tenantDomain) throws IdentityProviderManagementException {
    IdPMetadataPropertyCacheKey cacheKey = new IdPMetadataPropertyCacheKey(property, value);
    String idPName = idPCacheByMetadataProperty.getValueFromCache(cacheKey, tenantDomain);
    if (idPName != null) {
        if (log.isDebugEnabled()) {
            log.debug("Cache entry IDP name: " + idPName + " found for IDP metadata property name: " + property + " value: " + value);
        }
        return idPName;
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Cache entry not found for IDP metadata property name: " + property + " value: " + value + ". Fetching entry from DB");
        }
    }
    idPName = idPMgtDAO.getIdPNameByMetadataProperty(dbConnection, property, value, tenantId);
    if (idPName != null) {
        if (log.isDebugEnabled()) {
            log.debug("DB entry IDP name: " + idPName + " found for IDP metadata property name: " + property + " value: " + value);
        }
        idPCacheByMetadataProperty.addToCache(cacheKey, idPName, tenantDomain);
    } else {
        if (log.isDebugEnabled()) {
            log.debug("DB entry not found for IDP metadata property name: " + property + " value: " + value);
        }
    }
    return idPName;
}
Also used : IdPMetadataPropertyCacheKey(org.wso2.carbon.idp.mgt.cache.IdPMetadataPropertyCacheKey)

Example 2 with IdPMetadataPropertyCacheKey

use of org.wso2.carbon.idp.mgt.cache.IdPMetadataPropertyCacheKey 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)

Aggregations

IdPMetadataPropertyCacheKey (org.wso2.carbon.idp.mgt.cache.IdPMetadataPropertyCacheKey)2 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)1 IdPHomeRealmIdCacheKey (org.wso2.carbon.idp.mgt.cache.IdPHomeRealmIdCacheKey)1 IdPNameCacheKey (org.wso2.carbon.idp.mgt.cache.IdPNameCacheKey)1 IdPResourceIdCacheKey (org.wso2.carbon.idp.mgt.cache.IdPResourceIdCacheKey)1