コード例 #1
0
        public bool Authorize([NotNull] DashboardContext context)
        {
            var owinContext = new OwinContext(context.GetOwinEnvironment());

            // Allow all authenticated users to see the Dashboard (potentially dangerous).
            return(owinContext.Authentication.User.Identity.IsAuthenticated);
        }
コード例 #2
0
        public bool Authorize(DashboardContext context)
        {
            var owinContext = new OwinContext(context.GetOwinEnvironment());
            var isUserAdmin = owinContext.Authentication.User.IsAdmin();

            return(isUserAdmin);
        }
コード例 #3
0
ファイル: Startup.cs プロジェクト: xasermail/AtlantCRM
        public bool Authorize(DashboardContext context)
        {
            // получаем структуру, в которой в том числе хранятся данные об авторизации текущего пользователя
            OwinContext owinContext = new OwinContext(context.GetOwinEnvironment());

            // если пользователь аутентифицирован (вошёл в систему)
            if (owinContext.Authentication.User.Identity.IsAuthenticated)
            {
                // и вошёл под логином admin
                if (owinContext.Authentication.User.Identity.Name.ToUpper() == "admin".ToUpper())
                {
                    // то допускаю его до консоли управления hangfire
                    return(true);

                    // во всех остальных случаях доступ запрещён
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
コード例 #4
0
        public virtual bool Authorize([NotNull] DashboardContext context)
        {
            IOwinContext owinContext     = new OwinContext(context.GetOwinEnvironment());
            bool         isAuthenticated = owinContext.GetDependencyResolver().Resolve <IUserInformationProvider>().IsAuthenticated();

            return(isAuthenticated);
        }
コード例 #5
0
        public bool Authorize(DashboardContext context)
        {
            var owinContext = new OwinContext(context.GetOwinEnvironment());


            return(owinContext.Authentication.User.Identity.IsAuthenticated);
        }
コード例 #6
0
        public bool Authorize([NotNull] DashboardContext context)
        {
            var httpContext = new OwinContext(context.GetOwinEnvironment());
            var result      = _roles.Aggregate(false, (current, role) => current || httpContext.Authentication.User.IsInRole(role));

            return(result);
        }
コード例 #7
0
        public bool Authorize(DashboardContext context)
        {
            // In case you need an OWIN context, use the next line, `OwinContext` class
            // is the part of the `Microsoft.Owin` package.

            var owinContext = new OwinContext(context.GetOwinEnvironment());

            var user = owinContext.GetUserManager <ApplicationUserManager>().FindById(System.Web.HttpContext.Current.User.Identity.GetUserId());

            if (user == null)
            {
                return(false);
            }

            List <ApplicationRole> roles = null;

            if (HttpContext.Current.Cache["roles"] != null && false)
            {
                roles = (List <ApplicationRole>)HttpContext.Current.Cache["roles"];
            }
            else
            {
                var dbcontext = new ApplicationDbContext();
                roles = dbcontext.Roles.Include("Actions").ToList();
                HttpContext.Current.Cache["roles"] = roles;
            }

            var authorizedActions = roles.Where(t => user.Roles.Any(r => r.RoleId == t.Id)).ToList().SelectMany(t => t.Actions).ToList();

            return(authorizedActions.Any(t => t.ActionName == AppActions.Background_Job));
        }
コード例 #8
0
        public bool Authorize(DashboardContext context)
        {
            // In case you need an OWIN context, use the next line, `OwinContext` class
            // is the part of the `Microsoft.Owin` package.
            var owinContext = new OwinContext(context.GetOwinEnvironment());

            // Allow all authenticated users to see the Dashboard (potentially dangerous).
            bool boolAuthorizeCurrentUserToAccessHangFireDashboard = false;

            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                if (HttpContext.Current.User.IsInRole("Admin"))
                {
                    boolAuthorizeCurrentUserToAccessHangFireDashboard = true;
                }
            }

            return(boolAuthorizeCurrentUserToAccessHangFireDashboard);
            //if(owinContext.Authentication.User.Identity.IsAuthenticated){
            //    HttpCookie authCookie = HttpContext.Current.Request.Cookies["role"];
            //    FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);
            //    if (authTicket.Name == "role" && authTicket.UserData == "Admin")
            //    {
            //        return true;
            //    }
            //    else {
            //        return false;
            //    }
            //}
            //else{
            //    return false;
            //}
        }
コード例 #9
0
        /// <summary>
        ///     Determines whether a user may access the hangfire dashboard.
        /// </summary>
        /// <param name="aContext">Context we are accessing the dashboard in.</param>
        /// <returns>Returns TRUE should the user be allowed to access the dashboard.</returns>
        public bool Authorize(DashboardContext aContext)
        {
            // In case you need an OWIN context, use the next line, `OwinContext` class
            // is the part of the `Microsoft.Owin` package.
            OwinContext owinContext = new OwinContext(aContext.GetOwinEnvironment());

            return(true);
        }
コード例 #10
0
        public bool Authorize(DashboardContext context)
        {
            var owinContext  = new OwinContext(context.GetOwinEnvironment());
            var principal    = owinContext.Authentication.User;
            var isAuthorized = IsAuthorized(_securityService, principal);

            return(isAuthorized);
        }
コード例 #11
0
        public bool Authorize(DashboardContext context)
        {
            // In case you need an OWIN context, use the next line, `OwinContext` class
            // is the part of the `Microsoft.Owin` package.
            var owinContext = new OwinContext(context.GetOwinEnvironment());

            // Allow all authenticated users to see the Dashboard (potentially dangerous).
            return(owinContext.Authentication.User.Identity.IsAuthenticated);
        }
コード例 #12
0
        public bool Authorize(DashboardContext context)
        {
            var owinContext = new OwinContext(context.GetOwinEnvironment());
            var person      = KeystoneClaimsHelpers.GetOpenIDUserFromPrincipal(owinContext.Authentication.User,
                                                                               null,
                                                                               HttpRequestStorage.DatabaseEntities.People.GetPersonByPersonGuid);

            return(person.IsAdministrator());
        }
        public bool Authorize(DashboardContext dashboardContext)
        {
            var owinEnvironment = dashboardContext.GetOwinEnvironment();
            var owinContext     = new OwinContext(owinEnvironment);

            var currentPerson = ClaimsIdentityHelper.PersonFromClaimsIdentity(owinContext.Authentication);

            return(currentPerson.IsAdministrator());
        }
コード例 #14
0
        /// <summary>
        /// Method to return whether request is authorized
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public bool Authorize(DashboardContext context)
        {
            // In case you need an OWIN context, use the next line, `OwinContext` class
            // is the part of the `Microsoft.Owin` package.
            var owinContext = new OwinContext(context.GetOwinEnvironment());

            var isAdmin = owinContext.Authentication.User.IsInRole("Administrator");

            return(isAdmin);
        }
コード例 #15
0
        public bool Authorize(DashboardContext context)
        {
            var owinContext = new OwinContext(context.GetOwinEnvironment());

            if (owinContext.Authentication.User != null && owinContext.Authentication.User.IsInRole("ARI IT DEVELOPMENT GLOBAL"))
            {
                return(true);
            }

            return(false);
        }
コード例 #16
0
        public bool Authorize(DashboardContext context)
        {
            var owinContext = new OwinContext(context.GetOwinEnvironment());

            // Allow all authenticated users to see the Dashboard (potentially dangerous).
            if (owinContext.Authentication.User.Identity.IsAuthenticated)
            {
                return(owinContext.Authentication.User.IsInRole("PortalAdmin"));
            }
            return(false);
        }
コード例 #17
0
        public virtual bool Authorize([NotNull] DashboardContext context)
        {
#if DotNetCore
            throw new NotImplementedException();
#else
            IUserInformationProvider userInformationProvider = null;
            IOwinContext             owinContext             = new OwinContext(context.GetOwinEnvironment());
            userInformationProvider = owinContext.GetDependencyResolver().Resolve <IUserInformationProvider>();
            bool isAuthenticated = userInformationProvider.IsAuthenticated();
            return(isAuthenticated);
#endif
        }
コード例 #18
0
        public bool Authorize(DashboardContext dashboardContext)
        {
            var owinEnvironment = dashboardContext.GetOwinEnvironment();
            var owinContext     = new OwinContext(owinEnvironment);

            var userIsAdmin = owinContext
                              .Authentication
                              .User
                              .IsInRole(User.ADMIN);

            return(userIsAdmin);
        }
コード例 #19
0
        public bool Authorize(DashboardContext context)
        {
            // In case you need an OWIN context, use the next line, `OwinContext` class
            // is the part of the `Microsoft.Owin` package.
            var owinContext = new OwinContext(context.GetOwinEnvironment());

            // Allow all authenticated users to see the Dashboard (potentially dangerous).
            // return owinContext.Authentication.User.Identity.IsAuthenticated
            string userName = owinContext.Authentication.User.Identity.Name;

            return(userName == "josh.silver" || userName == "kamran.qadir");
        }
コード例 #20
0
        public virtual bool Authorize([NotNull] DashboardContext context)
        {
            IUserInformationProvider userInformationProvider = null;

#if NET461
            IOwinContext owinContext = new OwinContext(context.GetOwinEnvironment());
            userInformationProvider = owinContext.GetDependencyResolver().Resolve <IUserInformationProvider>();
#else
            userInformationProvider = Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService <IUserInformationProvider>(context.GetHttpContext().RequestServices);
#endif
            bool isAuthenticated = userInformationProvider.IsAuthenticated();
            return(isAuthenticated);
        }
コード例 #21
0
        public bool Authorize([NotNull] DashboardContext context)
        {
            var theContext = context.GetOwinEnvironment();

            var owinContext = new OwinContext(theContext);

            using (var unitOfWork = new UnitOfWork())
            {
                var userId = owinContext.Authentication.User.Identity.GetUserId();

                return(unitOfWork.Users.IsUserDeveloperAdmin(userId));
            }
        }
コード例 #22
0
        public bool Authorize(DashboardContext context)
        {
            var owinContext = new OwinContext(context.GetOwinEnvironment());

            if (!owinContext.Authentication.User.Identity.IsAuthenticated)
            {
                return(false);
            }

            var userInfo = UserController.GetUserByName(owinContext.Authentication.User.Identity.Name);

            return(userInfo.IsSuperUser);
        }
コード例 #23
0
            public bool Authorize(DashboardContext context)
            {
                //if (HttpContext.Current.User.IsInRole(Role.ADMINISTRATOR))
                //{
                //    return true;
                //}

                //return false;
                var owinContext = new OwinContext(context.GetOwinEnvironment());

                //return HttpContext.Current.User.Identity.IsAuthenticated;
                return(owinContext.Authentication.User.Identity.IsAuthenticated);
            }
コード例 #24
0
 public bool Authorize(DashboardContext context)
 {
     var owinContext = new OwinContext(context.GetOwinEnvironment());
     var identityName = owinContext.Authentication.User.Identity.Name;
     var authLevel = AuthRoles.Dev;
     TasksMenu.AuthTasks.Clear();
     foreach (var taskParameterse in TasksMenu.Tasks)
     {
         var taskAuth = taskParameterse as ITaskAuth;
         if (taskAuth == null) continue;
         if (taskAuth.AuthRoles.HasFlag(authLevel)) TasksMenu.AuthTasks.Add(taskParameterse);
     }
     return true;
 }
コード例 #25
0
        public bool Authorize(DashboardContext context)
        {
            var owinContext = new OwinContext(context.GetOwinEnvironment());

            foreach (String role in Roles)
            {
                if (owinContext.Authentication.User.IsInRole(role))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #26
0
        public bool Authorize(DashboardContext context)
        {
            try
            {
                var owinContext = new OwinContext(context.GetOwinEnvironment());

                var user = owinContext.Authentication.User;

                return
                    (user.Identity.IsAuthenticated &&
                     ApplicationPermissionAuthorizeAttribute.HasPermission(user, BusinessLayer.Authorization.ApplicationPermissionNames.BackgroundJobDashboard));
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #27
0
        public bool Authorize(DashboardContext dcontext)
        {
            string dashUsername = System.Configuration.ConfigurationManager.AppSettings["Jobs.Dashboard.Username"];
            string dashPassword = System.Configuration.ConfigurationManager.AppSettings["Jobs.Dashboard.Password"];

            OwinContext context = new OwinContext(dcontext.GetOwinEnvironment());

            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))
                        {
                            if (login == dashUsername && password == dashPassword)
                            {
                                return(true);
                            }
                            else
                            {
                                Challenge(context);
                            }
                        }
                    }
                }
            }

            //return true;// owinContext.Authentication.User.Identity.IsAuthenticated;
            return(Challenge(context));
        }
コード例 #28
0
        public bool Authorize(DashboardContext context)
        {
            var filter = new BasicAuthAuthorizationFilter(
                new BasicAuthAuthorizationFilterOptions
            {
                RequireSsl         = true,
                LoginCaseSensitive = true,
                Users = new[]
                {
                    new BasicAuthAuthorizationUser
                    {
                        Login         = ConfigurationManager.AppSettings["BasicAuth:Proximity:Key"],
                        PasswordClear = ConfigurationManager.AppSettings["BasicAuth:Proximity:Password"]
                    },
                    new BasicAuthAuthorizationUser
                    {
                        Login         = ConfigurationManager.AppSettings["BasicAuth:System:Key"],
                        PasswordClear = ConfigurationManager.AppSettings["BasicAuth:System:Password"]
                    },
                    new BasicAuthAuthorizationUser
                    {
                        Login         = ConfigurationManager.AppSettings["BasicAuth:External:Key"],
                        PasswordClear = ConfigurationManager.AppSettings["BasicAuth:External:Password"]
                    }
                }
            });

            var hasAccess = filter.Authorize(context.GetOwinEnvironment());

            if (hasAccess)
            {
                var user      = new GenericIdentity("Hangfire");
                var principal = new GenericPrincipal(user, null);
                Thread.CurrentPrincipal = principal;
            }

            return(hasAccess);
        }
コード例 #29
0
        public bool Authorize(DashboardContext context)
        {
            // In case you need an OWIN context, use the next line, `OwinContext` class
            // is the part of the `Microsoft.Owin` package.

            var owinContext = new OwinContext(context.GetOwinEnvironment());

            if (owinContext.Request.Scheme != "https")
            {
                string redirectUri = new UriBuilder("https", owinContext.Request.Host.ToString(), 443, context.Request.Path).ToString();

                owinContext.Response.StatusCode = 301;
                owinContext.Response.Redirect(redirectUri);
                return(false);
            }
            if (owinContext.Request.IsSecure == false)
            {
                owinContext.Response.Write("Secure connection is required to access Hangfire Dashboard.");
                return(false);
            }
            var user = owinContext.Authentication.User;

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

            // Allow all authenticated users to see the Dashboard (potentially dangerous).
            string header = owinContext.Request.Headers["Authorization"];

            if (!string.IsNullOrWhiteSpace(header))
            {
                var auHeader = AuthenticationHeaderValue.Parse(header);
                if ("Basic".Equals(auHeader.Scheme, StringComparison.InvariantCultureIgnoreCase))
                {
                    var split = Encoding.UTF8
                                .GetString(Convert.FromBase64String(auHeader.Parameter))
                                .Split(':');
                    if (split.Length == 2)
                    {
                        string userId   = split[0];
                        string password = split[1];
                        if (string.Compare(userId, "yao", true) == 0 &&
                            string.Compare(password, "pass@w0rd1~", true) == 0)
                        {
                            var claims = new List <Claim>();
                            claims.Add(new Claim(ClaimTypes.Name, "yao"));
                            claims.Add(new Claim(ClaimTypes.Role, "admin"));
                            var identity = new ClaimsIdentity(claims, "HangfireLogin");
                            owinContext.Authentication.SignIn(identity);
                            return(true);
                        }
                    }
                }
            }

            return(this.Challenge(owinContext));
        }
コード例 #30
0
        public bool Authorize(DashboardContext context)
        {
            var owinContext = new OwinContext(context.GetOwinEnvironment());

            return(owinContext.Authentication.User.IsInRole("Admin"));
        }