use of com.sun.identity.idm.IdRepo in project OpenAM by OpenRock.
the class IdServicesImpl method getMembers.
/*
* (non-Javadoc)
*/
public Set getMembers(SSOToken token, IdType type, String name, String amOrgName, IdType membersType, String amsdkDN) throws IdRepoException, SSOException {
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);
// Get the list of plugins that support the read 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);
}
Iterator it = configuredPluginClasses.iterator();
int noOfSuccess = configuredPluginClasses.size();
Set membersSet = new HashSet();
Set amsdkMembers = new HashSet();
boolean amsdkIncluded = false;
while (it.hasNext()) {
IdRepo idRepo = (IdRepo) it.next();
if (!idRepo.getSupportedTypes().contains(membersType) || idRepo.getClass().getName().equals(IdConstants.SPECIAL_PLUGIN)) {
// IdRepo plugin does not support the idType for
// memberships
noOfSuccess--;
continue;
}
try {
boolean isAMSDK = idRepo.getClass().getName().equals(IdConstants.AMSDK_PLUGIN);
Set members = (isAMSDK && (amsdkDN != null)) ? idRepo.getMembers(token, type, amsdkDN, membersType) : idRepo.getMembers(token, type, name, membersType);
if (isAMSDK) {
amsdkMembers.addAll(members);
amsdkIncluded = true;
} else {
membersSet.add(members);
}
} catch (IdRepoUnsupportedOpException ide) {
if (DEBUG.warningEnabled()) {
DEBUG.warning("IdServicesImpl.getMembers: " + "Unable to read identity members in the following" + " repository " + idRepo.getClass().getName() + " :: " + ide.getMessage());
}
noOfSuccess--;
origEx = (origEx == null) ? ide : origEx;
} catch (IdRepoFatalException idf) {
// fatal ..throw it all the way up
DEBUG.error("IdServicesImpl.getMembers: " + "Fatal Exception ", idf);
throw idf;
} catch (IdRepoException ide) {
if (DEBUG.warningEnabled()) {
DEBUG.warning("IdServicesImpl.getMembers: " + "Unable to read identity members in the following" + " repository " + idRepo.getClass().getName() + " :: " + ide.getMessage());
}
noOfSuccess--;
origEx = (origEx == null) ? ide : origEx;
}
}
if (noOfSuccess == 0) {
if (DEBUG.warningEnabled()) {
DEBUG.warning("IdServicesImpl.getMembers: " + "Unable to get members for identity " + type.getName() + "::" + name + " in any configured data store", origEx);
}
if (origEx != null) {
throw origEx;
} else {
return (Collections.EMPTY_SET);
}
} else {
Set results = combineMembers(token, membersSet, membersType, amOrgName, amsdkIncluded, amsdkMembers);
return results;
}
}
use of com.sun.identity.idm.IdRepo in project OpenAM by OpenRock.
the class IdRepoPluginsCache method getAgentRepoPlugin.
protected IdRepo getAgentRepoPlugin(String orgName) throws SSOException, IdRepoException {
IdRepo pluginClass = null;
try {
if (debug.messageEnabled()) {
debug.message("Agents repo being initialized");
}
Class thisClass = Thread.currentThread().getContextClassLoader().loadClass(IdConstants.AGENTREPO_PLUGIN);
pluginClass = (IdRepo) thisClass.newInstance();
HashMap config = new HashMap(2);
HashSet realmName = new HashSet();
realmName.add(orgName);
config.put("agentsRepoRealmName", realmName);
pluginClass.initialize(config);
} catch (Exception e) {
debug.error("IdRepoPluginsCache.getAgentRepoPlugin: " + "Unable to init plugin: " + IdConstants.AGENTREPO_PLUGIN, e);
}
// Add listener
if (pluginClass != null) {
Map listenerConfig = new HashMap();
listenerConfig.put("realm", orgName);
IdRepoListener lter = new IdRepoListener();
lter.setConfigMap(listenerConfig);
pluginClass.addListener(getAdminToken(), lter);
}
// Retuns the plugin class
return pluginClass;
}
use of com.sun.identity.idm.IdRepo in project OpenAM by OpenRock.
the class IdRepoPluginsCache method getIdRepoPlugins.
protected Set getIdRepoPlugins(String orgName, IdOperation op, IdType type) throws IdRepoException, SSOException {
if (debug.messageEnabled()) {
debug.message("IdRepoPluginsCache.getIdRepoPlugins for " + "OrgName: " + orgName + " Op: " + op + " Type: " + type);
}
String cacheName = DNUtils.normalizeDN(orgName) + op.toString() + type.toString();
Set answer = (Set) readonlyPlugins.get(cacheName);
if ((answer != null) && !answer.isEmpty()) {
return (answer);
}
answer = new OrderedSet();
Set plugins = getIdRepoPlugins(orgName);
if ((plugins != null) && !plugins.isEmpty()) {
for (Iterator items = plugins.iterator(); items.hasNext(); ) {
IdRepo repo = (IdRepo) items.next();
if (repo.getSupportedTypes().contains(type)) {
Set ops = repo.getSupportedOperations(type);
if (ops.contains(op)) {
answer.add(repo);
}
}
}
}
if (debug.messageEnabled()) {
Set ps = new HashSet();
for (Iterator items = answer.iterator(); items.hasNext(); ) {
IdRepo repo = (IdRepo) items.next();
ps.add(repo.getClass().getName());
}
debug.message("IdRepoPluginsCache.getIdRepoPlugins retuned for" + " OrgName: " + orgName + " Op: " + op + " Type: " + type + " Plugins: " + ps);
}
synchronized (idrepoPlugins) {
if (answer != null) {
readonlyPlugins.put(cacheName, answer);
}
}
return (answer);
}
use of com.sun.identity.idm.IdRepo in project OpenAM by OpenRock.
the class IdRepoPluginsCache method getIdRepoPlugins.
protected Set getIdRepoPlugins(String orgName) throws IdRepoException, SSOException {
if (debug.messageEnabled()) {
debug.message("IdRepoPluginsCache.getIdRepoPlugins orgName: " + orgName);
}
// Check the cache
Map orgRepos = null;
orgName = DNUtils.normalizeDN(orgName);
Set readOrgRepos = (Set) readonlyPlugins.get(orgName);
if ((readOrgRepos != null) && !readOrgRepos.isEmpty()) {
return (readOrgRepos);
}
synchronized (idrepoPlugins) {
orgRepos = (Map) idrepoPlugins.get(orgName);
if (orgRepos == null) {
try {
if (debug.messageEnabled()) {
debug.message("IdRepoPluginsCache.getIdRepoPlugins " + "Not in cache for: " + orgName);
}
// Initialize the plugins
orgRepos = new LinkedHashMap();
ServiceConfig sc = idRepoServiceConfigManager.getOrganizationConfig(orgName, null);
if (sc == null) {
// Organization does not exist. Error condition
debug.error("IdRepoPluginsCache.getIdRepoPlugins " + "Org does not exisit: " + orgName);
Object[] args = { orgName };
throw new IdRepoException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.REALM_DOESNT_EXIST, args);
}
Set subConfigNames = sc.getSubConfigNames();
if (debug.messageEnabled()) {
debug.message("IdRepoPluginsCache.getIdRepoPlugins " + "Loading plugins: " + subConfigNames);
}
if (subConfigNames != null && !subConfigNames.isEmpty()) {
for (Iterator items = subConfigNames.iterator(); items.hasNext(); ) {
String idRepoName = (String) items.next();
ServiceConfig reposc = sc.getSubConfig(idRepoName);
if (reposc == null) {
debug.error("IdRepoPluginsCache." + "getIdRepoPlugins SubConfig is null for" + " orgName: " + orgName + " subConfig Name: " + idRepoName);
}
IdRepo repo = constructIdRepoPlugin(orgName, reposc.getAttributesForRead(), idRepoName);
// Add to cache
orgRepos.put(idRepoName, repo);
}
}
// Add internal repos
addInternalRepo(orgRepos, orgName);
idrepoPlugins.put(orgName, orgRepos);
} catch (SMSException ex) {
debug.error("IdRepoPluginsCache.getIdRepoPlugins " + "SMS Exception for orgName: " + orgName, ex);
}
}
// Cache a readonly copy
if (orgRepos != null) {
readOrgRepos = new OrderedSet();
readOrgRepos.addAll(orgRepos.values());
readonlyPlugins.put(orgName, readOrgRepos);
}
}
if (debug.messageEnabled() && (readOrgRepos != null)) {
Set ps = new HashSet();
for (Iterator items = readOrgRepos.iterator(); items.hasNext(); ) {
ps.add(items.next().getClass().getName());
}
debug.message("IdRepoPluginsCache.getIdRepoPlugins retuned for" + " OrgName: " + orgName + " Plugins: " + ps);
}
return (readOrgRepos);
}
use of com.sun.identity.idm.IdRepo in project OpenAM by OpenRock.
the class IdServicesImpl method getAttributes.
/*
* (non-Javadoc)
*/
public Map getAttributes(SSOToken token, IdType type, String name, Set attrNames, String amOrgName, String amsdkDN, boolean isString) throws IdRepoException, SSOException {
IdRepoException origEx = null;
// Check permission first. If allowed then proceed, else the
// checkPermission method throws an "402" exception.
checkPermission(token, amOrgName, name, attrNames, IdOperation.READ, type);
// Get the list of plugins that support the read 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);
}
// Verify if it is an internal/special identity
// to avoid calling other plugins for special users
Set attrMapsSet = new HashSet();
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)) {
attrMapsSet.add(idRepo.getAttributes(token, type, name, attrNames));
return (combineAttrMaps(attrMapsSet, true));
}
}
} catch (Exception e) {
// Ignore and continue
}
}
Iterator it = configuredPluginClasses.iterator();
int noOfSuccess = configuredPluginClasses.size();
IdRepo idRepo;
while (it.hasNext()) {
idRepo = (IdRepo) it.next();
try {
Map cMap = idRepo.getConfiguration();
// do stuff to map attr names.
Set mappedAttributeNames = mapAttributeNames(attrNames, cMap);
Map aMap = null;
if (idRepo.getClass().getName().equals(IdConstants.AMSDK_PLUGIN) && amsdkDN != null) {
if (isString) {
aMap = idRepo.getAttributes(token, type, amsdkDN, mappedAttributeNames);
} else {
aMap = idRepo.getBinaryAttributes(token, type, amsdkDN, mappedAttributeNames);
}
} else {
if (isString) {
aMap = idRepo.getAttributes(token, type, name, mappedAttributeNames);
} else {
aMap = idRepo.getBinaryAttributes(token, type, name, mappedAttributeNames);
}
}
aMap = reverseMapAttributeNames(aMap, cMap);
attrMapsSet.add(aMap);
} catch (IdRepoUnsupportedOpException ide) {
if (DEBUG.warningEnabled()) {
DEBUG.warning("IdServicesImpl.getAttributes: " + "Unable to read identity in the following " + "repository " + idRepo.getClass().getName() + " :: " + ide.getMessage());
}
noOfSuccess--;
origEx = (origEx == null) ? ide : origEx;
} catch (IdRepoFatalException idf) {
// fatal ..throw it all the way up
DEBUG.error("GetAttributes: Fatal Exception ", idf);
throw idf;
} catch (IdRepoException ide) {
if (idRepo != null && DEBUG.warningEnabled()) {
DEBUG.warning("IdServicesImpl.getAttributes: " + "Unable to read 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.getAttributes: " + "Unable to get attributes for identity " + type.getName() + ", " + name + " in any configured data store", origEx);
}
throw origEx;
}
return combineAttrMaps(attrMapsSet, isString);
}
Aggregations