/**
   * Consumes the assertion, resulting in the extraction of the Subject as the JAAS principal and
   * the Role Statements as the JAAS roles.
   *
   * @param assertion
   * @throws Exception
   */
  private SimplePrincipal consumeAssertion(AssertionType assertion) throws Exception {
    SubjectType samlSubjectType = assertion.getSubject();
    String samlSubject = ((NameIDType) samlSubjectType.getSubType().getBaseID()).getValue();

    SimplePrincipal identity = new SimplePrincipal(samlSubject);

    Set<StatementAbstractType> statements = assertion.getStatements();
    for (StatementAbstractType statement : statements) {
      if (statement instanceof AttributeStatementType) {
        AttributeStatementType attrStatement = (AttributeStatementType) statement;
        List<ASTChoiceType> attributes = attrStatement.getAttributes();
        for (ASTChoiceType astChoiceType : attributes) {
          if (astChoiceType.getAttribute() != null
              && astChoiceType.getAttribute().getName().equals("Role")) { // $NON-NLS-1$
            List<Object> values = astChoiceType.getAttribute().getAttributeValue();
            for (Object roleValue : values) {
              if (roleValue != null) {
                identity.addRole(roleValue.toString());
              }
            }
          }
        }
      }
    }

    TL_principal.set(identity);

    return identity;
  }