Search in sources :

Example 1 with COTException

use of com.sun.identity.cot.COTException in project OpenAM by OpenRock.

the class GetCircleOfTrusts method execute.

/**
     * Returns Circle of trust of a given realm or extended metadata.
     *
     * @param locale Locale of the request.
     * @param params Map of creation parameters.
     */
public String execute(Locale locale, Map params) throws WorkflowException {
    String realm = getString(params, ParameterKeys.P_REALM);
    if (realm == null) {
        String extendedMetaData = getString(params, ParameterKeys.P_EXTENDED_DATA);
        if (extendedMetaData != null) {
            realm = getRealmFromExtData(getContent(extendedMetaData, locale));
        }
    }
    if (realm == null) {
        throw new WorkflowException("invalid-metaalias-slash", null);
    }
    try {
        CircleOfTrustManager mgr = new CircleOfTrustManager();
        Set cots = mgr.getAllCirclesOfTrust(realm);
        StringBuffer buff = new StringBuffer();
        if ((cots != null) && !cots.isEmpty()) {
            boolean first = true;
            for (Iterator i = cots.iterator(); i.hasNext(); ) {
                String c = (String) i.next();
                if (first) {
                    first = false;
                } else {
                    buff.append("|");
                }
                try {
                    buff.append(StringUtils.encodeURIComponent(c, "UTF-8"));
                } catch (UnsupportedEncodingException e) {
                    buff.append(c);
                }
            }
        }
        return buff.toString();
    } catch (COTException e) {
        throw new WorkflowException("invalid-extended-data-cot", null);
    }
}
Also used : CircleOfTrustManager(com.sun.identity.cot.CircleOfTrustManager) Set(java.util.Set) Iterator(java.util.Iterator) UnsupportedEncodingException(java.io.UnsupportedEncodingException) COTException(com.sun.identity.cot.COTException)

Example 2 with COTException

use of com.sun.identity.cot.COTException in project OpenAM by OpenRock.

the class GetHostedIDPs method execute.

public String execute(Locale locale, Map params) throws WorkflowException {
    String realm = getString(params, ParameterKeys.P_REALM);
    String cot = getString(params, ParameterKeys.P_COT);
    try {
        CircleOfTrustManager cotMgr = new CircleOfTrustManager();
        Set entities = cotMgr.listCircleOfTrustMember(realm, cot, COTConstants.SAML2);
        SAML2MetaManager mgr = new SAML2MetaManager();
        StringBuffer buff = new StringBuffer();
        boolean first = true;
        for (Iterator i = entities.iterator(); i.hasNext(); ) {
            String entityId = (String) i.next();
            EntityConfigElement elm = mgr.getEntityConfig(realm, entityId);
            // elm could be null due to OPENAM-269
            if (elm != null && elm.isHosted()) {
                EntityDescriptorElement desc = mgr.getEntityDescriptor(realm, entityId);
                if (SAML2MetaUtils.getIDPSSODescriptor(desc) != null) {
                    if (first) {
                        first = false;
                    } else {
                        buff.append("|");
                    }
                    buff.append(entityId);
                }
            }
        }
        return buff.toString();
    } catch (COTException e) {
        throw new WorkflowException(e.getMessage(), null);
    } catch (SAML2MetaException e) {
        throw new WorkflowException(e.getMessage(), null);
    }
}
Also used : CircleOfTrustManager(com.sun.identity.cot.CircleOfTrustManager) Set(java.util.Set) Iterator(java.util.Iterator) SAML2MetaManager(com.sun.identity.saml2.meta.SAML2MetaManager) COTException(com.sun.identity.cot.COTException) EntityDescriptorElement(com.sun.identity.saml2.jaxb.metadata.EntityDescriptorElement) SAML2MetaException(com.sun.identity.saml2.meta.SAML2MetaException) EntityConfigElement(com.sun.identity.saml2.jaxb.entityconfig.EntityConfigElement)

Example 3 with COTException

use of com.sun.identity.cot.COTException in project OpenAM by OpenRock.

the class LibertyManager method getListOfCOTs.

/**
     * Returns the List of COTs for the given Provider under a realm.
     *
     * @param realm The realm under which the entity resides.
     * @param providerId The ID of the provider whose <code>COTList</code>
     *  is to be found
     * @param providerRole The Role of the provider whose <code>COTList</code>
     *  is to be found
     * @return The set containing the authentication domains for the given
     *  provider.
     */
