Search in sources :

Example 6 with AffiliationDescriptorType

use of com.sun.identity.saml2.jaxb.metadata.AffiliationDescriptorType in project OpenAM by OpenRock.

the class SAML2Utils method getNameIDKeyMap.

/**
     * Returns the <code>NameIDInfoKey</code> key value pair that can
     * be used for searching the user.
     *
     * @param nameID         <code>NameID</code> object.
     * @param hostEntityID   hosted <code>EntityID</code>.
     * @param remoteEntityID remote <code>EntityID</code>.
     * @param hostEntityRole the role of hosted entity.
     * @throws <code>SAML2Exception</code> if any failure.
     */
public static Map getNameIDKeyMap(final NameID nameID, final String hostEntityID, final String remoteEntityID, final String realm, final String hostEntityRole) throws SAML2Exception {
    if (nameID == null) {
        throw new SAML2Exception(bundle.getString("nullNameID"));
    }
    NameIDInfoKey infoKey = null;
    String affiliationID = nameID.getSPNameQualifier();
    if (affiliationID != null && !affiliationID.isEmpty()) {
        AffiliationDescriptorType affiDesc = saml2MetaManager.getAffiliationDescriptor(realm, affiliationID);
        if (affiDesc == null) {
            infoKey = new NameIDInfoKey(nameID.getValue(), hostEntityID, remoteEntityID);
        } else {
            if (SAML2Constants.SP_ROLE.equals(hostEntityRole)) {
                if (!affiDesc.getAffiliateMember().contains(hostEntityID)) {
                    throw new SAML2Exception(SAML2Utils.bundle.getString("spNotAffiliationMember"));
                }
                infoKey = new NameIDInfoKey(nameID.getValue(), affiliationID, remoteEntityID);
            } else {
                if (!affiDesc.getAffiliateMember().contains(remoteEntityID)) {
                    throw new SAML2Exception(SAML2Utils.bundle.getString("spNotAffiliationMember"));
                }
                infoKey = new NameIDInfoKey(nameID.getValue(), hostEntityID, affiliationID);
            }
        }
    } else {
        infoKey = new NameIDInfoKey(nameID.getValue(), hostEntityID, remoteEntityID);
    }
    HashSet set = new HashSet();
    set.add(infoKey.toValueString());
    Map keyMap = new HashMap();
    keyMap.put(AccountUtils.getNameIDInfoKeyAttribute(), set);
    if (debug.messageEnabled()) {
        debug.message("SAML2Utils.getNameIDKeyMap: " + keyMap);
    }
    return keyMap;
}
Also used : HashMap(java.util.HashMap) AffiliationDescriptorType(com.sun.identity.saml2.jaxb.metadata.AffiliationDescriptorType) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 7 with AffiliationDescriptorType

use of com.sun.identity.saml2.jaxb.metadata.AffiliationDescriptorType in project OpenAM by OpenRock.

the class SPACSUtils method writeFedData.

private static void writeFedData(NameID nameId, String spEntityId, String realm, SAML2MetaManager metaManager, String idpEntityId, String userName, String storageKey) throws SAML2Exception {
    final NameIDInfo info;
    final String affiID = nameId.getSPNameQualifier();
    boolean isDualRole = SAML2Utils.isDualRole(spEntityId, realm);
    AffiliationDescriptorType affiDesc = null;
    if (affiID != null && !affiID.isEmpty()) {
        affiDesc = metaManager.getAffiliationDescriptor(realm, affiID);
    }
    if (affiDesc != null) {
        if (!affiDesc.getAffiliateMember().contains(spEntityId)) {
            throw new SAML2Exception("Unable to locate SP Entity ID in the affiliate descriptor.");
        }
        if (isDualRole) {
            info = new NameIDInfo(affiID, idpEntityId, nameId, SAML2Constants.DUAL_ROLE, true);
        } else {
            info = new NameIDInfo(affiID, idpEntityId, nameId, SAML2Constants.SP_ROLE, true);
        }
    } else {
        if (isDualRole) {
            info = new NameIDInfo(spEntityId, idpEntityId, nameId, SAML2Constants.DUAL_ROLE, false);
        } else {
            info = new NameIDInfo(spEntityId, idpEntityId, nameId, SAML2Constants.SP_ROLE, false);
        }
    }
    // write fed info into data store
    SPCache.fedAccountHash.put(storageKey, "true");
    AccountUtils.setAccountFederation(info, userName);
}
Also used : SAML2Exception(com.sun.identity.saml2.common.SAML2Exception) NameIDInfo(com.sun.identity.saml2.common.NameIDInfo) AffiliationDescriptorType(com.sun.identity.saml2.jaxb.metadata.AffiliationDescriptorType)

Aggregations

AffiliationDescriptorType (com.sun.identity.saml2.jaxb.metadata.AffiliationDescriptorType)7 SAML2Exception (com.sun.identity.saml2.common.SAML2Exception)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 NameIDInfo (com.sun.identity.saml2.common.NameIDInfo)3 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)2 SessionException (com.sun.identity.plugin.session.SessionException)2 NameID (com.sun.identity.saml2.assertion.NameID)2 Subject (com.sun.identity.saml2.assertion.Subject)2 SPSSODescriptorElement (com.sun.identity.saml2.jaxb.metadata.SPSSODescriptorElement)2 SAML2MetaManager (com.sun.identity.saml2.meta.SAML2MetaManager)2 NameIDPolicy (com.sun.identity.saml2.protocol.NameIDPolicy)2 Iterator (java.util.Iterator)2 DataStoreProviderException (com.sun.identity.plugin.datastore.DataStoreProviderException)1 SessionProvider (com.sun.identity.plugin.session.SessionProvider)1 Assertion (com.sun.identity.saml2.assertion.Assertion)1 EncryptedID (com.sun.identity.saml2.assertion.EncryptedID)1