Search in sources :

Example 26 with IDFFMetaException

use of com.sun.identity.federation.meta.IDFFMetaException in project OpenAM by OpenRock.

the class FSDefaultAttributeMapper method getAttributes.

/**
     * Returns the attribute map for the given list of 
     * <code>AttributeStatement</code>s. 
     * @param statements list of <code>AttributeStatements</code>s.
     * @param hostEntityId Hosted provider entity id.
     * @param remoteEntityId Remote provider entity id.
     * @param token Single sign-on session token.
     * @return map of attribute values. The  map will have the key as the
     *             attribute name and the map value is the attribute value
     *             that are passed via the single sign-on assertion.
     */
public Map getAttributes(List statements, String hostEntityId, String remoteEntityId, Object token) {
    Map map = new HashMap();
    if (statements == null || statements.size() == 0) {
        return map;
    }
    Map configMap = null;
    try {
        IDFFMetaManager metaManager = FSUtils.getIDFFMetaManager();
        if (metaManager != null) {
            SPDescriptorConfigElement spConfig = metaManager.getSPDescriptorConfig("/", hostEntityId);
            if (spConfig != null) {
                Map attributes = IDFFMetaUtils.getAttributes(spConfig);
                configMap = FSServiceUtils.parseAttributeConfig((List) attributes.get(IFSConstants.SP_ATTRIBUTE_MAP));
            }
        }
    } catch (IDFFMetaException fme) {
        FSUtils.debug.error("FSDefaultAttributeMapper.getAttributes:" + " Unable to read configuration map.", fme);
        return map;
    }
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSDefaultAttributeMapper.getAttributeMap: Configured map " + configMap);
    }
    for (Iterator iter = statements.iterator(); iter.hasNext(); ) {
        AttributeStatement statement = (AttributeStatement) iter.next();
        List attributes = statement.getAttribute();
        if (attributes == null || attributes.size() == 0) {
            continue;
        }
        Iterator iter1 = attributes.iterator();
        while (iter1.hasNext()) {
            Attribute attribute = (Attribute) iter1.next();
            List values = null;
            try {
                values = attribute.getAttributeValue();
            } catch (SAMLException ex) {
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("FSDefaultAttributeMapper.get" + "Attributes: Exception", ex);
                }
                continue;
            }
            if (values == null || values.size() == 0) {
                continue;
            }
            String attributeName = attribute.getAttributeName();
            if (configMap != null && !configMap.isEmpty()) {
                String realAttrName = (String) configMap.get(attributeName);
                if (realAttrName != null && realAttrName.length() > 0) {
                    attributeName = realAttrName;
                }
            }
            //Retrieve the first only one.
            String valueString = XMLUtils.getElementValue((Element) values.get(0));
            if (valueString != null && valueString.length() > 0) {
                map.put(attributeName, valueString);
            }
        }
    }
    return map;
}
Also used : HashMap(java.util.HashMap) Attribute(com.sun.identity.saml.assertion.Attribute) IDFFMetaManager(com.sun.identity.federation.meta.IDFFMetaManager) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) AttributeStatement(com.sun.identity.saml.assertion.AttributeStatement) SPDescriptorConfigElement(com.sun.identity.federation.jaxb.entityconfig.SPDescriptorConfigElement) Iterator(java.util.Iterator) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SAMLException(com.sun.identity.saml.common.SAMLException)

Example 27 with IDFFMetaException

use of com.sun.identity.federation.meta.IDFFMetaException in project OpenAM by OpenRock.

the class FSDefaultAttributePlugin method getAttributeStatements.

/**
     * Returns list of <code>AttributeStatement</code>s by using attribute
     * map defined in the configuration.
     * @param realm The realm under which the entity resides.
     * @param hostEntityId Hosted identity provider entity id.
     * @param remoteEntityID Remote provider's entity id
     * @param subject Subject subject of the authenticated principal.
     * @param token user's session.
     * @return list of SAML <code>AttributeStatement<code>s.
     */
