Search in sources :

Example 1 with IdPResourceIdCacheKey

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

the class CacheBackedIdPMgtDAO method addIdPCache.

/**
 * Add new cache entries for IDP against cache keys: name, home-realm-id and resource-id.
 *
 * @param identityProvider  Identity Provider information.
 * @param tenantDomain      Tenant domain of IDP.
 */
public void addIdPCache(IdentityProvider identityProvider, String tenantDomain) {
    if (identityProvider != null) {
        if (log.isDebugEnabled()) {
            log.debug("Adding new entry for Identity Provider: '" + identityProvider.getIdentityProviderName() + "' to cache.");
        }
        IdPNameCacheKey idPNameCacheKey = new IdPNameCacheKey(identityProvider.getIdentityProviderName());
        idPCacheByName.addToCache(idPNameCacheKey, new IdPCacheEntry(identityProvider), tenantDomain);
        if (identityProvider.getHomeRealmId() != null) {
            IdPHomeRealmIdCacheKey idPHomeRealmIdCacheKey = new IdPHomeRealmIdCacheKey(identityProvider.getHomeRealmId());
            idPCacheByHRI.addToCache(idPHomeRealmIdCacheKey, new IdPCacheEntry(identityProvider), tenantDomain);
        }
        IdPResourceIdCacheKey idPResourceIdCacheKey = new IdPResourceIdCacheKey(identityProvider.getResourceId());
        idPCacheByResourceId.addToCache(idPResourceIdCacheKey, new IdPCacheEntry(identityProvider), tenantDomain);
    }
}
Also used : IdPCacheEntry(org.wso2.carbon.idp.mgt.cache.IdPCacheEntry) IdPHomeRealmIdCacheKey(org.wso2.carbon.idp.mgt.cache.IdPHomeRealmIdCacheKey) IdPNameCacheKey(org.wso2.carbon.idp.mgt.cache.IdPNameCacheKey) IdPResourceIdCacheKey(org.wso2.carbon.idp.mgt.cache.IdPResourceIdCacheKey)

Example 2 with IdPResourceIdCacheKey

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

the class CacheBackedIdPMgtDAO method getIdPNameByResourceId.

public String getIdPNameByResourceId(String resourceId) throws IdentityProviderManagementException {
    IdPResourceIdCacheKey cacheKey = new IdPResourceIdCacheKey(resourceId);
    IdPCacheEntry entry = idPCacheByResourceId.getValueFromCache(cacheKey, CarbonContext.getThreadLocalCarbonContext().getTenantDomain());
    if (entry != null) {
        if (log.isDebugEnabled()) {
            log.debug("Cache entry found for Identity Provider with resource ID:" + resourceId);
        }
        IdentityProvider identityProvider = entry.getIdentityProvider();
        return identityProvider.getIdentityProviderName();
    }
    if (log.isDebugEnabled()) {
        log.debug("Cache entry not found for Identity Provider with resource ID: " + resourceId + ". Fetching the name from DB");
    }
    return idPMgtDAO.getIDPNameByResourceId(resourceId);
}
Also used : IdPCacheEntry(org.wso2.carbon.idp.mgt.cache.IdPCacheEntry) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdPResourceIdCacheKey(org.wso2.carbon.idp.mgt.cache.IdPResourceIdCacheKey)

Example 3 with IdPResourceIdCacheKey

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

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

the class CacheBackedIdPMgtDAO method getIdPByResourceId.

/**
 * @param resourceId   resource ID of the identity provider.
 * @param tenantId     Tenant ID of the identity provider.
 * @param tenantDomain Tenant domain of the identity provider.
 * @return Identity provider with given resource ID.
 * @throws IdentityProviderManagementException
 */
public IdentityProvider getIdPByResourceId(String resourceId, int tenantId, String tenantDomain) throws IdentityProviderManagementException {
    IdentityProvider identityProvider;
    IdPResourceIdCacheKey cacheKey = new IdPResourceIdCacheKey(resourceId);
    IdPCacheEntry entry = idPCacheByResourceId.getValueFromCache(cacheKey, tenantDomain);
    if (entry != null) {
        if (log.isDebugEnabled()) {
            log.debug("Cache entry found for Identity Provider with resource ID:" + resourceId);
        }
        identityProvider = entry.getIdentityProvider();
        IdPManagementUtil.removeRandomPasswords(identityProvider, false);
        return identityProvider;
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Cache entry not found for Identity Provider with resource ID: " + resourceId + ". Fetching entry from DB");
        }
        identityProvider = idPMgtDAO.getIDPbyResourceId(null, resourceId, tenantId, tenantDomain);
        if (identityProvider != null) {
            addIdPCache(identityProvider, tenantDomain);
        } else {
            if (log.isDebugEnabled()) {
                log.debug(String.format("No IDP found with resource ID: %s either in cache or DB", resourceId));
            }
        }
    }
    return identityProvider;
}
Also used : IdPCacheEntry(org.wso2.carbon.idp.mgt.cache.IdPCacheEntry) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdPResourceIdCacheKey(org.wso2.carbon.idp.mgt.cache.IdPResourceIdCacheKey)

Example 5 with IdPResourceIdCacheKey

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

the class CacheBackedIdPMgtDAO method getUpdatedIdPByResourceId.

/**
 * Get the updated IDP details using the resource ID.
 *
 * @param resourceId   Resource ID of the identity provider.
 * @param tenantId     Tenant ID of the identity provider.
 * @param tenantDomain Tenant domain of the identity provider.
 * @return Updated identity provider with given resource ID.
 * @throws IdentityProviderManagementException Error when getting the identity provider.
 */
public IdentityProvider getUpdatedIdPByResourceId(String resourceId, int tenantId, String tenantDomain) throws IdentityProviderManagementException {
    IdentityProvider identityProvider;
    IdPResourceIdCacheKey cacheKey = new IdPResourceIdCacheKey(resourceId);
    IdPCacheEntry entry = idPCacheByResourceId.getValueFromCache(cacheKey, tenantDomain);
    if (entry != null) {
        /*
             * Before updating an IDP we clear the cache. Therefore, if we get a cache hit again at this point, it
             * should be a reason of some other process done on the same IDP. Hence, we need to clear the cache before
             * proceed in order to generate a correct response.
             */
        if (log.isDebugEnabled()) {
            log.debug("Cache entry found for Identity Provider with resource ID: " + resourceId + ". Hence clear the cache before proceed.");
        }
        identityProvider = entry.getIdentityProvider();
        clearIdpCache(identityProvider.getIdentityProviderName(), identityProvider.getResourceId(), tenantId, tenantDomain);
    }
    identityProvider = idPMgtDAO.getIDPbyResourceId(null, resourceId, tenantId, tenantDomain);
    if (identityProvider == null) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("No IDP found with resource ID: %s in DB", resourceId));
        }
        return null;
    }
    addIdPCache(identityProvider, tenantDomain);
    return identityProvider;
}
Also used : IdPCacheEntry(org.wso2.carbon.idp.mgt.cache.IdPCacheEntry) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) IdPResourceIdCacheKey(org.wso2.carbon.idp.mgt.cache.IdPResourceIdCacheKey)

Aggregations

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