public static Set getListOfCOTs(String realm, String providerId, String providerRole) {
    Set returnSet = new HashSet();
    BaseConfigType hostConfig = IDFFMetaUtils.getExtendedConfig(realm, providerId, providerRole, metaManager);
    if (hostConfig != null) {
        List cotSet = IDFFMetaUtils.getAttributeValueFromConfig(hostConfig, IFSConstants.COT_LIST);
        if (cotSet != null && !cotSet.isEmpty()) {
            Iterator iter = cotSet.iterator();
            while (iter.hasNext()) {
                String cotID = (String) iter.next();
                try {
                    CircleOfTrustManager cotManager = new CircleOfTrustManager();
                    CircleOfTrustDescriptor cotDesc = cotManager.getCircleOfTrust(realm, cotID);
                    String tldURL = cotDesc.getIDFFWriterServiceURL();
                    String cotStatus = cotDesc.getCircleOfTrustStatus();
                    if (tldURL != null && tldURL.length() > 0 && cotStatus.equalsIgnoreCase(IFSConstants.ACTIVE)) {
                        returnSet.add((String) cotID);
                    }
                } catch (COTException fsExp) {
                    debug.error("LibertyManager: getListOfCots " + "COTException caught ", fsExp);
                }
            }
        }
        if (returnSet != null && returnSet.size() > 0) {
            if (debug.messageEnabled()) {
                debug.message("LibertyManager: getListOfCots returning " + " cot set with " + returnSet);
            }
        } else {
            if (debug.messageEnabled()) {
                debug.message("LibertyManager::getListOfCots returning" + " null. Looks like COT is not set");
            }
        }
    }
    return returnSet;
}
Also used : BaseConfigType(com.sun.identity.federation.jaxb.entityconfig.BaseConfigType) HashSet(java.util.HashSet) Set(java.util.Set) CircleOfTrustManager(com.sun.identity.cot.CircleOfTrustManager) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) CircleOfTrustDescriptor(com.sun.identity.cot.CircleOfTrustDescriptor) COTException(com.sun.identity.cot.COTException) HashSet(java.util.HashSet)

Example 4 with COTException

use of com.sun.identity.cot.COTException in project OpenAM by OpenRock.

the class ConfigFedMonitoring method getCOTs.

private Set getCOTs(String realm, CircleOfTrustManager cotmgr) {
    String classMethod = "ConfigFedMonitoring.getCOTs: ";
    Set cotSet = null;
    try {
        cotSet = cotmgr.getAllCirclesOfTrust(realm);
    } catch (COTException e) {
        debug.error(classMethod + "COTMgr error: " + e.getMessage());
    }
    return cotSet;
}
Also used : Set(java.util.Set) COTException(com.sun.identity.cot.COTException)

Example 5 with COTException

use of com.sun.identity.cot.COTException in project OpenAM by OpenRock.

the class FSIDPFinderService method getCommonDomainIDP.

/**
     * Gets a preferred IDP from the common domain cookie.
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @param realm The realm under which the entity resides.
     * @param entityID Hosted entity ID.
     * @param requestID Original Authentication Request ID.
     * @exception FSRedirectException for the redirection.
     *            IOException for any redirection failure.
     */
