Search in sources :

Example 11 with DataStoreProviderException

use of com.sun.identity.plugin.datastore.DataStoreProviderException in project OpenAM by OpenRock.

the class FSAccountManager method hasAnyActiveFederation.

/**
     * Returns true If Any Active federation is found where idpRole is true
     * means local deployment worked as SP in that federation and federation
     * is still Active.
     * @param userID user id
     * @return true If Any Active federation is found where idpRole is true
     *  means local deployment worked as SP in that federation and 
     *  federation is still Active.
     * @throws FSAccountMgmtException - If Account fed info is not found for 
     *  given user.
     */
public boolean hasAnyActiveFederation(String userID) throws FSAccountMgmtException {
    FSUtils.debug.message("FSAccountManager.hasAnyActiveFederation():called");
    if (userID == null) {
        FSUtils.debug.error("FSAccountManager.hasAnyActiveFederation():" + "Invalid Argument : user ID is NULL");
        throw new FSAccountMgmtException(IFSConstants.NULL_USER_DN, null);
    }
    Set existFedInfoSet = null;
    try {
        existFedInfoSet = provider.getAttribute(userID, FSAccountUtils.USER_FED_INFO_ATTR);
    } catch (DataStoreProviderException ame) {
        FSUtils.debug.error("FSAccountManager.hasAnyActiveFederation():Exception: ", ame);
        throw new FSAccountMgmtException(ame.getMessage());
    }
    if (existFedInfoSet != null && !existFedInfoSet.isEmpty()) {
        Iterator i = existFedInfoSet.iterator();
        String existFedInfoStr = "";
        while (i.hasNext()) {
            existFedInfoStr = (String) i.next();
            FSAccountFedInfo afi = FSAccountUtils.stringToObject(existFedInfoStr);
            // Means local deployment worked as SP in that federation.
            if (afi.isFedStatusActive() && afi.isRoleIDP()) {
                return true;
            }
        }
        return false;
    }
    // since all federtation info will be cleaned up once terminated
    return false;
}
Also used : DataStoreProviderException(com.sun.identity.plugin.datastore.DataStoreProviderException) Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator)

Example 12 with DataStoreProviderException

use of com.sun.identity.plugin.datastore.DataStoreProviderException in project OpenAM by OpenRock.

the class FSAccountManager method isFederationActive.

/**
     * Returns true/false if Account's federation Status is Active / Inactive
     * for given providerID.
     * @param userID user identity
     * @param providerID Remote ProviderID value.
     * @return true/false if Account's federation Status is Active / Inactive
     *  for given providerID.
     * @throws FSAccountMgmtException - If Account fed info is not found for 
     *  given user & given ProviderID.
     */
public boolean isFederationActive(String userID, String providerID) throws FSAccountMgmtException {
    FSUtils.debug.message("FSAccountManager.isFederationActive() : called");
    if (userID == null) {
        FSUtils.debug.error("FSAccountManager.isFederationActive():" + "Invalid Argument : user ID is NULL");
        throw new FSAccountMgmtException(IFSConstants.NULL_USER_DN, null);
    }
    if ((providerID == null) || (providerID.length() <= 0)) {
        FSUtils.debug.error("FSAccountManager.isFederationActive() : " + "Invalid Argument : ProviderID is NULL");
        throw new FSAccountMgmtException(IFSConstants.NULL_PROVIDER_ID, null);
    }
    Set existFedInfoSet = null;
    try {
        existFedInfoSet = provider.getAttribute(userID, FSAccountUtils.USER_FED_INFO_ATTR);
    } catch (DataStoreProviderException ame) {
        FSUtils.debug.error("FSAccountManager.isFederationActive() :Exception: ", ame);
        throw new FSAccountMgmtException(ame.getMessage());
    }
    if (existFedInfoSet != null && !existFedInfoSet.isEmpty()) {
        String filter = FSAccountUtils.createFilter(providerID);
        Iterator i = existFedInfoSet.iterator();
        while (i.hasNext()) {
            String existFedInfoStr = (String) i.next();
            if (existFedInfoStr.indexOf(filter) >= 0) {
                // accountFedInfo exists for given providerID
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("FSAccountManager.isFederationActive(): " + "value found: " + existFedInfoStr);
                }
                FSAccountFedInfo afi = FSAccountUtils.stringToObject(existFedInfoStr);
                if (afi.isFedStatusActive()) {
                    return true;
                }
                return false;
            }
        }
    }
    FSUtils.debug.error("FSAccountManager.isFederationActive() : " + "Account Federation Info not Found");
    throw new FSAccountMgmtException(IFSConstants.ACT_FED_INFO_NOT_FOUND, null);
}
Also used : DataStoreProviderException(com.sun.identity.plugin.datastore.DataStoreProviderException) Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator)

