Search in sources :

Example 1 with ServiceProviderProvisioningConnectorCacheEntry

use of org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheEntry in project carbon-identity-framework by wso2.

the class OutboundProvisioningManager method getOutboundProvisioningConnectors.

/**
 * TODO: Need to cache the output from this method.
 *
 * @return
 * @throws UserStoreException
 */
private Map<String, RuntimeProvisioningConfig> getOutboundProvisioningConnectors(ServiceProvider serviceProvider, String tenantDomain) throws IdentityProvisioningException {
    Map<String, RuntimeProvisioningConfig> connectors = new HashMap<>();
    ServiceProviderProvisioningConnectorCacheKey key;
    ServiceProviderProvisioningConnectorCacheEntry entry;
    // Reading from the cache.
    if (serviceProvider != null && tenantDomain != null) {
        key = new ServiceProviderProvisioningConnectorCacheKey(serviceProvider.getApplicationName());
        entry = ServiceProviderProvisioningConnectorCache.getInstance().getValueFromCache(key, tenantDomain);
        // cache hit
        if (entry != null) {
            if (log.isDebugEnabled()) {
                log.debug("Provisioning cache HIT for " + serviceProvider + " of " + tenantDomain);
            }
            return entry.getConnectors();
        }
    } else {
        throw new IdentityProvisioningException("Error reading service provider from cache.");
    }
    // NOW build the Map
    // a list of registered provisioning connector factories.
    Map<String, AbstractProvisioningConnectorFactory> registeredConnectorFactories = IdentityProvisionServiceComponent.getConnectorFactories();
    // get all registered list of out-bound provisioning connectors registered for the local
    // service provider.
    OutboundProvisioningConfig outboundProvisioningConfiguration = serviceProvider.getOutboundProvisioningConfig();
    if (outboundProvisioningConfiguration == null) {
        if (log.isDebugEnabled()) {
            log.debug("No outbound provisioning configuration defined for local service provider.");
        }
        // empty list.
        return new HashMap<String, RuntimeProvisioningConfig>();
    }
    // get the list of registered provisioning identity providers in out-bound provisioning
    // configuration.
    IdentityProvider[] provisionningIdPList = outboundProvisioningConfiguration.getProvisioningIdentityProviders();
    if (provisionningIdPList != null && provisionningIdPList.length > 0) {
        for (IdentityProvider fIdP : provisionningIdPList) {
            try {
                AbstractOutboundProvisioningConnector connector;
                ProvisioningConnectorConfig defaultConnector = fIdP.getDefaultProvisioningConnectorConfig();
                if (defaultConnector != null) {
                    // if no default provisioning connector defined for this identity provider,
                    // we can safely ignore it - need not to worry about provisioning.
                    String connectorType = fIdP.getDefaultProvisioningConnectorConfig().getName();
                    boolean enableJitProvisioning = false;
                    if (fIdP.getJustInTimeProvisioningConfig() != null && fIdP.getJustInTimeProvisioningConfig().isProvisioningEnabled()) {
                        enableJitProvisioning = true;
                    }
                    connector = getOutboundProvisioningConnector(fIdP, registeredConnectorFactories, tenantDomain, enableJitProvisioning);
                    // configuration of the local service provider.
                    if (connector != null) {
                        RuntimeProvisioningConfig proConfig = new RuntimeProvisioningConfig();
                        proConfig.setProvisioningConnectorEntry(new SimpleEntry<>(connectorType, connector));
                        proConfig.setBlocking(defaultConnector.isBlocking());
                        proConfig.setPolicyEnabled(defaultConnector.isRulesEnabled());
                        connectors.put(fIdP.getIdentityProviderName(), proConfig);
                    }
                }
            } catch (IdentityProviderManagementException e) {
                throw new IdentityProvisioningException("Error while retrieving idp configuration for " + fIdP.getIdentityProviderName(), e);
            }
        }
    }
    entry = new ServiceProviderProvisioningConnectorCacheEntry();
    entry.setConnectors(connectors);
    ServiceProviderProvisioningConnectorCache.getInstance().addToCache(key, entry, tenantDomain);
    if (log.isDebugEnabled()) {
        log.debug("Entry added successfully ");
    }
    return connectors;
}
Also used : HashMap(java.util.HashMap) IdentityProvider(org.wso2.carbon.identity.application.common.model.IdentityProvider) OutboundProvisioningConfig(org.wso2.carbon.identity.application.common.model.OutboundProvisioningConfig) ServiceProviderProvisioningConnectorCacheEntry(org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheEntry) ServiceProviderProvisioningConnectorCacheKey(org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheKey) IdentityProviderManagementException(org.wso2.carbon.idp.mgt.IdentityProviderManagementException) ProvisioningConnectorConfig(org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)

Example 2 with ServiceProviderProvisioningConnectorCacheEntry

use of org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheEntry in project carbon-identity-framework by wso2.

the class ProvisioningIdentityProviderMgtListener method destroyConnector.

/**
 * @param identityProviderName
 * @param tenantDomain
 * @throws IdentityProvisioningException
 */
