IsInRole() публичный Метод

Checks if a user in in a specific role
public IsInRole ( string role ) : bool
role string
Результат bool
Пример #1
0
		public static void VerifyUserInRole (HttpContext Context, DB db, WebServiceLogin login, string role, bool @readonly)
		{
			WebServiceResponse dummy = new WebServiceResponse ();
			Authenticate (Context, db, login, dummy, @readonly);

			if (!dummy.IsInRole (role)) {
				log.InfoFormat ("The user '{0}' has the roles '{1}', and requested role is: {2}", login.User, dummy.UserRoles == null ? "<null>" : string.Join (",", dummy.UserRoles), role);
				throw new UnauthorizedException ("You don't have the required permissions.");
			}
		}
Пример #2
0
		public static void VerifyUserInRole (string remote_ip, DB db, WebServiceLogin login, string role, bool @readonly)
		{
			WebServiceResponse dummy = new WebServiceResponse ();
			Authenticate (remote_ip, db, login, dummy, @readonly);

			if (!dummy.IsInRole (role)) {
				Logger.Log (2, "The user '{0}' has the roles '{1}', and requested role is: {2}", login.User, dummy.UserRoles == null ? "<null>" : string.Join (",", dummy.UserRoles), role);
				throw new HttpException (403, "You don't have the required permissions.");
			}
		}
Пример #3
0
		public static void VerifyUserInRoles (HttpContext Context, DB db, WebServiceLogin login, string[] roles, bool @readonly)
		{
			WebServiceResponse dummy = new WebServiceResponse ();
			Authenticate (Context, db, login, dummy, @readonly);

			foreach (var role in roles) {
				if (string.IsNullOrEmpty(role))
					continue;
				if (dummy.IsInRole(role))
					return;
			}

			var userRoles = dummy.UserRoles == null ? "<null>" : string.Join(",", dummy.UserRoles);
			var requestedRoles = roles == null ? "<null>" : string.Join(",", roles);

			log.InfoFormat("The user '{0}' has the roles '{1}', and requested roles are: {2}", login.User, userRoles, requestedRoles);
			throw new UnauthorizedException("You don't have the required permissions.");
		}