final DateTime issuedAt = response.getIssueInstant();
final Service service = getAssertionFrom(model).getService();
// Build up the SAML assertion containing AuthenticationStatement and AttributeStatement
final Assertion assertion = newSamlObject(Assertion.class);
assertion.setID(generateId());
assertion.setIssueInstant(issuedAt);
assertion.setIssuer(this.issuer);
assertion.setConditions(newConditions(issuedAt, service.getId()));
final AuthenticationStatement authnStatement = newAuthenticationStatement(authentication);
assertion.getAuthenticationStatements().add(authnStatement);
final Subject subject = newSubject(authentication.getPrincipal().getId());
final Map<String, Object> attributesToSend = prepareSamlAttributes(authentication, casAssertion);
if (!attributesToSend.isEmpty()) {
assertion.getAttributeStatements().add(newAttributeStatement(subject, attributesToSend));
}
response.setStatus(newStatus(StatusCode.SUCCESS, null));
response.getAssertions().add(assertion);
}