Search in sources :

Example 26 with WSFederationMetaManager

use of com.sun.identity.wsfederation.meta.WSFederationMetaManager 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)

Example 27 with WSFederationMetaManager

use of com.sun.identity.wsfederation.meta.WSFederationMetaManager in project OpenAM by OpenRock.

the class ExportMetaData method runWSFedExportExtended.

private void runWSFedExportExtended() throws CLIException {
    OutputStream os = null;
    String out = (isWebBase) ? "web" : extendedData;
    Object[] objs = { out };
    Object[] objs2 = { entityID, realm };
    try {
        WSFederationMetaManager metaManager = new WSFederationMetaManager(ssoToken);
        com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement config = metaManager.getEntityConfig(realm, entityID);
        if (config == null) {
            throw new CLIException(MessageFormat.format(getResourceString("export-entity-exception-entity-config-not-exist"), objs2), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        if (isWebBase) {
            os = new ByteArrayOutputStream();
        } else {
            os = new FileOutputStream(extendedData);
        }
        WSFederationMetaUtils.convertJAXBToOutputStream(config, os);
        if (isWebBase) {
            getOutputWriter().printlnMessage(os.toString());
        }
        getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("export-entity-export-config-succeeded"), objs));
    } catch (WSFederationMetaException e) {
        debugError("ExportMetaData.runExportExtended", e);
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (FileNotFoundException e) {
        debugWarning("ExportMetaData.runExportExtended", e);
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (JAXBException e) {
        debugWarning("ExportMetaData.runExportExtended", e);
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (IllegalArgumentException e) {
        debugWarning("ExportMetaData.runExportExtended", e);
        throw new CLIException(MessageFormat.format(getResourceString("export-entity-exception-invalid-config"), objs2), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } finally {
        if (os != null) {
            try {
                os.close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
}
Also used : WSFederationMetaManager(com.sun.identity.wsfederation.meta.WSFederationMetaManager) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) JAXBException(javax.xml.bind.JAXBException) FileNotFoundException(java.io.FileNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) FileOutputStream(java.io.FileOutputStream) CLIException(com.sun.identity.cli.CLIException) WSFederationMetaException(com.sun.identity.wsfederation.meta.WSFederationMetaException)

Example 28 with WSFederationMetaManager

use of com.sun.identity.wsfederation.meta.WSFederationMetaManager in project OpenAM by OpenRock.

the class DeleteMetaData method handleWSFedRequest.

private void handleWSFedRequest(RequestContext rc) throws CLIException {
    try {
        WSFederationMetaManager metaManager = new WSFederationMetaManager(ssoToken);
        if (metaManager.getEntityDescriptor(realm, entityID) == null) {
            Object[] param = { entityID };
            throw new CLIException(MessageFormat.format(getResourceString("delete-entity-entity-not-exist"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
        }
        if (extendedOnly) {
            metaManager.deleteEntityConfig(realm, entityID);
            Object[] objs = { entityID };
            getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("delete-entity-config-deleted"), objs));
        } else {
            metaManager.deleteFederation(realm, entityID);
            Object[] objs = { entityID };
            getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("delete-entity-descriptor-deleted"), objs));
        }
    } catch (WSFederationMetaException e) {
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : WSFederationMetaManager(com.sun.identity.wsfederation.meta.WSFederationMetaManager) CLIException(com.sun.identity.cli.CLIException) WSFederationMetaException(com.sun.identity.wsfederation.meta.WSFederationMetaException)

Example 29 with WSFederationMetaManager

use of com.sun.identity.wsfederation.meta.WSFederationMetaManager in project OpenAM by OpenRock.

the class WSFedPropertiesModelImpl method createExtendedObject.

/**
     * Creates the extended config object when it does not exist.
     * @param realm to which the entity belongs.
     * @param fedId is the entity id.
     * @param location is either hosted or remote
     * @param role is SP, IDP or SP/IDP.
     * @param keys which contain all extended attribute keys.
     * @throws WSFederationMetaException, JAXBException,
     *     AMConsoleException if saving of attribute value fails.
     */
private void createExtendedObject(String realm, String fedId, String location, String role, Map keys) throws WSFederationMetaException, JAXBException, AMConsoleException {
    try {
        ObjectFactory objFactory = new ObjectFactory();
        WSFederationMetaManager metaManager = getWSFederationMetaManager();
        FederationElement edes = metaManager.getEntityDescriptor(realm, fedId);
        if (edes == null) {
            if (debug.warningEnabled()) {
                debug.warning("WSFedPropertiesModelImpl.createExtendedObject: " + "No such entity: " + fedId);
            }
            String[] data = { realm, fedId };
            throw new WSFederationMetaException("fedId_invalid", data);
        }
        FederationConfigElement eConfig = metaManager.getEntityConfig(realm, fedId);
        if (eConfig == null) {
            BaseConfigType bctype = null;
            FederationConfigElement ele = objFactory.createFederationConfigElement();
            ele.setFederationID(fedId);
            if (location.equals("remote")) {
                ele.setHosted(false);
            }
            List ll = ele.getIDPSSOConfigOrSPSSOConfig();
            // Right now, it is either an SP or an IdP or dual role
            if (isDualRole(edes)) {
                //for dual role create both idp and sp config objects
                BaseConfigType bctype_idp = null;
                BaseConfigType bctype_sp = null;
                bctype_idp = objFactory.createIDPSSOConfigElement();
                bctype_idp = createAttributeElement(keys, bctype_idp);
                bctype_sp = objFactory.createSPSSOConfigElement();
                bctype_sp = createAttributeElement(keys, bctype_sp);
                ll.add(bctype_idp);
                ll.add(bctype_sp);
            } else if (role.equals(IDENTITY_PROVIDER)) {
                bctype = objFactory.createIDPSSOConfigElement();
                //bctype.getAttribute().add(atype);
                bctype = createAttributeElement(keys, bctype);
                ll.add(bctype);
            } else if (role.equals(SERVICE_PROVIDER)) {
                bctype = objFactory.createSPSSOConfigElement();
                bctype = createAttributeElement(keys, bctype);
                ll.add(bctype);
            }
            metaManager.setEntityConfig(realm, ele);
        }
    } catch (JAXBException e) {
        debug.warning("WSFedPropertiesModelImpl.createExtendedObject", e);
        throw new AMConsoleException(getErrorString(e));
    } catch (WSFederationMetaException e) {
        debug.warning("WSFedPropertiesModelImpl.createExtendedObject", e);
        throw new AMConsoleException(getErrorString(e));
    }
}
Also used : BaseConfigType(com.sun.identity.wsfederation.jaxb.entityconfig.BaseConfigType) WSFederationMetaManager(com.sun.identity.wsfederation.meta.WSFederationMetaManager) ObjectFactory(com.sun.identity.wsfederation.jaxb.entityconfig.ObjectFactory) JAXBException(javax.xml.bind.JAXBException) FederationConfigElement(com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement) List(java.util.List) WSFederationMetaException(com.sun.identity.wsfederation.meta.WSFederationMetaException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) FederationElement(com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement)

Example 30 with WSFederationMetaManager

use of com.sun.identity.wsfederation.meta.WSFederationMetaManager in project OpenAM by OpenRock.

the class WSFedPropertiesModelImpl method getServiceProviderAttributes.

/**
     * Returns a map with service provider attributes and values.
     *
     * @param realm to which the entity belongs.
     * @param fedId is the Federation Id otherwise known as the entity id.
     * @return attribute values of SP based on realm and fedId passed.
     * @throws AMConsoleException if unable to retreive the Service Provider
     *     attrubutes based on the realm and fedId passed.
     */
public Map getServiceProviderAttributes(String realm, String fedId) throws AMConsoleException {
    Map SPAttributes = null;
    try {
        WSFederationMetaManager metaManager = getWSFederationMetaManager();
        SPSSOConfigElement spconfig = metaManager.getSPSSOConfig(realm, fedId);
        if (spconfig != null) {
            SPAttributes = WSFederationMetaUtils.getAttributes(spconfig);
        }
    } catch (WSFederationMetaException e) {
        debug.warning("WSFedPropertiesModelImpl.getServiceProviderAttributes", e);
        throw new AMConsoleException(getErrorString(e));
    }
    return (SPAttributes != null) ? SPAttributes : Collections.EMPTY_MAP;
}
Also used : WSFederationMetaManager(com.sun.identity.wsfederation.meta.WSFederationMetaManager) SPSSOConfigElement(com.sun.identity.wsfederation.jaxb.entityconfig.SPSSOConfigElement) WSFederationMetaException(com.sun.identity.wsfederation.meta.WSFederationMetaException) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

WSFederationMetaManager (com.sun.identity.wsfederation.meta.WSFederationMetaManager)31 WSFederationMetaException (com.sun.identity.wsfederation.meta.WSFederationMetaException)20 List (java.util.List)13 FederationElement (com.sun.identity.wsfederation.jaxb.wsfederation.FederationElement)12 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)11 JAXBException (javax.xml.bind.JAXBException)10 Iterator (java.util.Iterator)9 CLIException (com.sun.identity.cli.CLIException)8 ArrayList (java.util.ArrayList)8 WSFederationException (com.sun.identity.wsfederation.common.WSFederationException)7 HashMap (java.util.HashMap)7 SPSSOConfigElement (com.sun.identity.wsfederation.jaxb.entityconfig.SPSSOConfigElement)6 Map (java.util.Map)6 SessionException (com.sun.identity.plugin.session.SessionException)5 Set (java.util.Set)5 BaseConfigType (com.sun.identity.wsfederation.jaxb.entityconfig.BaseConfigType)4 FederationConfigElement (com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement)4 IDPSSOConfigElement (com.sun.identity.wsfederation.jaxb.entityconfig.IDPSSOConfigElement)4 TokenIssuerEndpointElement (com.sun.identity.wsfederation.jaxb.wsfederation.TokenIssuerEndpointElement)4 IOException (java.io.IOException)4