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();
}
}
}
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
}
}
}
}
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);
}
}
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));
}
}
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;
}
Aggregations