Switch to compiler-tester
[mono.git] / mcs / class / System.Web / System.Web.Security / Roles.cs
1 //
2 // System.Web.Security.Roles
3 //
4 // Authors:
5 //      Ben Maurer (bmaurer@users.sourceforge.net)
6 //
7 // (C) 2003 Ben Maurer
8 //
9
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 #if NET_2_0
32 using System.Collections;
33 using System.Collections.Specialized;
34 using System.Text;
35
36 namespace System.Web.Security
37 {
38         public sealed class Roles
39         {
40                 public static void AddUsersToRole (string [] usernames, string rolename)
41                 {
42                         Provider.AddUsersToRoles (usernames, new string[] {rolename});
43                 }
44                 
45                 public static void AddUsersToRoles (string [] usernames, string [] rolenames)
46                 {
47                         Provider.AddUsersToRoles (usernames, rolenames);
48                 }
49                 
50                 public static void AddUserToRole (string username, string rolename)
51                 {
52                         Provider.AddUsersToRoles (new string[] {username}, new string[] {rolename});
53                 }
54                 
55                 public static void AddUserToRoles (string username, string [] rolenames)
56                 {
57                         Provider.AddUsersToRoles (new string[] {username}, rolenames);
58                 }
59                 
60                 public static void CreateRole (string rolename)
61                 {
62                         Provider.CreateRole (rolename);
63                 }
64                 
65                 [MonoTODO]
66                 public static void DeleteCookie ()
67                 {
68                         throw new NotImplementedException ();
69                 }
70                 
71                 public static bool DeleteRole (string rolename)
72                 {
73                         return Provider.DeleteRole (rolename, true);
74                 }
75                 
76                 public static bool DeleteRole (string rolename, bool throwOnPopulatedRole)
77                 {
78                         return Provider.DeleteRole (rolename, throwOnPopulatedRole);
79                 }
80                 
81                 public static string [] GetAllRoles ()
82                 {
83                         return Provider.GetAllRoles ();
84                 }
85                 
86                 public static string [] GetRolesForUser ()
87                 {
88                         return Provider.GetRolesForUser (CurrentUser);
89                 }
90                 
91                 static string CurrentUser {
92                         get {
93                                 if (HttpContext.Current != null && HttpContext.Current.User != null)
94                                         return HttpContext.Current.User.Identity.Name;
95                                 else
96                                         return System.Threading.Thread.CurrentPrincipal.Identity.Name;
97                         }
98                 }
99                 
100                 public static string [] GetRolesForUser (string username)
101                 {
102                         return Provider.GetRolesForUser (username);
103                 }
104                 
105                 public static string [] GetUsersInRole (string rolename)
106                 {
107                         return Provider.GetUsersInRole (rolename);
108                 }
109                 
110                 public static bool IsUserInRole (string rolename)
111                 {
112                         return Provider.IsUserInRole (CurrentUser, rolename);
113                 }
114                 
115                 public static bool IsUserInRole (string username, string rolename)
116                 {
117                         return Provider.IsUserInRole (username, rolename);
118                 }
119                 
120                 public static void RemoveUserFromRole (string username, string rolename)
121                 {
122                         Provider.RemoveUsersFromRoles (new string[] {username}, new string[] {rolename});
123                 }
124                 
125                 public static void RemoveUserFromRoles (string username, string [] rolenames)
126                 {
127                         Provider.RemoveUsersFromRoles (new string[] {username}, rolenames);
128                 }
129                 
130                 public static void RemoveUsersFromRole (string [] usernames, string rolename)
131                 {
132                         Provider.RemoveUsersFromRoles (usernames, new string[] {rolename});
133                 }
134                 
135                 public static void RemoveUsersFromRoles (string [] usernames, string [] rolenames)
136                 {
137                         Provider.RemoveUsersFromRoles (usernames, rolenames);
138                 }
139                 
140                 public static bool RoleExists (string rolename)
141                 {
142                         return Provider.RoleExists (rolename);
143                 }
144                 
145                 public static string[] FinsUsersInRole (string rolename, string usernameToMatch)
146                 {
147                         return Provider.FindUsersInRole (rolename, usernameToMatch);
148                 }
149                 
150                 public static string ApplicationName {
151                         get { return Provider.ApplicationName; }
152                         set { Provider.ApplicationName = value; }
153                 }
154                 
155                 [MonoTODO]
156                 public static bool CacheRolesInCookie {
157                         get { throw new NotImplementedException (); }
158                 }
159                 
160                 [MonoTODO]
161                 public static string CookieName {
162                         get { throw new NotImplementedException (); }
163                 }
164                 
165                 [MonoTODO]
166                 public static string CookiePath {
167                         get { throw new NotImplementedException (); }
168                 }
169                 
170                 [MonoTODO]
171                 public static CookieProtection CookieProtectionValue {
172                         get { throw new NotImplementedException (); }
173                 }
174                 
175                 [MonoTODO]
176                 public static bool CookieRequireSSL {
177                         get { throw new NotImplementedException (); }
178                 }
179                 
180                 [MonoTODO]
181                 public static bool CookieSlidingExpiration {
182                         get { throw new NotImplementedException (); }
183                 }
184                 
185                 [MonoTODO]
186                 public static int CookieTimeout {
187                         get { throw new NotImplementedException (); }
188                 }
189                 
190                 [MonoTODO]
191                 public static bool Enabled {
192                         get { throw new NotImplementedException (); }
193                 }
194                 
195                 [MonoTODO]
196                 public static RoleProvider Provider {
197                         get { throw new NotImplementedException (); }
198                 }
199                 
200                 [MonoTODO]
201                 public static RoleProviderCollection Providers {
202                         get { throw new NotImplementedException (); }
203                 }
204         }
205 }
206 #endif
207