Search in sources :

Example 11 with FederationElement

use of com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement in project OpenAM by OpenRock.

the class CreateWSFedMetaDataTemplate method createStandardMetaTemplate.

public static String createStandardMetaTemplate(String entityId, Map mapParams, String url) throws JAXBException, CertificateEncodingException {
    JAXBContext jc = WSFederationMetaUtils.getMetaJAXBContext();
    com.sun.identity.wsfederation.jaxb.wsfederation.ObjectFactory objFactory = new com.sun.identity.wsfederation.jaxb.wsfederation.ObjectFactory();
    FederationElement fed = objFactory.createFederationElement();
    fed.setFederationID(entityId);
    String idpAlias = (String) mapParams.get(MetaTemplateParameters.P_IDP);
    if (idpAlias != null) {
        addWSFedIdentityProviderTemplate(entityId, objFactory, fed, mapParams, url);
    }
    String spAlias = (String) mapParams.get(MetaTemplateParameters.P_SP);
    if (spAlias != null) {
        addWSFedServiceProviderTemplate(entityId, objFactory, fed, mapParams, url);
    }
    Marshaller m = jc.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    StringWriter pw = new StringWriter();
    m.marshal(fed, pw);
    return pw.toString();
}
Also used : Marshaller(javax.xml.bind.Marshaller) StringWriter(java.io.StringWriter) JAXBContext(javax.xml.bind.JAXBContext) FederationElement(com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement)

Example 12 with FederationElement

use of com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement in project OpenAM by OpenRock.

the class ConfigFedMonitoring method getWSFedRoles.

public List getWSFedRoles(String entity, String realm) {
    List roles = new ArrayList(4);
    boolean isSP = true;
    int cnt = 0;
    try {
        WSFederationMetaManager metaManager = new WSFederationMetaManager();
        if (metaManager.getIDPSSOConfig(realm, entity) != null) {
            roles.add(IDENTITY_PROVIDER);
        }
        if (metaManager.getSPSSOConfig(realm, entity) != null) {
            roles.add(SERVICE_PROVIDER);
        }
        //to handle dual roles specifically for WSFED
        if (roles.isEmpty()) {
            FederationElement fedElem = metaManager.getEntityDescriptor(realm, entity);
            if (fedElem != null) {
                for (Iterator iter = fedElem.getAny().iterator(); iter.hasNext(); ) {
                    Object o = iter.next();
                    if (o instanceof UriNamedClaimTypesOfferedElement) {
                        roles.add(IDENTITY_PROVIDER);
                        isSP = false;
                    } else if (o instanceof TokenIssuerEndpointElement) {
                        cnt++;
                    }
                }
                if ((isSP) || (cnt > 1)) {
                    roles.add(SERVICE_PROVIDER);
                }
            }
        }
    } catch (WSFederationMetaException e) {
        debug.warning("ConfigFedMonitoring.getWSFedRoles", e);
    }
    return (roles != null) ? roles : Collections.EMPTY_LIST;
}
Also used : WSFederationMetaManager(com.sun.identity.wsfederation.meta.WSFederationMetaManager) UriNamedClaimTypesOfferedElement(com.sun.identity.wsfederation.jaxb.wsfederation.UriNamedClaimTypesOfferedElement) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) WSFederationMetaException(com.sun.identity.wsfederation.meta.WSFederationMetaException) FederationElement(com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement) TokenIssuerEndpointElement(com.sun.identity.wsfederation.jaxb.wsfederation.TokenIssuerEndpointElement)

Example 13 with FederationElement

use of com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement in project OpenAM by OpenRock.

the class WSFedPropertiesModelImpl method setGenAttributeValues.

/**
     * Saves the attribute values from the General page.
     *
     * @param realm to which the entity belongs.
     * @param fedId is the entity id.
     * @param idpStdValues has the General standard attribute value pairs.
     * @param role of the entity ID.
     * @param location specifies if the entity is remote or local.
     * @throws AMConsoleException if saving of attribute value fails.
     */
