2 // System.Web.Security.Roles
5 // Ben Maurer (bmaurer@users.sourceforge.net)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
32 using System.Collections;
33 using System.Collections.Specialized;
36 namespace System.Web.Security
38 public sealed class Roles
40 public static void AddUsersToRole (string [] usernames, string rolename)
42 Provider.AddUsersToRoles (usernames, new string[] {rolename});
45 public static void AddUsersToRoles (string [] usernames, string [] rolenames)
47 Provider.AddUsersToRoles (usernames, rolenames);
50 public static void AddUserToRole (string username, string rolename)
52 Provider.AddUsersToRoles (new string[] {username}, new string[] {rolename});
55 public static void AddUserToRoles (string username, string [] rolenames)
57 Provider.AddUsersToRoles (new string[] {username}, rolenames);
60 public static void CreateRole (string rolename)
62 Provider.CreateRole (rolename);
66 public static void DeleteCookie ()
68 throw new NotImplementedException ();
71 public static bool DeleteRole (string rolename)
73 return Provider.DeleteRole (rolename, true);
76 public static bool DeleteRole (string rolename, bool throwOnPopulatedRole)
78 return Provider.DeleteRole (rolename, throwOnPopulatedRole);
81 public static string [] GetAllRoles ()
83 return Provider.GetAllRoles ();
86 public static string [] GetRolesForUser ()
88 return Provider.GetRolesForUser (CurrentUser);
91 static string CurrentUser {
93 if (HttpContext.Current != null && HttpContext.Current.User != null)
94 return HttpContext.Current.User.Identity.Name;
96 return System.Threading.Thread.CurrentPrincipal.Identity.Name;
100 public static string [] GetRolesForUser (string username)
102 return Provider.GetRolesForUser (username);
105 public static string [] GetUsersInRole (string rolename)
107 return Provider.GetUsersInRole (rolename);
110 public static bool IsUserInRole (string rolename)
112 return Provider.IsUserInRole (CurrentUser, rolename);
115 public static bool IsUserInRole (string username, string rolename)
117 return Provider.IsUserInRole (username, rolename);
120 public static void RemoveUserFromRole (string username, string rolename)
122 Provider.RemoveUsersFromRoles (new string[] {username}, new string[] {rolename});
125 public static void RemoveUserFromRoles (string username, string [] rolenames)
127 Provider.RemoveUsersFromRoles (new string[] {username}, rolenames);
130 public static void RemoveUsersFromRole (string [] usernames, string rolename)
132 Provider.RemoveUsersFromRoles (usernames, new string[] {rolename});
135 public static void RemoveUsersFromRoles (string [] usernames, string [] rolenames)
137 Provider.RemoveUsersFromRoles (usernames, rolenames);
140 public static bool RoleExists (string rolename)
142 return Provider.RoleExists (rolename);
145 public static string[] FinsUsersInRole (string rolename, string usernameToMatch)
147 return Provider.FindUsersInRole (rolename, usernameToMatch);
150 public static string ApplicationName {
151 get { return Provider.ApplicationName; }
152 set { Provider.ApplicationName = value; }
156 public static bool CacheRolesInCookie {
157 get { throw new NotImplementedException (); }
161 public static string CookieName {
162 get { throw new NotImplementedException (); }
166 public static string CookiePath {
167 get { throw new NotImplementedException (); }
171 public static CookieProtection CookieProtectionValue {
172 get { throw new NotImplementedException (); }
176 public static bool CookieRequireSSL {
177 get { throw new NotImplementedException (); }
181 public static bool CookieSlidingExpiration {
182 get { throw new NotImplementedException (); }
186 public static int CookieTimeout {
187 get { throw new NotImplementedException (); }
191 public static bool Enabled {
192 get { throw new NotImplementedException (); }
196 public static RoleProvider Provider {
197 get { throw new NotImplementedException (); }
201 public static RoleProviderCollection Providers {
202 get { throw new NotImplementedException (); }