use of org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheKey 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;
}
use of org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheKey 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);
}
}
use of org.wso2.carbon.identity.provisioning.cache.ServiceProviderProvisioningConnectorCacheKey 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);
}
}
}
Aggregations