public void destroyConnector(String identityProviderName, String tenantDomain) throws IdentityProvisioningException {
    ProvisioningConnectorCacheKey cacheKey = new ProvisioningConnectorCacheKey(identityProviderName);
    ProvisioningConnectorCacheEntry entry = ProvisioningConnectorCache.getInstance().getValueFromCache(cacheKey, tenantDomain);
    if (entry != null) {
        ProvisioningConnectorCache.getInstance().clearCacheEntry(cacheKey, tenantDomain);
        if (log.isDebugEnabled()) {
            log.debug("Provisioning cached entry removed for idp " + identityProviderName);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Provisioning cached entry not found for idp " + identityProviderName);
        }
    }
    int tenantId;
    try {
        RealmService realmService = ProvisioningServiceDataHolder.getInstance().getRealmService();
        tenantId = realmService.getTenantManager().getTenantId(tenantDomain);
    } catch (UserStoreException e) {
        throw new IdentityProvisioningException("Error occurred while retrieving tenant id from tenant domain", e);
    }
    try {
        List<String> serviceProviders = provisioningManagementDAO.getSPNamesOfProvisioningConnectorsByIDP(identityProviderName, tenantId);
        for (String serviceProvider : serviceProviders) {
            ServiceProviderProvisioningConnectorCacheKey key = new ServiceProviderProvisioningConnectorCacheKey(serviceProvider);
            ServiceProviderProvisioningConnectorCacheEntry cacheEntry = ServiceProviderProvisioningConnectorCache.getInstance().getValueFromCache(key, tenantDomain);
            if (cacheEntry != null) {
                ServiceProviderProvisioningConnectorCache.getInstance().clearCacheEntry(key, tenantDomain);
                if (log.isDebugEnabled()) {
                    log.debug("Service Provider '" + serviceProvider + "' Provisioning cached entry removed for idp " + identityProviderName);
                }
            } else {
                if (log.isDebugEnabled()) {
                    log.debug("Service Provider '" + serviceProvider + "' Provisioning cached entry not found for idp " + identityProviderName);
                }
            }
        }
    } catch (IdentityApplicationManagementException e) {
        throw new IdentityProvisioningException("Error occurred while removing cache entry from the " + "service provider provisioning connector cache", e);
    }
}
Also used : ServiceProviderProvisioningConnectorCacheEntry(org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheEntry) ProvisioningConnectorCacheEntry(org.wso2.carbon.identity.provisioning.cache.ProvisioningConnectorCacheEntry) IdentityProvisioningException(org.wso2.carbon.identity.provisioning.IdentityProvisioningException) ServiceProviderProvisioningConnectorCacheKey(org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheKey) ProvisioningConnectorCacheKey(org.wso2.carbon.identity.provisioning.cache.ProvisioningConnectorCacheKey) RealmService(org.wso2.carbon.user.core.service.RealmService) ServiceProviderProvisioningConnectorCacheEntry(org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheEntry) ServiceProviderProvisioningConnectorCacheKey(org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheKey) IdentityApplicationManagementException(org.wso2.carbon.identity.application.common.IdentityApplicationManagementException) UserStoreException(org.wso2.carbon.user.api.UserStoreException)

Example 3 with ServiceProviderProvisioningConnectorCacheEntry

use of org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheEntry in project carbon-identity-framework by wso2.

the class ProvisioningApplicationMgtListener method destroySpProvConnectors.

private void destroySpProvConnectors(String applicationName, String tenantDomain) {
    // reading from the cache
    ServiceProviderProvisioningConnectorCacheKey key = new ServiceProviderProvisioningConnectorCacheKey(applicationName);
    ServiceProviderProvisioningConnectorCacheEntry entry = ServiceProviderProvisioningConnectorCache.getInstance().getValueFromCache(key, tenantDomain);
    // cache hit
    if (entry != null) {
        ServiceProviderProvisioningConnectorCache.getInstance().clearCacheEntry(key, tenantDomain);
        if (log.isDebugEnabled()) {
            log.debug("Provisioning cached entry removed for sp " + applicationName);
        }
    } else {
        if (log.isDebugEnabled()) {
            log.debug("Provisioning cached entry not found for sp " + applicationName);
        }
    }
}
Also used : ServiceProviderProvisioningConnectorCacheEntry(org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheEntry) ServiceProviderProvisioningConnectorCacheKey(org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheKey)

Aggregations

ServiceProviderProvisioningConnectorCacheEntry (org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheEntry)3 ServiceProviderProvisioningConnectorCacheKey (org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheKey)3 HashMap (java.util.HashMap)1 IdentityApplicationManagementException (org.wso2.carbon.identity.application.common.IdentityApplicationManagementException)1 IdentityProvider (org.wso2.carbon.identity.application.common.model.IdentityProvider)1 OutboundProvisioningConfig (org.wso2.carbon.identity.application.common.model.OutboundProvisioningConfig)1 ProvisioningConnectorConfig (org.wso2.carbon.identity.application.common.model.ProvisioningConnectorConfig)1 IdentityProvisioningException (org.wso2.carbon.identity.provisioning.IdentityProvisioningException)1 ProvisioningConnectorCacheEntry (org.wso2.carbon.identity.provisioning.cache.ProvisioningConnectorCacheEntry)1 ProvisioningConnectorCacheKey (org.wso2.carbon.identity.provisioning.cache.ProvisioningConnectorCacheKey)1 IdentityProviderManagementException (org.wso2.carbon.idp.mgt.IdentityProviderManagementException)1 UserStoreException (org.wso2.carbon.user.api.UserStoreException)1 RealmService (org.wso2.carbon.user.core.service.RealmService)1