| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Collections.Generic; |
| | | 6 | | using System.Collections.ObjectModel; |
| | | 7 | | using CoreWCF.Security; |
| | | 8 | | using CoreWCF.Runtime; |
| | | 9 | | using MSIdentitySAML = Microsoft.IdentityModel.Tokens.Saml; |
| | | 10 | | |
| | | 11 | | namespace CoreWCF.IdentityModel.Tokens |
| | | 12 | | { |
| | | 13 | | public class SamlSecurityToken : SecurityToken |
| | | 14 | | { |
| | | 15 | | private readonly ReadOnlyCollection<SecurityKey> _keys; |
| | 2 | 16 | | protected SamlSecurityToken() |
| | | 17 | | { |
| | 2 | 18 | | } |
| | | 19 | | |
| | 53 | 20 | | internal SamlSecurityToken(MSIdentitySAML.SamlSecurityToken samlSecurityToken, ReadOnlyCollection<SecurityKey> k |
| | | 21 | | { |
| | | 22 | | Fx.Assert(samlSecurityToken != null, "SamlSecurityToken can't be null"); |
| | 53 | 23 | | WrappedSamlSecurityToken = samlSecurityToken; |
| | 53 | 24 | | Initialize(samlSecurityToken.Assertion); |
| | 53 | 25 | | _keys = keys; |
| | 53 | 26 | | } |
| | | 27 | | |
| | 0 | 28 | | public SamlSecurityToken(MSIdentitySAML.SamlAssertion assertion) |
| | | 29 | | { |
| | 0 | 30 | | Initialize(assertion); |
| | 0 | 31 | | } |
| | | 32 | | |
| | | 33 | | protected void Initialize(MSIdentitySAML.SamlAssertion assertion) |
| | | 34 | | { |
| | 53 | 35 | | if (assertion != null) |
| | | 36 | | { |
| | 53 | 37 | | Assertion = assertion; |
| | | 38 | | // this.assertion.MakeReadOnly(); |
| | 53 | 39 | | SamlStatements = new List<InternalSamlSubjectStatement>(); |
| | | 40 | | } |
| | | 41 | | else |
| | 0 | 42 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(assertion)); |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | public static explicit operator MSIdentitySAML.SamlSecurityToken(SamlSecurityToken samlSecurityToken) |
| | | 46 | | { |
| | 1 | 47 | | return samlSecurityToken.WrappedSamlSecurityToken; |
| | | 48 | | } |
| | | 49 | | |
| | 28 | 50 | | public override string Id => Assertion.AssertionId; |
| | | 51 | | |
| | 1 | 52 | | internal MSIdentitySAML.SamlSecurityToken WrappedSamlSecurityToken { get; } |
| | | 53 | | |
| | 182 | 54 | | internal MSIdentitySAML.SamlAssertion Assertion { get; private set; } |
| | | 55 | | |
| | 133 | 56 | | internal SecurityToken SigningToken { get; set; } |
| | | 57 | | |
| | 57 | 58 | | internal List<InternalSamlSubjectStatement> SamlStatements { get; set; } |
| | | 59 | | |
| | | 60 | | public override DateTime ValidFrom |
| | | 61 | | { |
| | | 62 | | get |
| | | 63 | | { |
| | 0 | 64 | | if (Assertion.Conditions != null) |
| | | 65 | | { |
| | 0 | 66 | | return Assertion.Conditions.NotBefore; |
| | | 67 | | } |
| | | 68 | | |
| | 0 | 69 | | return SecurityUtils.MinUtcDateTime; |
| | | 70 | | } |
| | | 71 | | } |
| | | 72 | | |
| | | 73 | | public override DateTime ValidTo |
| | | 74 | | { |
| | | 75 | | get |
| | | 76 | | { |
| | 0 | 77 | | if (Assertion.Conditions != null) |
| | | 78 | | { |
| | 0 | 79 | | return Assertion.Conditions.NotOnOrAfter; |
| | | 80 | | } |
| | | 81 | | |
| | 0 | 82 | | return SecurityUtils.MaxUtcDateTime; |
| | | 83 | | } |
| | | 84 | | } |
| | | 85 | | |
| | 0 | 86 | | public override ReadOnlyCollection<SecurityKey> SecurityKeys => _keys; |
| | | 87 | | |
| | 98 | 88 | | public string AssertionXML { get; internal set; } |
| | | 89 | | |
| | | 90 | | } |
| | | 91 | | } |