view Agendas/trunk/src/Agendas.Web/Controllers/CustomAuthorizeAttribute.cs @ 288:a6037c6c88d8

Se soluciona bug #198 Bug: Summary incorrecto en Google Calendar. Se parametriza la hora en el mensaje.
author user@MECHUQUE
date Mon, 30 Jan 2012 01:52:47 -0300
parents 2d02adb79322
children
line wrap: on
line source

using System.Web;
using System.Web.Mvc;
using AltNetHispano.Agendas.Domain;
using AltNetHispano.Agendas.Factories;

namespace AltNetHispano.Agendas.Web.Controllers
{
	public class CustomAuthorizeAttribute : AuthorizeAttribute
	{
		public string RedirectResultUrl { get; set; }

		public CustomAuthorizeAttribute()
		{
			RedirectResultUrl = "~/Error/NoAutorizado";
		}

		protected override bool AuthorizeCore(HttpContextBase httpContext)
		{
			if (!httpContext.User.Identity.IsAuthenticated || !IdentityContext.IsAuthenticated())
				return false;

			if (!string.IsNullOrWhiteSpace(Roles))
			{
				using (NHibernateFactory.GetSessionScope())
				{
					var roles = Roles.Split(',');
					if (!IdentityContext.IsInRole(roles))
					{
						httpContext.Response.StatusCode = 403;
						return false;
					}
				}
			}

			return true;
		}

		protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
		{
			if (filterContext.HttpContext.Response.StatusCode == 403)
				filterContext.Result = new RedirectResult(RedirectResultUrl);
			else
				base.HandleUnauthorizedRequest(filterContext);
		}
	}
}