if (nameId == null) {
log.warn("Received assertion not processed because it doesn't contain a valid subject.");
return null;
}
SamlPrincipalImpl principal = new SamlPrincipalImpl();
principal.setAssertion(assertion);
principal.setNameId(new SamlNameIdImpl(nameId.getValue(), nameId.getFormat(), nameId.getNameQualifier()));
SamlSpSessionImpl session = new SamlSpSessionImpl();
session.setSessionIndex(authnStatement.getSessionIndex());
session.setPrincipal(principal);
session.setIdentityProvider(idp);
for (StatementAbstractType statement : assertion.getStatementOrAuthnStatementOrAuthzDecisionStatement()) {
if (statement instanceof AttributeStatementType) {
AttributeStatementType attributeStatement = (AttributeStatementType) statement;
List<AttributeType> attributes = new LinkedList<AttributeType>();
for (Object object : attributeStatement.getAttributeOrEncryptedAttribute()) {
if (object instanceof AttributeType) {
attributes.add((AttributeType) object);
} else {
log.warn("Encrypted attributes are not supported. Ignoring the attribute.");
}
}
principal.setAttributes(attributes);
}
}
return session;
}