Search in sources :

Example 16 with DataStoreProviderException

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());
    }
}
Also used : DataStoreProviderException(com.sun.identity.plugin.datastore.DataStoreProviderException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 17 with DataStoreProviderException

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;
}
Also used : DataStoreProviderException(com.sun.identity.plugin.datastore.DataStoreProviderException) Set(java.util.Set) DataStoreProvider(com.sun.identity.plugin.datastore.DataStoreProvider) SessionException(com.sun.identity.plugin.session.SessionException) SessionProvider(com.sun.identity.plugin.session.SessionProvider)

Example 18 with DataStoreProviderException

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);
    }
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) DataStoreProviderException(com.sun.identity.plugin.datastore.DataStoreProviderException) HashSet(java.util.HashSet) Set(java.util.Set) Iterator(java.util.Iterator)

Example 19 with DataStoreProviderException

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);
    }
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) DataStoreProviderException(com.sun.identity.plugin.datastore.DataStoreProviderException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Iterator(java.util.Iterator) Map(java.util.Map) HashMap(java.util.HashMap) NameIDInfoKey(com.sun.identity.saml2.common.NameIDInfoKey) HashSet(java.util.HashSet)

Example 20 with DataStoreProviderException

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());
    }
}
Also used : DataStoreProviderException(com.sun.identity.plugin.datastore.DataStoreProviderException) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DataStoreProviderException (com.sun.identity.plugin.datastore.DataStoreProviderException)35 Set (java.util.Set)26 HashSet (java.util.HashSet)20 Iterator (java.util.Iterator)18 Map (java.util.Map)15 HashMap (java.util.HashMap)12 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)9 SessionException (com.sun.identity.plugin.session.SessionException)8 ArrayList (java.util.ArrayList)8 List (java.util.List)7 SSOException (com.iplanet.sso.SSOException)6 AMIdentity (com.sun.identity.idm.AMIdentity)6 IdRepoException (com.sun.identity.idm.IdRepoException)6 SSOToken (com.iplanet.sso.SSOToken)5 DataStoreProvider (com.sun.identity.plugin.datastore.DataStoreProvider)5 EncryptedID (com.sun.identity.saml2.assertion.EncryptedID)5 NameID (com.sun.identity.saml2.assertion.NameID)5 SessionProvider (com.sun.identity.plugin.session.SessionProvider)4 SAMLException (com.sun.identity.saml.common.SAMLException)4 NameIdentifier (com.sun.identity.saml.assertion.NameIdentifier)3