Ejemplo n.º 1
0
        public static string GetPermissionNameWithAuthLevel(string serviceName, AuthorizationLevel authorizationLevel)
        {
            var permissionName = string.Join(".", new List <string> {
                ApplicationKey, serviceName, authorizationLevel.ToString()
            });

            return(permissionName);
        }
Ejemplo n.º 2
0
        private ClaimsPrincipal CreatePrincipal(AuthorizationLevel level)
        {
            var claims = new List <Claim>
            {
                new Claim(SecurityConstants.AuthLevelClaimType, level.ToString())
            };

            return(new ClaimsPrincipal(new ClaimsIdentity(claims, "Test")));
        }
Ejemplo n.º 3
0
        private void updateOperatorMsgHandler(OperatorResponseMessage msg)
        {
            if (msg.PortNo != thisPortNo)
            {
                return;
            }
            AuthorizationLevel authLevel = msg.authLevel;

            BusyOp         = false;
            OperatorStatus = authLevel == AuthorizationLevel.InvalidUser ? "../Images/CheckBoxRed.png" : "../Images/CheckBoxGreen.png";
            if (authLevel == AuthorizationLevel.InvalidUser)
            {
                if (!string.IsNullOrEmpty(OperatorID))
                {
                    Application.Current.Dispatcher.Invoke((Action) delegate
                    {
                        var vm = new DialogViewModel($"Invalid Operator ID {OperatorID} entered! Please re-enter", "", "Ok");
                        dialogService.ShowDialog(vm);
                        _operatorID = "";
                        Messenger.Default.Send(new ReFocusMessage("OperatorField", null));
                        Engineer = false;
                    });
                }
            }
            else if (authLevel == AuthorizationLevel.Engineer)
            {
                IsRecipeOverridable = true;
                Engineer            = true;
                Messenger.Default.Send(new ReFocusMessage("ToolField", null));
                RaisePropertyChanged(nameof(OperatorID));
                RaisePropertyChanged(nameof(OperatorLevel));
            }
            else
            {
                IsRecipeOverridable = false;
                Engineer            = false;
                RaisePropertyChanged(nameof(OperatorID));
                RaisePropertyChanged(nameof(OperatorLevel));
            }

            if (authLevel != AuthorizationLevel.InvalidUser)
            {
                Messenger.Default.Send(new CurrentOperatorMessage(thisPortNo, OperatorID, authLevel));
            }

            OperatorLevel = authLevel.ToString();
            MyLog.Debug($"MES->ValidateEmployee->UpdateOperatorMsgHandler sets OperatorLevel=({OperatorLevel})");

            //RaisePropertyChanged(nameof(OperatorID));
            //RaisePropertyChanged(nameof(OperatorLevel));

            //if (string.IsNullOrEmpty(_operatorID))
            //    Messenger.Default.Send(new ReFocusMessage("OperatorField", null));
            //else
            //    Messenger.Default.Send(new ReFocusMessage(string.Empty, null));
        }
        private async Task TestAuthorizationAsync(
            AuthorizationLevel claimAuthLevel,
            AuthorizationLevel requiredFunctionLevel,
            bool expectSuccess = true,
            Mock <FunctionDescriptor> descriptor = null)
        {
            descriptor = descriptor ?? CreateDefaultDescriptor(requiredFunctionLevel);

            var authHandler = new FunctionAuthorizationHandler();

            var requirements = new IAuthorizationRequirement[] { new FunctionAuthorizationRequirement() };
            var claims       = new List <Claim>
            {
                new Claim(SecurityConstants.AuthLevelClaimType, claimAuthLevel.ToString())
            };

            var user = new ClaimsPrincipal(new ClaimsIdentity(claims, "Test"));

            var authHandlerContext = new AuthorizationHandlerContext(requirements, user, descriptor.Object);
            await authHandler.HandleAsync(authHandlerContext);

            Assert.Equal(expectSuccess, authHandlerContext.HasSucceeded);
        }