public void setGenAttributeValues(String realm, String fedId, Map idpStdValues, String role, String location) throws AMConsoleException {
    String tknissEndPt = null;
    String tknissName = null;
    Iterator it = idpStdValues.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry entry = (Map.Entry) it.next();
        Object key = entry.getKey();
        Object value = entry.getValue();
        if (key.equals(TFTOKENISSUER_ENDPT)) {
            HashSet set = (HashSet) idpStdValues.get(key);
            Iterator i = set.iterator();
            while ((i != null) && (i.hasNext())) {
                tknissEndPt = (String) i.next();
            }
        } else if (key.equals(TFTOKENISSUER_NAME)) {
            HashSet set = (HashSet) idpStdValues.get(key);
            Iterator i = set.iterator();
            while ((i != null) && (i.hasNext())) {
                tknissName = (String) i.next();
            }
        } else if (key.equals(TF_DISPNAME)) {
            if (role.equals(EntityModel.SERVICE_PROVIDER)) {
                HashSet set = (HashSet) idpStdValues.get(key);
                // Get the current map of extended SP values
                Map tmpMap = getExtendedValues(role, realm, fedId);
                // Replace existing value
                tmpMap.put(TF_DISPNAME, set);
                setSPExtAttributeValues(realm, fedId, tmpMap, location);
            } else if (role.equals(EntityModel.IDENTITY_PROVIDER)) {
                HashSet set = (HashSet) idpStdValues.get(key);
                // Get the current map of extended IDP values
                Map tmpMap = getExtendedValues(role, realm, fedId);
                // Replace existing value
                tmpMap.put(TF_DISPNAME, set);
                setIDPExtAttributeValues(realm, fedId, tmpMap, location);
            } else if (role.equals(DUAL)) {
                HashSet set = (HashSet) idpStdValues.get(key);
                // Get the current map of extended SP values
                Map tmpMap = getExtendedValues(EntityModel.SERVICE_PROVIDER, realm, fedId);
                // Replace existing value
                tmpMap.put(TF_DISPNAME, set);
                setSPExtAttributeValues(realm, fedId, tmpMap, location);
                // Get the current map of extended IDP values
                tmpMap = getExtendedValues(EntityModel.IDENTITY_PROVIDER, realm, fedId);
                set = (HashSet) idpStdValues.get(TFIDPDISP_NAME);
                // Replace existing value
                tmpMap.put(TF_DISPNAME, set);
                setIDPExtAttributeValues(realm, fedId, tmpMap, location);
            }
        }
    }
    try {
        //fedElem is standard metadata federation element under the realm.
        WSFederationMetaManager metaManager = getWSFederationMetaManager();
        FederationElement fedElem = metaManager.getEntityDescriptor(realm, fedId);
        if (fedElem == null) {
            if (debug.warningEnabled()) {
                debug.warning("WSFedPropertiesModelImpl.setGenAttributeValues:" + " found invalid  federation element " + fedId);
            }
            throw new AMConsoleException("invalid.federation.element");
        } else {
            for (Iterator iter = fedElem.getAny().iterator(); iter.hasNext(); ) {
                Object o = iter.next();
                if (o instanceof TokenIssuerEndpointElement) {
                    ((TokenIssuerEndpointElement) o).getAddress().setValue(tknissEndPt);
                } else if (o instanceof TokenIssuerNameElement) {
                    ((TokenIssuerNameElement) o).setValue(tknissName);
                }
            }
            metaManager.setFederation(realm, fedElem);
        }
    } catch (WSFederationMetaException e) {
        debug.warning("WSFedPropertiesModelImpl.setGenAttributeValues", e);
        throw new AMConsoleException(e.getMessage());
    }
}
Also used : WSFederationMetaManager(com.sun.identity.wsfederation.meta.WSFederationMetaManager) TokenIssuerEndpointElement(com.sun.identity.wsfederation.jaxb.wsfederation.TokenIssuerEndpointElement) TokenIssuerNameElement(com.sun.identity.wsfederation.jaxb.wsfederation.TokenIssuerNameElement) Iterator(java.util.Iterator) WSFederationMetaException(com.sun.identity.wsfederation.meta.WSFederationMetaException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) HashMap(java.util.HashMap) Map(java.util.Map) FederationElement(com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement) HashSet(java.util.HashSet)

Example 14 with FederationElement

use of com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement in project OpenAM by OpenRock.

the class WSFedGeneralViewBean method beginDisplay.

