/
SecurityToken.cs
60 lines (49 loc) · 2.15 KB
/
SecurityToken.cs
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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.ObjectModel;
using System.ServiceModel;
namespace System.IdentityModel.Tokens
{
public abstract class SecurityToken
{
public abstract string Id { get; }
public abstract ReadOnlyCollection<SecurityKey> SecurityKeys { get; }
public abstract DateTime ValidFrom { get; }
public abstract DateTime ValidTo { get; }
public virtual bool CanCreateKeyIdentifierClause<T>() where T : SecurityKeyIdentifierClause
{
return ((typeof(T) == typeof(LocalIdKeyIdentifierClause)) && CanCreateLocalKeyIdentifierClause());
}
public virtual T CreateKeyIdentifierClause<T>() where T : SecurityKeyIdentifierClause
{
if ((typeof(T) == typeof(LocalIdKeyIdentifierClause)) && CanCreateLocalKeyIdentifierClause())
{
return new LocalIdKeyIdentifierClause(Id, GetType()) as T;
}
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(
SRP.Format(SRP.TokenDoesNotSupportKeyIdentifierClauseCreation, GetType().Name, typeof(T).Name)));
}
public virtual bool MatchesKeyIdentifierClause(SecurityKeyIdentifierClause keyIdentifierClause)
{
LocalIdKeyIdentifierClause localKeyIdentifierClause = keyIdentifierClause as LocalIdKeyIdentifierClause;
if (localKeyIdentifierClause != null)
{
return localKeyIdentifierClause.Matches(Id, GetType());
}
return false;
}
public virtual SecurityKey ResolveKeyIdentifierClause(SecurityKeyIdentifierClause keyIdentifierClause)
{
if (SecurityKeys.Count != 0 && MatchesKeyIdentifierClause(keyIdentifierClause))
{
return SecurityKeys[0];
}
return null;
}
private bool CanCreateLocalKeyIdentifierClause()
{
return (Id != null);
}
}
}