use of com.sun.identity.saml2.meta.SAML2MetaException in project OpenAM by OpenRock.
the class CreateMetaDataTemplate method buildDescriptorTemplate.
private void buildDescriptorTemplate() throws CLIException {
Writer pw = null;
try {
boolean writeToFile = !isWebBased && (metadata != null) && (metadata.length() > 0);
if (writeToFile) {
pw = new PrintWriter(new FileWriter(metadata));
} else {
pw = new StringWriter();
}
String xml = CreateSAML2HostedProviderTemplate.buildMetaDataTemplate(entityID, getWorkflowParamMap(), protocol + "://" + host + ":" + port + deploymentURI);
pw.write(xml);
if (writeToFile) {
Object[] objs = { metadata };
getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("create-meta-template-created-descriptor-template"), objs));
}
} catch (SAML2MetaException e) {
throw new CLIException(e.getMessage(), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} catch (IOException e) {
Object[] objs = { metadata };
throw new CLIException(MessageFormat.format(getResourceString("cannot-write-to-file"), objs), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
} finally {
if ((pw != null) && (pw instanceof PrintWriter)) {
((PrintWriter) pw).close();
} else {
this.getOutputWriter().printlnMessage(((StringWriter) pw).toString());
}
}
}
use of com.sun.identity.saml2.meta.SAML2MetaException in project OpenAM by OpenRock.
the class ExportMetaData method runExportExtended.
private void runExportExtended() throws CLIException {
OutputStream os = null;
String out = (isWebBase) ? "web" : extendedData;
Object[] objs = { out };
Object[] objs2 = { entityID, realm };
try {
SAML2MetaManager metaManager = new SAML2MetaManager(ssoToken);
EntityConfigElement 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);
}
SAML2MetaUtils.convertJAXBToOutputStream(config, os);
if (isWebBase) {
getOutputWriter().printlnMessage(os.toString());
}
getOutputWriter().printlnMessage(MessageFormat.format(getResourceString("export-entity-export-config-succeeded"), objs));
} catch (SAML2MetaException 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
}
}
}
}
use of com.sun.identity.saml2.meta.SAML2MetaException in project OpenAM by OpenRock.
the class ExportMetaData method runExportMetaSign.
private void runExportMetaSign() throws CLIException {
PrintWriter pw = null;
String out = (isWebBase) ? "web" : metadata;
Object[] objs = { out };
try {
SAML2MetaManager metaManager = new SAML2MetaManager(ssoToken);
EntityDescriptorElement 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);
}
Document doc = SAML2MetaSecurityUtils.sign(realm, descriptor);
if (doc == null) {
runExportMeta();
return;
} else {
String xmlstr = XMLUtils.print(doc);
xmlstr = workaroundAbstractRoleDescriptor(xmlstr);
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 (SAML2MetaException 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();
}
}
}
use of com.sun.identity.saml2.meta.SAML2MetaException in project OpenAM by OpenRock.
the class ImportBulkFederationData method saml2GetRoleAndEntityId.
private void saml2GetRoleAndEntityId() throws CLIException {
try {
SAML2MetaManager saml2Mgr = new SAML2MetaManager(ssoToken);
String role = saml2Mgr.getRoleByMetaAlias(metaAlias);
if (role.equals(SAML2Constants.UNKNOWN_ROLE)) {
Object[] param = { metaAlias };
throw new CLIException(MessageFormat.format(getResourceString("import-bulk-federation-data-unknown-metaalias"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
isIDP = role.equals(SAML2Constants.IDP_ROLE);
localEntityId = saml2Mgr.getEntityByMetaAlias(metaAlias);
} catch (SAML2MetaException e) {
debugError("ImportBulkFederationData.idffGetRoleAndEntityId", e);
Object[] param = { metaAlias };
throw new CLIException(MessageFormat.format(getResourceString("import-bulk-federation-data-unknown-metaalias"), param), ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
}
}
use of com.sun.identity.saml2.meta.SAML2MetaException in project OpenAM by OpenRock.
the class ImportEntityModelImpl method createSAMLv2Entity.
private void createSAMLv2Entity() throws AMConsoleException {
try {
EntityConfigElement configElt = null;
if (extendedMetaData != null) {
configElt = getEntityConfigElement();
if (configElt != null && configElt.isHosted()) {
List config = configElt.getIDPSSOConfigOrSPSSOConfigOrAuthnAuthorityConfig();
if (!config.isEmpty()) {
BaseConfigType bConfig = (BaseConfigType) config.iterator().next();
// get the realm from the extended meta and use
// for import
realm = SAML2MetaUtils.getRealmByMetaAlias(bConfig.getMetaAlias());
}
}
}
SAML2MetaManager metaManager = new SAML2MetaManager();
if (standardMetaData != null) {
importSAML2MetaData(metaManager, realm);
}
if (configElt != null) {
metaManager.createEntityConfig(realm, configElt);
}
} catch (SAML2MetaException e) {
throw new AMConsoleException(e);
}
}
Aggregations