Search in sources :

Example 21 with WSFederationMetaException

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

the class ImportMetaData method handleWSFedRequest.

private void handleWSFedRequest(RequestContext rc) throws CLIException {
    try {
        String federationID = null;
        List<String> newMetaAliases = null;
        com.sun.identity.wsfederation.jaxb.entityconfig.FederationConfigElement configElt = null;
        if (extendedData != null) {
            configElt = getWSFedEntityConfigElement();
            /*
                 * see note at the end of this class for how we decide
                 * the realm value
                 */
            if (configElt != null && configElt.isHosted()) {
                List config = configElt.getIDPSSOConfigOrSPSSOConfig();
                if (!config.isEmpty()) {
                    com.sun.identity.wsfederation.jaxb.entityconfig.BaseConfigType bConfig = (com.sun.identity.wsfederation.jaxb.entityconfig.BaseConfigType) config.iterator().next();
                    realm = WSFederationMetaUtils.getRealmByMetaAlias(bConfig.getMetaAlias());
                    newMetaAliases = getMetaAliases(config);
                }
            }
        }
        WSFederationMetaManager metaManager = new WSFederationMetaManager(ssoToken);
        if (metadata != null) {
            federationID = importWSFedMetaData();
        }
        if (configElt != null) {
            if (null != newMetaAliases && !newMetaAliases.isEmpty()) {
                metaManager.validateMetaAliasForNewEntity(realm, newMetaAliases);
            }
            metaManager.createEntityConfig(realm, configElt);
            String out = (webAccess) ? "web" : extendedData;
            Object[] objs = { out };
            getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("import-entity-succeeded"), objs));
        }
        if ((cot != null) && (cot.length() > 0) && (federationID != null)) {
            CircleOfTrustManager cotManager = new CircleOfTrustManager(ssoToken);
            if (!cotManager.isInCircleOfTrust(realm, cot, spec, federationID)) {
                cotManager.addCircleOfTrustMember(realm, cot, spec, federationID);
            }
        }
    } catch (COTException e) {
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    } catch (WSFederationMetaException e) {
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : WSFederationMetaManager(com.sun.identity.wsfederation.meta.WSFederationMetaManager) CircleOfTrustManager(com.sun.identity.cot.CircleOfTrustManager) COTException(com.sun.identity.cot.COTException) BaseConfigType(com.sun.identity.saml2.jaxb.entityconfig.BaseConfigType) CLIException(com.sun.identity.cli.CLIException) ArrayList(java.util.ArrayList) List(java.util.List) WSFederationMetaException(com.sun.identity.wsfederation.meta.WSFederationMetaException)

Example 22 with WSFederationMetaException

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

the class ListEntities method handleWSFedRequest.

private void handleWSFedRequest(RequestContext rc) throws CLIException {
    IOutput outputWriter = getOutputWriter();
    Object[] objs = { realm };
    try {
        WSFederationMetaManager metaManager = new WSFederationMetaManager(ssoToken);
        Set entities = metaManager.getAllEntities(realm);
        if ((entities == null) || entities.isEmpty()) {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("list-entities-no-entities"), objs));
        } else {
            outputWriter.printlnMessage(MessageFormat.format(getResourceString("list-entities-entity-listing"), objs));
            for (Iterator i = entities.iterator(); i.hasNext(); ) {
                String name = (String) i.next();
                outputWriter.printlnMessage("  " + name);
            }
        }
    } catch (WSFederationMetaException e) {
        debugWarning("ListEntities.handleRequest", e);
        String[] args = { realm, e.getMessage() };
        writeLog(LogWriter.LOG_ERROR, Level.INFO, "FAILED_LIST_ENTITIES", args);
        throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
    }
}
Also used : WSFederationMetaManager(com.sun.identity.wsfederation.meta.WSFederationMetaManager) Set(java.util.Set) IOutput(com.sun.identity.cli.IOutput) Iterator(java.util.Iterator) CLIException(com.sun.identity.cli.CLIException) WSFederationMetaException(com.sun.identity.wsfederation.meta.WSFederationMetaException)

Example 23 with WSFederationMetaException

use of com.sun.identity.wsfederation.meta.WSFederationMetaException 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 24 with WSFederationMetaException

use of com.sun.identity.wsfederation.meta.WSFederationMetaException 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 25 with WSFederationMetaException

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

Aggregations

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