public List getAttributeStatements(String realm, String hostEntityId, String remoteEntityID, FSSubject subject, Object token) {
    FSUtils.debug.message("FSDefaultAttributePlugin.getAttributeStatements");
    Map attributeMap = null;
    try {
        IDFFMetaManager metaManager = FSUtils.getIDFFMetaManager();
        if (metaManager != null) {
            IDPDescriptorConfigElement idpConfig = metaManager.getIDPDescriptorConfig(realm, hostEntityId);
            if (idpConfig != null) {
                Map attributes = IDFFMetaUtils.getAttributes(idpConfig);
                attributeMap = FSServiceUtils.parseAttributeConfig((List) attributes.get(IFSConstants.IDP_ATTRIBUTE_MAP));
            }
        }
    } catch (IDFFMetaException me) {
        FSUtils.debug.error("FSDefaultAttributePlugin.getAttribute" + "Statements: meta exception.", me);
        return null;
    }
    if (attributeMap == null || attributeMap.isEmpty()) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSDefaultAttributePlugin.getAttribute" + "Statements: Attribute map configuration is empty.");
        }
        return null;
    } else {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSDefaultAttributePlugin.getAttribute" + "Statements: Attribute map configuration: " + attributeMap);
        }
    }
    List statements = new ArrayList();
    List attributes = new ArrayList();
    try {
        Iterator iter = attributeMap.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            String attributeName = (String) entry.getKey();
            String attributeValue = getAttributeValue(token, (String) entry.getValue());
            if (attributeValue != null) {
                Attribute attr = new Attribute(attributeName, SAMLConstants.assertionSAMLNameSpaceURI, attributeValue);
                attributes.add(attr);
            }
        }
        AttributeStatement statement = new AttributeStatement(subject, attributes);
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSDefaultAttributePlugin.getAttribute" + "Statements: attribute statement: " + statement.toString());
        }
        statements.add(statement);
        return statements;
    } catch (SAMLException ex) {
        FSUtils.debug.error("FSDefaultAttributePlugin.getAttribute" + "Statements: SAML Exception", ex);
    }
    return new ArrayList();
}
Also used : Attribute(com.sun.identity.saml.assertion.Attribute) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) ArrayList(java.util.ArrayList) SAMLException(com.sun.identity.saml.common.SAMLException) IDFFMetaManager(com.sun.identity.federation.meta.IDFFMetaManager) AttributeStatement(com.sun.identity.saml.assertion.AttributeStatement) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) IDPDescriptorConfigElement(com.sun.identity.federation.jaxb.entityconfig.IDPDescriptorConfigElement) Map(java.util.Map)

Example 28 with IDFFMetaException

use of com.sun.identity.federation.meta.IDFFMetaException in project OpenAM by OpenRock.

the class FSIDPProxyImpl method getPreferredIDP.

/**
     * Returns the preferred IDP.
     * @param authnRequest original authnrequest
     * @param hostEntityID ProxyIDP entity ID.
     * @param request <code>HttpServletRequest</code> object
     * @param response <code>HttpServletResponse</code> object
     * @return providerID of the authenticating provider to be proxied.
     * @exception FSRedirectException if redirect was done
     */
