/* prepare the Response object to return */
// build a response object
ResponseBuilder responseBuilder = (ResponseBuilder) builderFactory.getBuilder(Response.DEFAULT_ELEMENT_NAME);
Response response = responseBuilder.buildObject();
// set a few attributes for the response
response.setID("_" + UUID.randomUUID().toString());
response.setVersion(SAMLVersion.VERSION_20);
response.setIssueInstant(new DateTime());
response.setInResponseTo(inResponseTo.getID());
/* add the Assertion element */
// build an assertion object
AssertionBuilder assertionBuilder = (AssertionBuilder) builderFactory.getBuilder(Assertion.DEFAULT_ELEMENT_NAME);
Assertion assertion = assertionBuilder.buildObject();
// set a few attributes for the assertion
assertion.setID("_" + UUID.randomUUID().toString());
assertion.setVersion(SAMLVersion.VERSION_20);
assertion.setIssueInstant(new DateTime());
// build an issuer object
IssuerBuilder issuerBuilder = (IssuerBuilder) builderFactory.getBuilder(Issuer.DEFAULT_ELEMENT_NAME);
Issuer issuer = issuerBuilder.buildObject();
String defaultEntityId = String.format("%s://%s:%s/%s/services/ProvisioningService",
request.getScheme(),
request.getServerName(),
request.getServerPort(),
PAPConfiguration.DEFAULT_WEBAPP_CONTEXT);
PAPConfiguration conf = PAPConfiguration.instance();
String issuerValue = conf.getString(PAPConfiguration.STANDALONE_SERVICE_STANZA+".entity_id", defaultEntityId);
issuer.setValue(issuerValue);
assertion.setIssuer(issuer);
/* build policy statements objects */
XACMLPolicyStatementTypeImplBuilder policyStatementBuilder = (XACMLPolicyStatementTypeImplBuilder) builderFactory.getBuilder(XACMLPolicyStatementType.TYPE_NAME_XACML20);
XACMLPolicyStatementType policyStatement = policyStatementBuilder.buildObject(Statement.DEFAULT_ELEMENT_NAME,
XACMLPolicyStatementType.TYPE_NAME_XACML20);
Iterator<XACMLObject> iterator = policyObjects.iterator();
while (iterator.hasNext()) {
XACMLObject xacmlObject = iterator.next();
if (xacmlObject instanceof PolicySetType) {
policyStatement.getPolicySets().add((PolicySetType) xacmlObject);
// if (xacmlObject instanceof PolicySetTypeString) {
// ((PolicySetTypeString) xacmlObject).releasePolicySetType();
// }
} else {
policyStatement.getPolicies().add((PolicyType) xacmlObject);
// if (xacmlObject instanceof PolicyTypeString) {
// ((PolicyTypeString) xacmlObject).releasePolicyType();
// }
}
// add the statement to the assertion
assertion.getStatements().add(policyStatement);
}
// add the assertion to the response
response.getAssertions().add(assertion);
/* add the Status element */
// build a status object
StatusBuilder statusBuilder = (StatusBuilder) builderFactory.getBuilder(Status.DEFAULT_ELEMENT_NAME);
Status status = statusBuilder.buildObject();
// build a status code object
StatusCodeBuilder statusCodeBuilder = (StatusCodeBuilder) builderFactory.getBuilder(StatusCode.DEFAULT_ELEMENT_NAME);
StatusCode statusCode = statusCodeBuilder.buildObject();
statusCode.setValue(StatusCode.SUCCESS_URI);
status.setStatusCode(statusCode);
response.setStatus(status);
return response;
}