*/
public static Document addSamlAssertion(Document dropOffInputDocument,
String commonNameInCert, String recordURI, String clientsideID,
String mailBoxURI)
{
ServiceResponseInfo sb = new ServiceResponseInfo();
// ssaf:authenticated_user element is a mandatory element in schema,
// so check for that element and if it is there add saml assertion
//element if not throw Fault.
NodeList ssafAuthenticatedUserNodeList = dropOffInputDocument
.getElementsByTagNameNS(
SSAFNodes.authenticated_user
.getNamespace(),
SSAFNodes.authenticated_user
.getLocalName());
// check for presence of ssaf:authenticated_user element
if (ssafAuthenticatedUserNodeList.getLength() > 0)
{
NodeList ssafAccountNodeList = dropOffInputDocument
.getElementsByTagNameNS(SSAFNodes.account
.getNamespace(), SSAFNodes.account
.getLocalName());
if (ssafAccountNodeList.getLength() > 0)
{
// as per schema if <ssaf:account> element is there
// user_nominal_uri attribute should be there -
// cardinality on that attribute is required.
Element ssafAccount = (Element) ssafAccountNodeList.item(0);
String userNominalURI = ssafAccount.getAttributeNS(
SSAFNodes.user_nominal_uri.getNamespace(),
SSAFNodes.user_nominal_uri.getLocalName());
if (StringUtils.isNotBlank(userNominalURI))
{
log.info("user_nominal_uri attribute value from <ssaf:account> : "
+ userNominalURI);
}
else
{
// throw FatalFault if ssaf:user_nominal_uri is not defined.
sb.noteError("ssaf:user_nominal_uri attribute in ssaf:account" +
" is not present in incoming request document");
log.error(sb.getMergedMessages());
Drop_OffUtil .throwFault(
recordURI,
clientsideID,
null,
sb, SSAFErrorTypes.REQUEST_USER_UNKNOWN,
mailBoxURI, dropOffInputDocument
.getDocumentElement());
}
// check for presence of ssaf:permission_assertions tag
NodeList permissionAssertionNodeList = dropOffInputDocument
.getElementsByTagNameNS(SSAFNodes.permission_assertions
.getNamespace(),
SSAFNodes.permission_assertions.getLocalName());
if (permissionAssertionNodeList.getLength() > 0)
{
try
{
Node nodeToAppend = dropOffInputDocument.importNode(
DomUtils.createSamlAssertionDocument(
"http://wijiscommons.org",
commonNameInCert), true);
// add saml assertion element
permissionAssertionNodeList.item(0).appendChild(
nodeToAppend);
}
catch (ParserConfigurationException e)
{
// throw FatalFault if there is any problem while
// adding saml assertion to incoming request
sb.noteError("Caught ParserConfigurationException while adding a Saml " +
"Assertion element to incoming document");
log.error(sb.getMergedMessages());
Drop_OffUtil .throwFault(
recordURI,
clientsideID,
null,
sb,
SSAFErrorTypes.NONLOGIC,
mailBoxURI, dropOffInputDocument
.getDocumentElement());
}
}
else
{ // throw FatalFault if ssaf:permission_assertions element is not present
sb.noteError("ssaf:permission_assertions element is not present" +
" in incoming request document");
log.error(sb.getMergedMessages());
Drop_OffUtil.throwFault(
recordURI,
clientsideID,
null,
sb, SSAFErrorTypes.REQUEST_USER_UNKNOWN,
mailBoxURI, dropOffInputDocument
.getDocumentElement());
}
}
else
{ // throw FatalFault if ssaf:account element is not present
sb.noteError("ssaf:account element is not present in incoming request document");
log.error(sb.getMergedMessages());
Drop_OffUtil.throwFault(
recordURI,
clientsideID,
null,
sb, SSAFErrorTypes.REQUEST_USER_UNKNOWN,
mailBoxURI, dropOffInputDocument
.getDocumentElement());
}
}
else
{
// throw FatalFault if ssaf:authenticated_user element is not present
sb.noteError("ssaf:authenticated_user element is not present in incoming request document");
log.error(sb.getMergedMessages());
Drop_OffUtil .throwFault(
recordURI,
clientsideID,
null,
sb, SSAFErrorTypes.REQUEST_USER_UNKNOWN,