public void beginDisplay(DisplayEvent event) throws ModelControlException {
    super.beginDisplay(event);
    //setting the Name fields
    setDisplayFieldValue(WSFedPropertiesModel.TF_REALM, realm);
    setDisplayFieldValue(WSFedPropertiesModel.TF_NAME, entityName);
    try {
        WSFedPropertiesModel model = (WSFedPropertiesModel) getModel();
        FederationElement fedElement = model.getEntityDesc(realm, entityName);
        //setting the Token Issuer Name
        setDisplayFieldValue(WSFedPropertiesModel.TFTOKENISSUER_NAME, model.getTokenName(fedElement));
        //setting the Token Issuer End Point
        setDisplayFieldValue(WSFedPropertiesModel.TFTOKENISSUER_ENDPT, model.getTokenEndpoint(fedElement));
        //setting the value of displayName
        setDisplayName(entityName, realm);
    } catch (AMConsoleException e) {
        debug.error("WSFedGeneralViewBean.beginDisplay", e);
    }
}
Also used : WSFedPropertiesModel(com.sun.identity.console.federation.model.WSFedPropertiesModel) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) FederationElement(com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement)

Example 15 with FederationElement

use of com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement in project OpenAM by OpenRock.

the class ExportMetaData method runWSFedExportMetaSign.

private void runWSFedExportMetaSign() throws CLIException {
    PrintWriter pw = null;
    String out = (isWebBase) ? "web" : metadata;
    Object[] objs = { out };
    try {
        WSFederationMetaManager metaManager = new WSFederationMetaManager(ssoToken);
        FederationElement descriptor = metaManager.getEntityDescriptor(realm, entityID);
        if (descriptor == null) {
            Object[] objs2 = { entityID, realm };
            throw new CLIException(MessageFormat.format(getResourceString("export-entity-exception-entity-descriptor-not-exist"), objs2), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        com.sun.identity.wsfederation.jaxb.entityconfig.SPSSOConfigElement spConfig = metaManager.getSPSSOConfig(realm, entityID);
        com.sun.identity.wsfederation.jaxb.entityconfig.IDPSSOConfigElement idpConfig = metaManager.getIDPSSOConfig(realm, entityID);
        Document doc = WSFederationMetaSecurityUtils.sign(descriptor, spConfig, idpConfig);
        if (doc == null) {
            runWSFedExportMeta();
            return;
        } else {
            String xmlstr = XMLUtils.print(doc);
            if (isWebBase) {
                getOutputWriter().printlnMessage(xmlstr);
            } else {
                pw = new PrintWriter(new FileWriter(metadata));
                pw.print(xmlstr);
            }
            getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("export-entity-export-descriptor-succeeded"), objs));
        }
    } catch (WSFederationMetaException e) {
        debugError("ExportMetaData.runExportMetaSign", e);
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (JAXBException jaxbe) {
        Object[] objs3 = { entityID, realm };
        throw new CLIException(MessageFormat.format(getResourceString("export-entity-exception-invalid_descriptor"), objs3), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IOException e) {
        debugError("ExportMetaData.runExportMetaSign", e);
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
}
Also used : WSFederationMetaManager(com.sun.identity.wsfederation.meta.WSFederationMetaManager) FileWriter(java.io.FileWriter) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException) Document(org.w3c.dom.Document) CLIException(com.sun.identity.cli.CLIException) WSFederationMetaException(com.sun.identity.wsfederation.meta.WSFederationMetaException) FederationElement(com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement) PrintWriter(java.io.PrintWriter)

Aggregations

FederationElement (com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement)23 WSFederationMetaManager (com.sun.identity.wsfederation.meta.WSFederationMetaManager)12 WSFederationMetaException (com.sun.identity.wsfederation.meta.WSFederationMetaException)10 List (java.util.List)8 Iterator (java.util.Iterator)7 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)6 HashSet (java.util.HashSet)6 JAXBException (javax.xml.bind.JAXBException)6 FederationConfigElement (com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement)5 BaseConfigType (com.sun.identity.wsfederation.jaxb.entityconfig.BaseConfigType)4 TokenIssuerEndpointElement (com.sun.identity.wsfederation.jaxb.wsfederation.TokenIssuerEndpointElement)4 CLIException (com.sun.identity.cli.CLIException)3 WSFederationException (com.sun.identity.wsfederation.common.WSFederationException)3 UriNamedClaimTypesOfferedElement (com.sun.identity.wsfederation.jaxb.wsfederation.UriNamedClaimTypesOfferedElement)3 ArrayList (java.util.ArrayList)3 Set (java.util.Set)3 WSFedPropertiesModel (com.sun.identity.console.federation.model.WSFedPropertiesModel)2 ConfigurationException (com.sun.identity.plugin.configuration.ConfigurationException)2 AttributeType (com.sun.identity.wsfederation.jaxb.entityconfig.AttributeType)2 ObjectFactory (com.sun.identity.wsfederation.jaxb.entityconfig.ObjectFactory)2