public String getPreferredIDP(FSAuthnRequest authnRequest, String hostEntityID, HttpServletRequest request, HttpServletResponse response) throws FSRedirectException {
    FSUtils.debug.message("FSIDPProxyImpl.getPreferredIDP:Init");
    try {
        Map attributes = IDFFMetaUtils.getAttributes(FSUtils.getIDFFMetaManager().getSPDescriptorConfig("/", authnRequest.getProviderId()));
        String useIntroductionForProxying = IDFFMetaUtils.getFirstAttributeValue(attributes, IFSConstants.USE_INTRODUCTION_FOR_IDP_PROXY);
        if (useIntroductionForProxying == null || !useIntroductionForProxying.equals("true")) {
            List proxyIDPs = (List) attributes.get(IFSConstants.IDP_PROXY_LIST);
            if (proxyIDPs == null || proxyIDPs.isEmpty()) {
                FSUtils.debug.error("FSIDPProxyImpl.getPrefferedIDP:" + "Preferred IDPs are null.");
                return null;
            }
            return (String) proxyIDPs.iterator().next();
        } else {
            StringBuffer redirectURL = new StringBuffer(100);
            String baseURL = FSServiceUtils.getBaseURL(request);
            redirectURL.append(baseURL).append(IFSConstants.IDP_FINDER_URL).append("?").append("RequestID=").append(authnRequest.getRequestID()).append("&").append("ProviderID=").append(hostEntityID);
            FSUtils.forwardRequest(request, response, redirectURL.toString());
            throw new FSRedirectException(FSUtils.bundle.getString("Redirection_Happened"));
        }
    } catch (IDFFMetaException ex) {
        FSUtils.debug.error("FSIDPProxyImpl.getPreferredIDP: " + "meta Exception in retrieving the preferred IDP", ex);
        return null;
    } catch (Exception e) {
        FSUtils.debug.error("FSIDPProxyImpl.getPreferredIDP: " + "Exception in retrieving the preferred IDP", e);
        return null;
    }
}
Also used : IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) FSRedirectException(com.sun.identity.federation.common.FSRedirectException) List(java.util.List) Map(java.util.Map) FSRedirectException(com.sun.identity.federation.common.FSRedirectException) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException)

Example 29 with IDFFMetaException

use of com.sun.identity.federation.meta.IDFFMetaException in project OpenAM by OpenRock.

the class FSLoginHelper method getIDPs.

private Set getIDPs(String metaAlias) {
    Set idpSet = new HashSet();
    try {
        String provider = "";
        String providerStatus = "";
        String role = IFSConstants.IDP.toLowerCase();
        IDPDescriptorType providerDesc = null;
        BaseConfigType providerConfig = null;
        Set trustedProviders = metaManager.getAllTrustedProviders(metaAlias);
        if (trustedProviders != null && !trustedProviders.isEmpty()) {
            Iterator it = trustedProviders.iterator();
            while (it.hasNext()) {
                provider = (String) it.next();
                providerDesc = metaManager.getIDPDescriptor(realm, provider);
                providerConfig = metaManager.getIDPDescriptorConfig(realm, provider);
                if (providerDesc == null || providerConfig == null) {
                    continue;
                }
                providerStatus = IDFFMetaUtils.getFirstAttributeValueFromConfig(providerConfig, IFSConstants.PROVIDER_STATUS);
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("FSLoginHelper::getIDPs For " + "providerId " + provider + " status is " + providerStatus);
                }
                if (providerStatus == null || providerStatus.length() == 0 || (providerStatus != null && providerStatus.equalsIgnoreCase(IFSConstants.ACTIVE))) {
                    idpSet.add(provider);
                }
            }
        }
    } catch (IDFFMetaException ame) {
        FSUtils.debug.error("FSLoginHelper::getIDPs Error in getting idp List:", ame);
    }
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSLoginHelper::getIDPs returing idpset as " + idpSet);
    }
    return idpSet;
}
Also used : IDPDescriptorType(com.sun.identity.liberty.ws.meta.jaxb.IDPDescriptorType) BaseConfigType(com.sun.identity.federation.jaxb.entityconfig.BaseConfigType) HashSet(java.util.HashSet) Set(java.util.Set) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) Iterator(java.util.Iterator) HashSet(java.util.HashSet)

Example 30 with IDFFMetaException

use of com.sun.identity.federation.meta.IDFFMetaException in project OpenAM by OpenRock.

the class FSDefaultRealmAttributeMapper method getAttributes.

/**
     * Returns the attribute map for the given list of 
     * <code>AttributeStatement</code>s. 
     * @param statements list of <code>AttributeStatements</code>s.
     * @param realm The realm under which the entity resides.
     * @param hostEntityId Hosted provider entity id.
     * @param remoteEntityId Remote provider entity id.
     * @param token Single sign-on session token.
     * @return map of attribute values. The  map will have the key as the
     *             attribute name and the map value is the attribute value
     *             that are passed via the single sign-on assertion.
     */
