| | | 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.ObjectModel; |
| | | 6 | | using CoreWCF.Security; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.IdentityModel.Tokens |
| | | 9 | | { |
| | | 10 | | public class UserNameSecurityToken : SecurityToken |
| | | 11 | | { |
| | | 12 | | private readonly string _id; |
| | | 13 | | private readonly DateTime _effectiveTime; |
| | | 14 | | public UserNameSecurityToken(string userName, string password) |
| | 2 | 15 | | : this(userName, password, SecurityUniqueId.Create().Value) |
| | | 16 | | { |
| | 2 | 17 | | } |
| | | 18 | | |
| | 20 | 19 | | public UserNameSecurityToken(string userName, string password, string id) |
| | | 20 | | { |
| | 20 | 21 | | if (userName == null) |
| | | 22 | | { |
| | 0 | 23 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(userName)); |
| | | 24 | | } |
| | | 25 | | |
| | 20 | 26 | | if (userName == string.Empty) |
| | | 27 | | { |
| | 0 | 28 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.UserNameCannotBeEmpty); |
| | | 29 | | } |
| | | 30 | | |
| | 20 | 31 | | UserName = userName; |
| | 20 | 32 | | Password = password; |
| | 20 | 33 | | _id = id; |
| | 20 | 34 | | _effectiveTime = DateTime.UtcNow; |
| | 20 | 35 | | } |
| | | 36 | | |
| | 13 | 37 | | public override string Id => _id; |
| | | 38 | | |
| | 0 | 39 | | public override ReadOnlyCollection<SecurityKey> SecurityKeys => EmptyReadOnlyCollection<SecurityKey>.Instance; |
| | | 40 | | |
| | 0 | 41 | | public override DateTime ValidFrom => _effectiveTime; |
| | | 42 | | |
| | 0 | 43 | | public override DateTime ValidTo => SecurityUtils.MaxUtcDateTime; |
| | | 44 | | |
| | 18 | 45 | | public string UserName { get; } |
| | | 46 | | |
| | 18 | 47 | | public string Password { get; } |
| | | 48 | | } |
| | | 49 | | } |