Merge pull request #1304 from slluis/mac-proxy-autoconfig
[mono.git] / mcs / class / corlib / System.Security.Principal / GenericIdentity.cs
1 //
2 // System.Security.Principal.GenericIdentity.cs
3 //
4 // Authors:
5 //   Miguel de Icaza (miguel@ximian.com)
6 //   Marek Safar (marek.safar@gmail.com)
7 //
8 // (C) Ximian, Inc.  http://www.ximian.com
9 // Copyright (C) 2004-2006 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.Runtime.InteropServices;
32 using System.Collections.Generic;
33 #if NET_4_5
34 using System.Security.Claims;
35 #endif
36
37 namespace System.Security.Principal {
38
39         [Serializable]
40         [ComVisible (true)]
41         public class GenericIdentity :
42 #if NET_4_5
43                 ClaimsIdentity
44 #else
45                 IIdentity
46 #endif
47         {
48
49                 // field names are serialization compatible with .net
50                 private string m_name;
51                 private string m_type;
52                 
53                 public GenericIdentity (string name, string type)
54                 {
55                         if (name == null)
56                                 throw new ArgumentNullException ("name");
57
58                         if (type == null)
59                                 throw new ArgumentNullException ("type");
60
61                         m_name = name;
62                         m_type = type;
63
64 #if NET_4_5
65                         AddDefaultClaim (name);
66 #endif
67                 }
68
69                 public GenericIdentity (string name)
70                         : this (name, String.Empty)
71                 {
72                 }
73
74 #if NET_4_5
75                 protected GenericIdentity (GenericIdentity identity)
76                         : base (identity)
77                 {
78                 }
79 #endif
80
81 #if NET_4_5
82                 override
83 #else
84                 virtual
85 #endif
86                 public string AuthenticationType {
87                         get {
88                                 return m_type;
89                         }
90                 }
91
92 #if NET_4_5
93                 override
94 #else
95                 virtual
96 #endif
97                 public string Name {
98                         get {
99                                 return m_name;
100                         }
101                 }
102
103 #if NET_4_5
104                 override
105 #else
106                 virtual
107 #endif
108                 public bool IsAuthenticated {
109                         get {
110                                 return (m_name.Length > 0);
111                         }
112                 }
113
114 #if NET_4_5
115                 public override IEnumerable<Claim> Claims {
116                         get {
117                                 return base.Claims;
118                         }
119                 }
120 #endif
121         }
122 }