1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
//-----------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.IdentityModel.Tokens
{
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Xml.Serialization;
using System.Xml;
using System.Xml.Schema;
using System.CodeDom;
using System.Runtime.Serialization;
using System.Globalization;
using System.Threading;
using System.IdentityModel.Selectors;
using System.IdentityModel.Policy;
using System.Reflection;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.IO;
public class SamlSecurityToken : SecurityToken
{
SamlAssertion assertion;
protected SamlSecurityToken()
{
}
public SamlSecurityToken(SamlAssertion assertion)
{
Initialize(assertion);
}
protected void Initialize(SamlAssertion assertion)
{
if (assertion == null)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("assertion");
this.assertion = assertion;
this.assertion.MakeReadOnly();
}
public override string Id
{
get { return this.assertion.AssertionId; }
}
public override ReadOnlyCollection<SecurityKey> SecurityKeys
{
get
{
return this.assertion.SecurityKeys;
}
}
public SamlAssertion Assertion
{
get { return this.assertion; }
}
public override DateTime ValidFrom
{
get
{
if (this.assertion.Conditions != null)
{
return this.assertion.Conditions.NotBefore;
}
return SecurityUtils.MinUtcDateTime;
}
}
public override DateTime ValidTo
{
get
{
if (this.assertion.Conditions != null)
{
return this.assertion.Conditions.NotOnOrAfter;
}
return SecurityUtils.MaxUtcDateTime;
}
}
public override bool CanCreateKeyIdentifierClause<T>()
{
if (typeof(T) == typeof(SamlAssertionKeyIdentifierClause))
return true;
return false;
}
public override T CreateKeyIdentifierClause<T>()
{
if (typeof(T) == typeof(SamlAssertionKeyIdentifierClause))
return new SamlAssertionKeyIdentifierClause(this.Id) as T;
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.UnableToCreateTokenReference)));
}
public override bool MatchesKeyIdentifierClause(SecurityKeyIdentifierClause keyIdentifierClause)
{
SamlAssertionKeyIdentifierClause samlKeyIdentifierClause = keyIdentifierClause as SamlAssertionKeyIdentifierClause;
if (samlKeyIdentifierClause != null)
return samlKeyIdentifierClause.Matches(this.Id);
return false;
}
}
}
|