use of com.sun.identity.idm.IdRepoException 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.IdRepoException 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.IdRepoException 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);
}
use of com.sun.identity.idm.IdRepoException in project OpenAM by OpenRock.
the class IdServicesImpl method createRealmIdentity.
private AMIdentity createRealmIdentity(SSOToken token, IdType type, String name, Map attrMap, String orgName) throws IdRepoException, SSOException {
try {
OrganizationConfigManager orgMgr = new OrganizationConfigManager(token, orgName);
Map<String, Set<String>> newAttrMap = new HashMap<>(attrMap);
if (!newAttrMap.containsKey(IdConstants.ORGANIZATION_STATUS_ATTR)) {
newAttrMap.put(IdConstants.ORGANIZATION_STATUS_ATTR, CollectionUtils.asSet("Active"));
}
Map serviceAttrsMap = new HashMap();
serviceAttrsMap.put(IdConstants.REPO_SERVICE, newAttrMap);
orgMgr.createSubOrganization(name, serviceAttrsMap);
return getSubRealmIdentity(token, name, orgName);
} catch (SMSException sme) {
DEBUG.error("AMIdentityRepository.createIdentity() - " + "Error occurred while creating " + type.getName() + ":" + name, sme);
throw new IdRepoException(sme.getMessage());
}
}
use of com.sun.identity.idm.IdRepoException in project OpenAM by OpenRock.
the class IdRepoPluginsCache method constructIdRepoPlugin.
/**
* Constructs IdRepo plugin object and returns.
*/
private IdRepo constructIdRepoPlugin(String orgName, Map configMap, String name) throws IdRepoException, SSOException {
IdRepo answer = null;
if (debug.messageEnabled()) {
debug.message("IdRepoPluginsCache.constructIdRepoPlugin: config=" + configMap.get("sunIdRepoClass"));
}
if (configMap == null || configMap.isEmpty()) {
if (debug.warningEnabled()) {
debug.warning("IdRepoPluginsCache.constructIdRepoPlugin: " + "Cannot construct with empty config data");
}
return (null);
}
Set vals = (Set) configMap.get(IdConstants.ID_REPO);
if ((vals != null) && !vals.isEmpty()) {
String className = (String) vals.iterator().next();
Class thisClass;
try {
thisClass = Thread.currentThread().getContextClassLoader().loadClass(className);
answer = (IdRepo) thisClass.newInstance();
} catch (Throwable ex) {
debug.error("IdRepoPluginsCached.constructIdRepoPlugin " + " OrgName: " + orgName + " ConfigMap: " + configMap, ex);
throw (new IdRepoException(ex.getMessage()));
}
answer.initialize(configMap);
// Add listener to this plugin class!
Map listenerConfig = new HashMap();
listenerConfig.put("realm", orgName);
listenerConfig.put("plugin-name", name);
if (className.equals(IdConstants.AMSDK_PLUGIN)) {
listenerConfig.put("amsdk", "true");
}
IdRepoListener listener = new IdRepoListener();
listener.setConfigMap(listenerConfig);
answer.addListener(getAdminToken(), listener);
}
return (answer);
}
Aggregations