public WsFederationCredential createCredentialFromToken ( final Assertion assertion ) { val retrievedOn = ZonedDateTime . now ( ZoneOffset . UTC ) ; LOGGER . debug ( "Retrieved on [{}]" , retrievedOn ) ; val credential = new WsFederationCredential ( ) ; credential . setRetrievedOn ( retrievedOn ) ; credential . setId ( assertion . getID ( ) ) ; credential . setIssuer ( assertion . getIssuer ( ) ) ; credential . setIssuedOn ( ZonedDateTime . parse ( assertion . getIssueInstant ( ) . toDateTimeISO ( ) . toString ( ) ) ) ; val conditions = assertion . getConditions ( ) ; if ( conditions != null ) { credential . setNotBefore ( ZonedDateTime . parse ( conditions . getNotBefore ( ) . toDateTimeISO ( ) . toString ( ) ) ) ; credential . setNotOnOrAfter ( ZonedDateTime . parse ( conditions . getNotOnOrAfter ( ) . toDateTimeISO ( ) . toString ( ) ) ) ; if ( ! conditions . getAudienceRestrictionConditions ( ) . isEmpty ( ) ) { credential . setAudience ( conditions . getAudienceRestrictionConditions ( ) . get ( 0 ) . getAudiences ( ) . get ( 0 ) . getUri ( ) ) ; } } if ( ! assertion . getAuthenticationStatements ( ) . isEmpty ( ) ) { credential . setAuthenticationMethod ( assertion . getAuthenticationStatements ( ) . get ( 0 ) . getAuthenticationMethod ( ) ) ; } //retrieve an attributes from the assertion val attributes = new HashMap < String , List < Object > > ( ) ; assertion . getAttributeStatements ( ) . stream ( ) . flatMap ( attributeStatement -> attributeStatement . getAttributes ( ) . stream ( ) ) . forEach ( item -> { LOGGER . debug ( "Processed attribute: [{}]" , item . getAttributeName ( ) ) ; final List < Object > itemList = item . getAttributeValues ( ) . stream ( ) . map ( xmlObject -> ( ( XSAny ) xmlObject ) . getTextContent ( ) ) . collect ( Collectors . toList ( ) ) ; if ( ! itemList . isEmpty ( ) ) { attributes . put ( item . getAttributeName ( ) , itemList ) ; } } ) ; credential . setAttributes ( attributes ) ; LOGGER . debug ( "Credential: [{}]" , credential ) ; return credential ; }
createCredentialFromToken converts a SAML 1 . 1 assertion to a WSFederationCredential .