use of com.sun.identity.idm.IdRepo in project OpenAM by OpenRock.
the class IdServicesImpl method isActive.
public boolean isActive(SSOToken token, IdType type, String name, String amOrgName, String amsdkDN) throws SSOException, IdRepoException {
IdRepoException origEx = null;
// Check permission first. If allowed then proceed, else the
// checkPermission method throws an "402" exception.
checkPermission(token, amOrgName, name, null, IdOperation.READ, type);
// First get the list of plugins that support the create operation.
Set configuredPluginClasses = idrepoCache.getIdRepoPlugins(amOrgName, IdOperation.READ, type);
if ((configuredPluginClasses == null) || configuredPluginClasses.isEmpty()) {
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.NO_PLUGINS_CONFIGURED, null);
}
// To avoid loading other plugins
if (isSpecialIdentity(token, name, type, amOrgName)) {
try {
for (Iterator items = configuredPluginClasses.iterator(); items.hasNext(); ) {
IdRepo idRepo = (IdRepo) items.next();
if (idRepo.getClass().getName().equals(IdConstants.SPECIAL_PLUGIN)) {
return (idRepo.isActive(token, type, name));
}
}
} catch (Exception idm) {
// Ignore exception
}
}
// Iterator through the plugins
Iterator it = configuredPluginClasses.iterator();
int noOfSuccess = configuredPluginClasses.size();
boolean active = false;
while (it.hasNext()) {
IdRepo idRepo = (IdRepo) it.next();
try {
if (idRepo.getClass().getName().equals(IdConstants.AMSDK_PLUGIN) && (amsdkDN != null)) {
active = idRepo.isActive(token, type, amsdkDN);
} else if (idRepo.getClass().getName().equals(IdConstants.SPECIAL_PLUGIN)) {
// Already checked above
noOfSuccess--;
continue;
} else {
active = idRepo.isActive(token, type, name);
}
if (active) {
break;
}
} catch (IdRepoFatalException idf) {
// fatal ..throw it all the way up
DEBUG.error("IdServicesImpl.isActive: Fatal Exception ", idf);
throw idf;
} catch (IdRepoException ide) {
if (idRepo != null && DEBUG.warningEnabled()) {
DEBUG.warning("IdServicesImpl.isActive: " + "Unable to check isActive identity in the " + "following repository " + idRepo.getClass().getName() + " :: " + ide.getMessage());
}
noOfSuccess--;
origEx = (origEx == null) ? ide : origEx;
}
}
if (noOfSuccess == 0) {
if (DEBUG.warningEnabled()) {
DEBUG.warning("IdServicesImpl.isActive: " + "Unable to check if identity is active " + type.getName() + "::" + name + " in any configured data store", origEx);
}
if (origEx != null) {
throw origEx;
} else {
Object[] args = { "isActive", IdOperation.READ.getName() };
throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.PLUGIN_OPERATION_NOT_SUPPORTED, args);
}
}
return active;
}
use of com.sun.identity.idm.IdRepo in project OpenAM by OpenRock.
the class IdRepoPluginsCache method removeIdRepo.
/**
* Delete an IdRepo plugin
*/
private void removeIdRepo(String orgName, String name, boolean reinitialize) throws IdRepoException, SSOException {
orgName = DNUtils.normalizeDN(orgName);
synchronized (idrepoPlugins) {
// Clear IdRepo plugins first since other threads should
// not access it during shutdown
clearReadOnlyPlugins(orgName);
Map idrepos = (Map) idrepoPlugins.get(orgName);
if (idrepos != null && !idrepos.isEmpty()) {
// Iterate through the plugins
for (Iterator items = idrepos.keySet().iterator(); items.hasNext(); ) {
String iname = items.next().toString();
if (iname.equalsIgnoreCase(name)) {
IdRepo repo = (IdRepo) idrepos.get(iname);
// Shutting down idrepo
if (debug.messageEnabled()) {
debug.message("IdRepoPluginsCache.removeIdRepo" + " for OrgName: " + orgName + " Repo Name: " + name);
}
// Remove from cache first
idrepos.remove(iname);
ShutdownIdRepoPlugin shutdownrepo = new ShutdownIdRepoPlugin(repo);
// Provide a delay of 500ms for existing operations
// to complete. the delay is in the forked thread.
SMSThreadPool.scheduleTask(shutdownrepo);
break;
}
}
if (reinitialize) {
// Adding plugin back provides the atomic operation
// for the caller. Else, client will get No-plugins
// configured exception.
// Add the plugin back to the cache
addIdRepo(orgName, name);
}
}
}
}
use of com.sun.identity.idm.IdRepo in project OpenAM by OpenRock.
the class IdRepoPluginsCache method getAMRepoPlugin.
protected IdRepo getAMRepoPlugin(String orgName) throws SSOException, IdRepoException {
IdRepo pluginClass = null;
try {
if (debug.messageEnabled()) {
debug.message("AMSDK repo being initialized");
}
Class thisClass = Thread.currentThread().getContextClassLoader().loadClass(IdConstants.AMSDK_PLUGIN);
pluginClass = (IdRepo) thisClass.newInstance();
Map amsdkConfig = new HashMap();
Set vals = new HashSet();
vals.add(DNMapper.realmNameToAMSDKName(orgName));
amsdkConfig.put("amSDKOrgName", vals);
pluginClass.initialize(amsdkConfig);
} catch (Exception e) {
debug.error("IdRepoPluginsCache.getAMRepoPlugin: " + "Unable to instantiate plugin for Org: " + orgName, e);
}
if (pluginClass != null) {
// Add listener to this plugin class
Map listenerConfig = new HashMap();
listenerConfig.put("realm", orgName);
listenerConfig.put("amsdk", "true");
IdRepoListener lter = new IdRepoListener();
lter.setConfigMap(listenerConfig);
pluginClass.addListener(getAdminToken(), lter);
}
return pluginClass;
}
use of com.sun.identity.idm.IdRepo in project OpenAM by OpenRock.
the class IdRepoPluginsCache method getSpecialRepoPlugin.
// Internal repos
private IdRepo getSpecialRepoPlugin() throws SSOException, IdRepoException {
// Valid only for root realm
IdRepo pluginClass = null;
try {
if (debug.messageEnabled()) {
debug.message("Special repo being initialized");
}
Class thisClass = Thread.currentThread().getContextClassLoader().loadClass(IdConstants.SPECIAL_PLUGIN);
pluginClass = (IdRepo) thisClass.newInstance();
HashMap config = new HashMap(2);
config.put("realm", ServiceManager.getBaseDN());
pluginClass.initialize(config);
IdRepoListener lter = new IdRepoListener();
lter.setConfigMap(config);
pluginClass.addListener(getAdminToken(), lter);
} catch (Exception e) {
debug.error("IdRepoPluginsCache.getSpecialRepoPlugin: " + "Unable to init plugin: " + IdConstants.SPECIAL_PLUGIN, e);
}
return pluginClass;
}
Aggregations