1 //------------------------------------------------------------------------------
2 // <copyright file="FormsIdentity.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
10 * Copyright (c) 1999 Microsoft Corporation
13 namespace System.Web.Security {
14 using System.Collections.Generic;
15 using System.Runtime.InteropServices;
16 using System.Runtime.Serialization;
17 using System.Security;
18 using System.Security.Claims;
19 using System.Security.Permissions;
22 /// This class is an IIdentity derived class
23 /// used by FormsAuthenticationModule. It provides a way for an application to
24 /// access the cookie authentication ticket.
28 public class FormsIdentity : ClaimsIdentity {
31 /// The name of the identity (in this case, the
32 /// passport user name).
34 public override String Name { get { return _Ticket.Name;}}
37 /// The type of the identity (in this case,
40 public override String AuthenticationType { get { return "Forms";}}
43 /// Indicates whether or not authentication took
46 public override bool IsAuthenticated { get { return true;}}
48 private FormsAuthenticationTicket _Ticket;
51 /// Returns the FormsAuthenticationTicket
52 /// associated with the current request.
54 public FormsAuthenticationTicket Ticket { get { return _Ticket;}}
56 public override IEnumerable<Claim> Claims
67 public FormsIdentity (FormsAuthenticationTicket ticket) {
69 throw new ArgumentNullException("ticket");
79 protected FormsIdentity(FormsIdentity identity)
82 _Ticket = identity._Ticket;
86 /// Returns a new instance of <see cref="FormsIdentity"/> with values copied from this object.
88 public override ClaimsIdentity Clone()
90 return new FormsIdentity(this);
94 private void OnDeserializedMethod(StreamingContext context)
96 // FormIdentities that have been deserialized from a .net 4.0 runtime, will not have any claims.
97 // In this case add a name claim, otherwise assume it was deserialized.
99 bool claimFound = false;
100 foreach (Claim c in base.Claims)
112 [SecuritySafeCritical]
113 private void AddNameClaim()
115 if (_Ticket != null && _Ticket.Name != null)
117 base.AddClaim(new Claim(base.NameClaimType, _Ticket.Name, ClaimValueTypes.String, "Forms", "Forms", this));