Exemple #1
0
        public bool Authorize(DashboardContext dashboardContext)
        {
            var context = new OwinContext(dashboardContext.GetOwinEnvironment());

            if (context.Authentication.User == null)
            {
                return(false);
            }

            return(context.Authentication.User.HasClaim(_type, _value));
        }
        public bool Authorize(DashboardContext dashboardContext)
        {
            OwinContext context = new OwinContext(dashboardContext.GetOwinEnvironment());

            if ((_options.SslRedirect == true) && (context.Request.Uri.Scheme != "https"))
            {
                context.Response.OnSendingHeaders(state =>
                {
                    string redirectUri = new UriBuilder("https", context.Request.Uri.Host, 443, context.Request.Uri.PathAndQuery).ToString();

                    context.Response.StatusCode = 301;
                    context.Response.Redirect(redirectUri);
                }, null);
                return(false);
            }

            if ((_options.RequireSsl == true) && (context.Request.IsSecure == false))
            {
                context.Response.Write("Secure connection is required to access Hangfire Dashboard.");
                return(false);
            }

            string header = context.Request.Headers["Authorization"];

            if (String.IsNullOrWhiteSpace(header) == false)
            {
                AuthenticationHeaderValue authValues = AuthenticationHeaderValue.Parse(header);

                if ("Basic".Equals(authValues.Scheme, StringComparison.InvariantCultureIgnoreCase))
                {
                    string parameter = Encoding.UTF8.GetString(Convert.FromBase64String(authValues.Parameter));
                    var    parts     = parameter.Split(':');

                    if (parts.Length > 1)
                    {
                        string login    = parts[0];
                        string password = parts[1];

                        if ((String.IsNullOrWhiteSpace(login) == false) && (String.IsNullOrWhiteSpace(password) == false))
                        {
                            return(_options
                                   .Users
                                   .Any(user => user.Validate(login, password, _options.LoginCaseSensitive)) ||
                                   Challenge(context));
                        }
                    }
                }
            }

            return(Challenge(context));
        }
        public bool Authorize(DashboardContext dashboardContext)
        {
            var        context = new OwinContext(dashboardContext.GetOwinEnvironment());
            IPrincipal user    = context.Authentication.User;

            if (user == null || user.Identity == null || !user.Identity.IsAuthenticated)
            {
                return(false);
            }

            if (_usersSplit.Length > 0 && !_usersSplit.Contains(user.Identity.Name, StringComparer.OrdinalIgnoreCase))
            {
                return(false);
            }

            if (_rolesSplit.Length > 0 && !_rolesSplit.Any(user.IsInRole))
            {
                return(false);
            }

            return(true);
        }
 public bool Authorize(DashboardContext context)
 {
     return(Authorize(context.GetOwinEnvironment()));
 }