/// <summary> /// Gets the security role for the given parameters. /// </summary> /// <param name="roleName">Name of the role.</param> /// <param name="request">The request.</param> /// <returns>Returns the security role for the given role name, with its permissions</returns> public static SecurityRol GetSecurityRole(string roleName, HttpRequestBase request) { var cacheKey = GetRoleCacheKey(roleName); var securityRole = HttpContext.Current.Cache[cacheKey] as SecurityRol; if (securityRole == null) { var strFilePath = request.MapPath("~/Security/Roles/" + roleName + ".xml"); var xdoc = new XmlDocument(); xdoc.Load(strFilePath); if (xdoc.DocumentElement != null) { securityRole = new SecurityRol(roleName, xdoc.DocumentElement); HttpContext.Current.Cache.Insert(cacheKey, securityRole, new CacheDependency(strFilePath)); } } return securityRole; }
/// <summary> /// Gets the security role for the given parameters. /// </summary> /// <param name="roleName">Name of the role.</param> /// <param name="request">The request.</param> /// <returns>Returns the security role for the given role name, with its permissions</returns> public static SecurityRol GetSecurityRole(string roleName, HttpRequestBase request) { var cacheKey = GetRoleCacheKey(roleName); var securityRole = HttpContext.Current.Cache[cacheKey] as SecurityRol; if (securityRole == null) { var strFilePath = request.MapPath("~/Security/Roles/" + roleName + ".xml"); var xdoc = new XmlDocument(); xdoc.Load(strFilePath); if (xdoc.DocumentElement != null) { securityRole = new SecurityRol(roleName, xdoc.DocumentElement); HttpContext.Current.Cache.Insert(cacheKey, securityRole, new CacheDependency(strFilePath)); } } return(securityRole); }
/// <summary> /// Validates the action execution. /// </summary> /// <param name="securityRole">The security role.</param> /// <param name="action">The action.</param> /// <param name="controller">The controller.</param> private static void ValidateActionExecution(SecurityRol securityRole, string action, string controller) { if (!securityRole.AllowAction(action, controller)) { throw GetUnautorizedException(controller, action); } }