private String getCommonDomainIDP(HttpServletRequest request, HttpServletResponse response, String realm, String entityID, String requestID) throws FSRedirectException, IOException {
    String idpID = FSUtils.findPreferredIDP(realm, request);
    if (idpID != null) {
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSIDPFinderService.getCommonDomainIDP:" + "Preferred IDP found from the common domain." + idpID);
        }
        if (requestCotSetMap.containsKey(requestID)) {
            requestCotSetMap.remove(requestID);
        }
        return idpID;
    }
    Set tmpCotSet = (Set) requestCotSetMap.get(requestID);
    if (tmpCotSet == null) {
        try {
            IDFFMetaManager metaManager = FSUtils.getIDFFMetaManager();
            List cotList = null;
            if (metaManager != null) {
                BaseConfigType spConfig = metaManager.getSPDescriptorConfig(realm, entityID);
                cotList = IDFFMetaUtils.getAttributeValueFromConfig(spConfig, IFSConstants.COT_LIST);
            }
            if (cotList != null) {
                tmpCotSet = new HashSet();
                tmpCotSet.addAll(cotList);
            }
        } catch (IDFFMetaException ie) {
            FSUtils.debug.error("FSIDPFinderService.getCommonDomainIDP:cannot get meta:", ie);
            return null;
        }
    }
    if (tmpCotSet == null || tmpCotSet.isEmpty()) {
        FSUtils.debug.message("FSIDPFinderService.getCommonDomainIDP::No more Cots.");
        if (requestCotSetMap.containsKey(requestID)) {
            requestCotSetMap.remove(requestID);
        }
        return null;
    }
    Iterator iter = tmpCotSet.iterator();
    while (iter.hasNext()) {
        String cotName = (String) iter.next();
        iter.remove();
        requestCotSetMap.put(requestID, tmpCotSet);
        if (FSUtils.debug.messageEnabled()) {
            FSUtils.debug.message("FSIDPFinderService.getCommonDomainIDP: Trying Cot: " + cotName);
        }
        String readerServiceURL = null;
        try {
            CircleOfTrustManager cotManager = new CircleOfTrustManager();
            CircleOfTrustDescriptor cotDesc = cotManager.getCircleOfTrust(realm, cotName);
            if (cotDesc != null && (cotDesc.getCircleOfTrustStatus()).equalsIgnoreCase(IFSConstants.ACTIVE)) {
                readerServiceURL = cotDesc.getIDFFReaderServiceURL();
            }
        } catch (COTException fe) {
            FSUtils.debug.error("FSIDPFinderService.getCommonDomainIDP:" + "Unable to retrieve reader service url.", fe);
        }
        if (readerServiceURL != null) {
            String baseURL = FSServiceUtils.getBaseURL(request);
            StringBuffer returnURL = new StringBuffer(300);
            returnURL.append(baseURL).append(IFSConstants.IDP_FINDER_URL).append("?").append("RequestID").append("=").append(URLEncDec.encode(requestID)).append("&").append("Realm=").append(URLEncDec.encode(realm)).append("&").append("ProviderID=").append(URLEncDec.encode(entityID));
            StringBuffer redirectURL = new StringBuffer(300);
            redirectURL.append(readerServiceURL).append("?").append(IFSConstants.LRURL).append("=").append(URLEncDec.encode(returnURL.toString()));
            String url = redirectURL.toString();
            if (FSUtils.debug.messageEnabled()) {
                FSUtils.debug.message("FSIDPFinderService.getCommonDomainIDP:Redirection URL:" + url);
            }
            response.setHeader("Location", url);
            response.sendRedirect(url);
            throw new FSRedirectException(FSUtils.bundle.getString("Redirection_Happened"));
        }
    }
    return null;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) CircleOfTrustManager(com.sun.identity.cot.CircleOfTrustManager) IDFFMetaException(com.sun.identity.federation.meta.IDFFMetaException) FSRedirectException(com.sun.identity.federation.common.FSRedirectException) CircleOfTrustDescriptor(com.sun.identity.cot.CircleOfTrustDescriptor) COTException(com.sun.identity.cot.COTException) BaseConfigType(com.sun.identity.federation.jaxb.entityconfig.BaseConfigType) IDFFMetaManager(com.sun.identity.federation.meta.IDFFMetaManager) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Aggregations

COTException (com.sun.identity.cot.COTException)42 CircleOfTrustManager (com.sun.identity.cot.CircleOfTrustManager)29 Set (java.util.Set)18 Iterator (java.util.Iterator)16 CircleOfTrustDescriptor (com.sun.identity.cot.CircleOfTrustDescriptor)15 List (java.util.List)15 Map (java.util.Map)14 ArrayList (java.util.ArrayList)13 SAML2MetaException (com.sun.identity.saml2.meta.SAML2MetaException)12 HashMap (java.util.HashMap)11 CLIException (com.sun.identity.cli.CLIException)10 HashSet (java.util.HashSet)10 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)9 SAML2MetaManager (com.sun.identity.saml2.meta.SAML2MetaManager)9 SPSSOConfigElement (com.sun.identity.saml2.jaxb.entityconfig.SPSSOConfigElement)7 EntityConfigElement (com.sun.identity.saml2.jaxb.entityconfig.EntityConfigElement)6 IDFFMetaException (com.sun.identity.federation.meta.IDFFMetaException)5 JAXBException (javax.xml.bind.JAXBException)5 IDFFMetaManager (com.sun.identity.federation.meta.IDFFMetaManager)4 EntityDescriptorElement (com.sun.identity.saml2.jaxb.metadata.EntityDescriptorElement)4