public Map getAttributes(List statements, String realm, String hostEntityId, String remoteEntityId, Object token) {
    Map map = new HashMap();
    if (statements == null || statements.size() == 0) {
        return map;
    }
    Map configMap = null;
    try {
        IDFFMetaManager metaManager = FSUtils.getIDFFMetaManager();
        if (metaManager != null) {
            SPDescriptorConfigElement spConfig = metaManager.getSPDescriptorConfig(realm, hostEntityId);
            if (spConfig != null) {
                Map attributes = IDFFMetaUtils.getAttributes(spConfig);
                configMap = FSServiceUtils.parseAttributeConfig((List) attributes.get(IFSConstants.SP_ATTRIBUTE_MAP));
            }
        }
    } catch (IDFFMetaException fme) {
        FSUtils.debug.error("FSDefaultAttributeMapper.getAttributes:" + " Unable to read configuration map.", fme);
        return map;
    }
    if (FSUtils.debug.messageEnabled()) {
        FSUtils.debug.message("FSDefaultAttributeMapper.getAttributeMap: Configured map " + configMap);
    }
    for (Iterator iter = statements.iterator(); iter.hasNext(); ) {
        AttributeStatement statement = (AttributeStatement) iter.next();
        List attributes = statement.getAttribute();
        if (attributes == null || attributes.size() == 0) {
            continue;
        }
        Iterator iter1 = attributes.iterator();
        while (iter1.hasNext()) {
            Attribute attribute = (Attribute) iter1.next();
            List values = null;
            try {
                values = attribute.getAttributeValue();
            } catch (SAMLException ex) {
                if (FSUtils.debug.messageEnabled()) {
                    FSUtils.debug.message("FSDefaultAttributeMapper.get" + "Attributes: Exception", ex);
                }
                continue;
            }
            if (values == null || values.size() == 0) {
                continue;
            }
            String attributeName = attribute.getAttributeName();
            if (configMap != null && !configMap.isEmpty()) {
                String realAttrName = (String) configMap.get(attributeName);
                if (realAttrName != null && realAttrName.length() > 0) {
                    attributeName = realAttrName;
                }
            }
            //Retrieve the first only one.
            String valueString = XMLUtils.getElementValue((Element) values.get(0));
            if (valueString != null && valueString.length() > 0) {
                map.put(attributeName, valueString);
            }
        }
    }
    return map;
}
Also used : HashMap(java.util.HashMap) Attribute(com.sun.identity.saml.assertion.Attribute) IDFFMetaManager(com.sun.identity.federation.meta.IDFFMetaManager) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) AttributeStatement(com.sun.identity.saml.assertion.AttributeStatement) SPDescriptorConfigElement(com.sun.identity.federation.jaxb.entityconfig.SPDescriptorConfigElement) Iterator(java.util.Iterator) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SAMLException(com.sun.identity.saml.common.SAMLException)

Aggregations

IDFFMetaException (com.sun.identity.federation.meta.IDFFMetaException)89 IDFFMetaManager (com.sun.identity.federation.meta.IDFFMetaManager)55 BaseConfigType (com.sun.identity.federation.jaxb.entityconfig.BaseConfigType)30 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)27 Iterator (java.util.Iterator)25 Map (java.util.Map)25 HashMap (java.util.HashMap)24 List (java.util.List)24 ProviderDescriptorType (com.sun.identity.liberty.ws.meta.jaxb.ProviderDescriptorType)22 Set (java.util.Set)21 SAMLException (com.sun.identity.saml.common.SAMLException)17 HashSet (java.util.HashSet)17 ArrayList (java.util.ArrayList)14 FSException (com.sun.identity.federation.common.FSException)13 FSMsgException (com.sun.identity.federation.message.common.FSMsgException)12 CLIException (com.sun.identity.cli.CLIException)10 SessionException (com.sun.identity.plugin.session.SessionException)9 IOException (java.io.IOException)9 IDPDescriptorConfigElement (com.sun.identity.federation.jaxb.entityconfig.IDPDescriptorConfigElement)8 SPDescriptorConfigElement (com.sun.identity.federation.jaxb.entityconfig.SPDescriptorConfigElement)8