Example 13 with DataStoreProviderException

use of com.sun.identity.plugin.datastore.DataStoreProviderException in project OpenAM by OpenRock.

the class FSAccountManager method removeAccountFedInfoKey.

/**
     * Removes Account's federation Info Key in data store.
     * @param userID user id
     * @param fedInfoKey Account Fed Info Key which contains NameSpace
     * & opaque handle sent/received, which will be removed.
     * @throws FSAccountMgmtException if illegal argument passed.
     */
public void removeAccountFedInfoKey(String userID, FSAccountFedInfoKey fedInfoKey) throws FSAccountMgmtException {
    FSUtils.debug.message("FSAccountManager.removeAccountFedInfoKey():called");
    if (userID == null) {
        FSUtils.debug.error("FSAccountManager.removeAccountFedInfoKey():" + "Invalid Argument : user ID is NULL");
        throw new FSAccountMgmtException(IFSConstants.NULL_USER_DN, null);
    }
    if (fedInfoKey == null) {
        FSUtils.debug.error("FSAccountManager.removeAccountFedInfoKey():" + "Invalid Argument : FedInfo key is NULL");
        throw new FSAccountMgmtException(IFSConstants.NULL_FED_INFO_KEY_OBJECT, null);
    }
    try {
        Map attrMap = new HashMap();
        Set existFedInfoKeySet = provider.getAttribute(userID, FSAccountUtils.USER_FED_INFO_KEY_ATTR);
        if (existFedInfoKeySet != null && !existFedInfoKeySet.isEmpty()) {
            Iterator i = existFedInfoKeySet.iterator();
            String existFedInfoKeyStr = "";
            String filter = FSAccountUtils.createFilter(fedInfoKey);
            while (i.hasNext()) {
                existFedInfoKeyStr = (String) i.next();
                if (existFedInfoKeyStr.indexOf(filter) >= 0) {
                    if (FSUtils.debug.messageEnabled()) {
                        FSUtils.debug.message("FSAccountManager.removeAccountFedInfoKey():" + "Account Fed Info Key Exists, will remove it");
                    }
                    existFedInfoKeySet.remove(existFedInfoKeyStr);
                    attrMap.put(FSAccountUtils.USER_FED_INFO_KEY_ATTR, existFedInfoKeySet);
                    provider.setAttributes(userID, attrMap);
                    break;
                }
            }
        }
    } catch (DataStoreProviderException ame) {
        FSUtils.debug.error("FSAccountManager.removeAccountFedInfoKey():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)

Example 14 with DataStoreProviderException

use of com.sun.identity.plugin.datastore.DataStoreProviderException in project OpenAM by OpenRock.

the class AccountUtils method removeAccountFederation.

/**
     * Removes the account federation of a user.
     * @param info <code>NameIDInfo</code> object. 
     * @param userID user identifie for which the account federation needs to
     *               be removed.
     * @return true if the account federation is removed successfully.
     * @exception SAML2Exception if any failure.
     */
public static boolean removeAccountFederation(NameIDInfo info, String userID) throws SAML2Exception {
    SAML2Utils.debug.message("AccountUtils.removeAccountFederation:");
    if (info == null) {
        throw new SAML2Exception(SAML2Utils.bundle.getString("nullNameIDInfo"));
    }
    if (userID == null) {
        throw new SAML2Exception(SAML2Utils.bundle.getString("nullUserID"));
    }
    try {
        Set existingFed = SAML2Utils.getDataStoreProvider().getAttribute(userID, getNameIDInfoAttribute());
        Set existingInfoKey = SAML2Utils.getDataStoreProvider().getAttribute(userID, getNameIDInfoKeyAttribute());
        if (existingFed == null || existingFed.isEmpty()) {
            if (SAML2Utils.debug.messageEnabled()) {
                SAML2Utils.debug.message("AccountUtils.removeAccount" + "Federation: user does not have account federation infos.");
            }
            return false;
        }
        String infoValue = info.toValueString();
        String infoKeyValue = info.getNameIDInfoKey().toValueString();
        if (SAML2Utils.debug.messageEnabled()) {
            SAML2Utils.debug.message("AccountUtils.removeAccount" + "Federation: info to be removed:" + infoValue + "user=" + userID + "infoKeyValue = " + infoKeyValue);
        }
        if (existingFed.contains(infoValue)) {
            existingFed.remove(infoValue);
            if (existingInfoKey != null && existingInfoKey.contains(infoKeyValue)) {
                existingInfoKey.remove(infoKeyValue);
            }
            Map map = new HashMap();
            map.put(getNameIDInfoAttribute(), existingFed);
            map.put(getNameIDInfoKeyAttribute(), existingInfoKey);
            SAML2Utils.getDataStoreProvider().setAttributes(userID, map);
            return true;
        }
        if (SAML2Utils.debug.messageEnabled()) {
            SAML2Utils.debug.message("AccountUtils.removeAccount" + "Federation: account federation info not found.");
        }
        return false;
    } catch (DataStoreProviderException dse) {
        SAML2Utils.debug.error("SAML2Utils.removeAccountFederation: " + "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) Map(java.util.Map) HashMap(java.util.HashMap)

Example 15 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 SAML2Exception if account federation retrieval is failed.
     */
public static NameIDInfo getAccountFederation(String userID, String hostEntityID, String remoteEntityID) throws SAML2Exception {
    SAML2Utils.debug.message("AccountUtils.getAccountFederation:");
    if (userID == null) {
        throw new SAML2Exception(SAML2Utils.bundle.getString("nullUserID"));
    }
    if (hostEntityID == null) {
        throw new SAML2Exception(SAML2Utils.bundle.getString("nullHostEntityID"));
    }
    if (remoteEntityID == null) {
        throw new SAML2Exception(SAML2Utils.bundle.getString("nullRemoteEntityID"));
    }
    try {
        Set set = SAML2Utils.getDataStoreProvider().getAttribute(userID, getNameIDInfoAttribute());
        if (set == null || set.isEmpty()) {
            if (SAML2Utils.debug.messageEnabled()) {
                SAML2Utils.debug.message("AccountUtils.getAccount" + "Federation : user does not have any account federations.");
            }
            return null;
        }
        String filter = hostEntityID + DELIM + remoteEntityID + DELIM;
        if (SAML2Utils.debug.messageEnabled()) {
            SAML2Utils.debug.message("AccountUtils.getAccountFederation: " + " 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 (SAML2Utils.debug.messageEnabled()) {
                SAML2Utils.debug.message("AccountUtils.getAccount" + "Federation : user does not have account federation " + " corresponding to =" + filter);
            }
            return null;
        }
        return NameIDInfo.parse(info);
    } catch (DataStoreProviderException dse) {
        SAML2Utils.debug.error("AccountUtils.readAccountFederation" + "Info: DataStoreProviderException", dse);
        throw new SAML2Exception(dse.getMessage());
    }
}
Also used : DataStoreProviderException(com.sun.identity.plugin.datastore.DataStoreProviderException) HashSet(java.util.HashSet) Set(java.util.Set) Iterator(java.util.Iterator)

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