use of com.sun.identity.plugin.datastore.DataStoreProviderException in project OpenAM by OpenRock.
the class AccountUtils method setAccountFederation.
/**
* Sets the account federation information to the datastore for a user.
* @param info <code>NameIDInfo</code> object to be set.
* @param userID user identifier for which the account federation to be set.
* @exception SAML2Exception if any failure.
*/
public static void setAccountFederation(NameIDInfo info, String userID) throws SAML2Exception {
SAML2Utils.debug.message("AccountUtils.setAccountFederation:");
if (info == null) {
throw new SAML2Exception(SAML2Utils.bundle.getString("nullNameIDInfo"));
}
if (userID == null) {
throw new SAML2Exception(SAML2Utils.bundle.getString("nullUserID"));
}
NameIDInfoKey infoKey = new NameIDInfoKey(info.getNameIDValue(), info.getHostEntityID(), info.getRemoteEntityID());
if (SAML2Utils.debug.messageEnabled()) {
SAML2Utils.debug.message("AccountUtils.setAccountFederation: " + "info to be set:" + info.toValueString() + "," + "infoKey to be set:" + infoKey.toValueString());
}
String filter = info.getHostEntityID() + DELIM + info.getRemoteEntityID() + DELIM;
try {
String nameIDInfoAttr = getNameIDInfoAttribute();
String nameIDInfoKeyAttr = getNameIDInfoKeyAttribute();
Set set = new HashSet();
set.add(nameIDInfoAttr);
set.add(nameIDInfoKeyAttr);
Map map = new HashMap();
Map existMap = SAML2Utils.getDataStoreProvider().getAttributes(userID, set);
if (existMap == null || existMap.isEmpty()) {
map.putAll(convertToAttributes(info, infoKey));
} else {
Set set1 = (Set) existMap.get(nameIDInfoAttr);
if (set1 != null) {
for (Iterator iter1 = set1.iterator(); iter1.hasNext(); ) {
String value = (String) iter1.next();
if (value.startsWith(filter)) {
iter1.remove();
}
}
} else {
set1 = new HashSet();
}
set1.add(info.toValueString());
map.put(nameIDInfoAttr, set1);
Set set2 = (Set) existMap.get(nameIDInfoKeyAttr);
if (set2 != null) {
for (Iterator iter2 = set2.iterator(); iter2.hasNext(); ) {
String value = (String) iter2.next();
if (value.startsWith(filter)) {
iter2.remove();
}
}
} else {
set2 = new HashSet();
}
set2.add(infoKey.toValueString());
map.put(nameIDInfoKeyAttr, set2);
}
if (SAML2Utils.debug.messageEnabled()) {
SAML2Utils.debug.message("AccountUtils.setAccountFederation: " + " set fedinfo " + map + " userID = " + userID);
}
SAML2Utils.getDataStoreProvider().setAttributes(userID, map);
} catch (DataStoreProviderException dse) {
SAML2Utils.debug.error("SAML2Utils.setAccountFederation: " + "DataStoreProviderException", dse);
throw new SAML2Exception(dse.getMessage());
}
}
use of com.sun.identity.plugin.datastore.DataStoreProviderException in project OpenAM by OpenRock.
the class FSDefaultAttributePlugin method getAttributeValue.
private String getAttributeValue(Object token, String attrName) {
if (attrName == null) {
FSUtils.debug.error("FSDefaultAttributePlugin.getAttribute" + "Value: attribute Name is null. Check the attribute map");
return null;
}
try {
SessionProvider sessionProvider = SessionManager.getProvider();
String userID = sessionProvider.getPrincipalName(token);
DataStoreProvider dsProvider = DataStoreProviderManager.getInstance().getDataStoreProvider(IFSConstants.IDFF);
Set attrValues = dsProvider.getAttribute(userID, attrName);
if (attrValues == null || attrValues.isEmpty()) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSDefaultAttributePlugin.getAttribute" + "Value: values not found for : " + attrName);
}
return null;
}
return (String) attrValues.iterator().next();
} catch (SessionException se) {
FSUtils.debug.error("FSDefaultAttributePlugin.getAttributeValue: exception:", se);
} catch (DataStoreProviderException dspe) {
FSUtils.debug.error("FSDefaultAttributePlugin.getAttributeValue: exception: ", dspe);
}
return null;
}
use of com.sun.identity.plugin.datastore.DataStoreProviderException in project OpenAM by OpenRock.
the class AccountUtils method getAccountFederation.
/**
* Returns the account federation information of a user for the given
* identity provider and a service provider.
* @param userID user id for which account federation needs to be returned.
* @param hostEntityID <code>EntityID</code> of the hosted entity.
* @param remoteEntityID <code>EntityID</code> of the remote entity.
* @return the account federation info object.
* null if the account federation does not exist.
* @exception WSFederationException if account federation retrieval failed.
*/
public static NameIDInfo getAccountFederation(String userID, String hostEntityID, String remoteEntityID) throws WSFederationException {
String classMethod = "AccountUtils.getAccountFederation: ";
if (debug.messageEnabled()) {
debug.message(classMethod);
}
if (userID == null) {
throw new WSFederationException(WSFederationUtils.bundle.getString("nullUserID"));
}
if (hostEntityID == null) {
throw new WSFederationException(WSFederationUtils.bundle.getString("nullHostEntityID"));
}
if (remoteEntityID == null) {
throw new WSFederationException(WSFederationUtils.bundle.getString("nullRemoteEntityID"));
}
try {
Set set = WSFederationUtils.dsProvider.getAttribute(userID, getNameIDInfoAttribute());
if (set == null || set.isEmpty()) {
if (WSFederationUtils.debug.messageEnabled()) {
WSFederationUtils.debug.message(classMethod + "user does not have any account federations.");
}
return null;
}
String filter = hostEntityID + DELIM + remoteEntityID + DELIM;
if (WSFederationUtils.debug.messageEnabled()) {
WSFederationUtils.debug.message(classMethod + " filter = " + filter + " userID = " + userID);
}
String info = null;
for (Iterator iter = set.iterator(); iter.hasNext(); ) {
String value = (String) iter.next();
if (value.startsWith(filter)) {
info = value;
break;
}
}
if (info == null) {
if (WSFederationUtils.debug.messageEnabled()) {
WSFederationUtils.debug.message(classMethod + "user does not have account federation " + " corresponding to =" + filter);
}
return null;
}
return NameIDInfo.parse(info);
} catch (DataStoreProviderException dse) {
WSFederationUtils.debug.error(classMethod + "Info: DataStoreProviderException", dse);
throw new WSFederationException(dse);
} catch (SAML2Exception se) {
WSFederationUtils.debug.error(classMethod + "Info: SAML2Exception", se);
throw new WSFederationException(se);
}
}
use of com.sun.identity.plugin.datastore.DataStoreProviderException in project OpenAM by OpenRock.
the class AccountUtils method setAccountFederation.
/**
* Sets the account federation information in the datastore for a user.
* @param info <code>NameIDInfo</code> object to be set.
* @param userID user identifier for which the account federation to be set.
* @exception WSFederationException if any failure.
*/
public static void setAccountFederation(NameIDInfo info, String userID) throws WSFederationException {
String classMethod = "AccountUtils.setAccountFederation: ";
WSFederationUtils.debug.message(classMethod);
if (info == null) {
throw new WSFederationException(WSFederationUtils.bundle.getString("nullNameIDInfo"));
}
if (userID == null) {
throw new WSFederationException(WSFederationUtils.bundle.getString("nullUserID"));
}
try {
NameIDInfoKey infoKey = new NameIDInfoKey(info.getNameIDValue(), info.getHostEntityID(), info.getRemoteEntityID());
if (WSFederationUtils.debug.messageEnabled()) {
WSFederationUtils.debug.message(classMethod + "info to be set:" + info.toValueString() + "," + "infoKey to be set:" + infoKey.toValueString());
}
String filter = info.getHostEntityID() + DELIM + info.getRemoteEntityID() + DELIM;
String nameIDInfoAttr = getNameIDInfoAttribute();
String nameIDInfoKeyAttr = getNameIDInfoKeyAttribute();
Set set = new HashSet();
set.add(nameIDInfoAttr);
set.add(nameIDInfoKeyAttr);
Map map = new HashMap();
Map existMap = WSFederationUtils.dsProvider.getAttributes(userID, set);
if (existMap == null || existMap.isEmpty()) {
Set set1 = new HashSet();
set1.add(infoKey.toValueString());
map.put(nameIDInfoKeyAttr, set1);
Set set2 = new HashSet();
set2.add(info.toValueString());
map.put(nameIDInfoAttr, set2);
} else {
Set set1 = (Set) existMap.get(nameIDInfoAttr);
if (set1 != null) {
for (Iterator iter1 = set1.iterator(); iter1.hasNext(); ) {
String value = (String) iter1.next();
if (value.startsWith(filter)) {
iter1.remove();
}
}
} else {
set1 = new HashSet();
}
set1.add(info.toValueString());
map.put(nameIDInfoAttr, set1);
Set set2 = (Set) existMap.get(nameIDInfoKeyAttr);
if (set2 != null) {
for (Iterator iter2 = set2.iterator(); iter2.hasNext(); ) {
String value = (String) iter2.next();
if (value.startsWith(filter)) {
iter2.remove();
}
}
} else {
set2 = new HashSet();
}
set2.add(infoKey.toValueString());
map.put(nameIDInfoKeyAttr, set2);
}
if (WSFederationUtils.debug.messageEnabled()) {
WSFederationUtils.debug.message(classMethod + " set fedinfo " + map + " userID = " + userID);
}
WSFederationUtils.dsProvider.setAttributes(userID, map);
} catch (DataStoreProviderException dse) {
WSFederationUtils.debug.error(classMethod + "DataStoreProviderException", dse);
throw new WSFederationException(dse);
} catch (SAML2Exception se) {
WSFederationUtils.debug.error(classMethod + "SAML2Exception", se);
throw new WSFederationException(se);
}
}
use of com.sun.identity.plugin.datastore.DataStoreProviderException in project OpenAM by OpenRock.
the class FSAccountManager method removeAccountFedInfo.
/**
* Removes Account's federation Info in data store for given providerID
* in fedInfo object.
* @param userID user id
* @param fedInfoKey Account Fed Info Key which contains NameSpace
* & opaque handle sent/received.
* @param providerID Remote ProviderID value.
* @throws FSAccountMgmtException - If Account fed info is not found for
* given user & given ProviderID.
*/
public void removeAccountFedInfo(String userID, FSAccountFedInfoKey fedInfoKey, String providerID) throws FSAccountMgmtException {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSAccountManager.removeAccountFedInfo(): userID=" + userID + ", infoKey=" + FSAccountUtils.createFilter(fedInfoKey) + ", providerID=" + providerID);
}
if (fedInfoKey == null) {
FSUtils.debug.error("FSAccountManager.removeAccountFedInfo():" + "Invalid Argument : FedInfo key is NULL");
throw new FSAccountMgmtException(IFSConstants.NULL_FED_INFO_KEY_OBJECT, null);
}
if ((providerID == null) || (providerID.length() <= 0)) {
FSUtils.debug.error("FSAccountManager.removeAccountFedInfo():" + "Invalid Argument : providerID is NULL");
throw new FSAccountMgmtException(IFSConstants.NULL_PROVIDER_ID, null);
}
if (userID == null) {
FSUtils.debug.error("FSAccountManager.removeAccountFedInfo():" + "Invalid Argument : user ID is NULL");
throw new FSAccountMgmtException(IFSConstants.NULL_USER_DN, null);
}
try {
Map attrMap = new HashMap();
boolean found = false;
Set existFedInfoKeySet = provider.getAttribute(userID, FSAccountUtils.USER_FED_INFO_KEY_ATTR);
String existFedInfoKeyStr = "";
if (existFedInfoKeySet != null && !existFedInfoKeySet.isEmpty()) {
String filter = FSAccountUtils.createFilter(fedInfoKey);
Iterator i = existFedInfoKeySet.iterator();
while (i.hasNext()) {
existFedInfoKeyStr = (String) i.next();
if (existFedInfoKeyStr.indexOf(filter) >= 0) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSAccountManager.removeAccountFedInfo():" + "Account Fed Info Key Exists, will remove it");
}
existFedInfoKeySet.remove(existFedInfoKeyStr);
attrMap.put(FSAccountUtils.USER_FED_INFO_KEY_ATTR, existFedInfoKeySet);
found = true;
break;
}
}
}
String nameIDValue = fedInfoKey.getName();
Set existFedInfoSet = provider.getAttribute(userID, FSAccountUtils.USER_FED_INFO_ATTR);
if (existFedInfoSet != null && !existFedInfoSet.isEmpty()) {
Iterator i = existFedInfoSet.iterator();
String existFedInfoStr = "";
String filter = FSAccountUtils.createFilter(providerID);
while (i.hasNext()) {
existFedInfoStr = (String) i.next();
if ((existFedInfoStr.indexOf(filter) >= 0) && (existFedInfoStr.indexOf(nameIDValue) >= 0)) {
if (FSUtils.debug.messageEnabled()) {
FSUtils.debug.message("FSAccountManager.removeAccountFedInfo():" + "Account Fed Info Exists, will remove it");
}
existFedInfoSet.remove(existFedInfoStr);
attrMap.put(FSAccountUtils.USER_FED_INFO_ATTR, existFedInfoSet);
found = true;
break;
}
}
}
if (found) {
provider.setAttributes(userID, attrMap);
String[] args = { userID, providerID, existFedInfoKeyStr };
LogUtil.access(Level.INFO, LogUtil.REMOVE_ACCOUNT_FED_INFO, args);
} else {
FSUtils.debug.error("FSAccountManager.removeAccountFedInfo():" + "Account Federation Info not Found");
throw new FSAccountMgmtException(IFSConstants.ACT_FED_INFO_NOT_FOUND, null);
}
} catch (DataStoreProviderException ame) {
FSUtils.debug.error("FSAccountManager.removeAccountFedInfo():Exception:", ame);
throw new FSAccountMgmtException(ame.getMessage());
}
}
Aggregations