Exemplo n.º 1
0
        public void Two_keys_with_different_values_by_case()
        {
            var one = new PermissionKey("one");
            var two = new PermissionKey("ONE");

            one.ShouldBe(two);
        }
Exemplo n.º 2
0
		private async Task GetPermissionDetails(IOwinContext context)
		{
			var key = new PermissionKey(context.GetRouteValue("key"));
			var permission = _collectionsReadModel.Permissions.Single(p => p.Key == key);

			await context.WriteJson(permission, _settings);
		}
Exemplo n.º 3
0
        public void Two_keys_with_same_value()
        {
            var one = new PermissionKey("one");
            var two = new PermissionKey("one");

            one.ShouldBe(two);
        }
 public CreatePermissionCommand(Operator user, PermissionKey key, string name, string description)
 {
     Operator = user;
     Key = key;
     Name = name;
     Description = description;
 }
Exemplo n.º 5
0
        public void Two_different_keys()
        {
            var one = new PermissionKey("one");
            var two = new PermissionKey("two");

            one.ShouldNotBe(two);
        }
Exemplo n.º 6
0
        public void When_serializing()
        {
            var input = new PermissionKey("one");
            var json = JsonConvert.SerializeObject(input);
            var output = JsonConvert.DeserializeObject<PermissionKey>(json);

            output.ShouldBe(input);
        }
Exemplo n.º 7
0
 public static string GetPermissionKey(Type module, PermissionKey permission)
 {
     if (module.BaseType != typeof(EntityBase))
     {
         return(null);
     }
     return(string.Format("Edo:{0}:{1}", module.Name, permission.ToString()));
 }
Exemplo n.º 8
0
 public PermissionCreatedEvent(Operator @operator, Guid id, PermissionKey key, string name, string description)
     : base(@operator)
 {
     ID = id;
     Key = key;
     Name = name;
     Description = description;
 }
        protected override void Render(HtmlTextWriter writer)
        {
            string imagePath;
            string altText;

            switch (Value)
            {
            case "True":
                imagePath = _grantImagePath;
                altText   = _grantAltText;
                break;

            case "False":
                imagePath = _denyImagePath;
                altText   = _denyAltText;
                break;

            default:
                imagePath = _nullImagePath;
                altText   = _nullAltText;
                break;
            }

            string cssClass = "tristate";

            if (Locked)
            {
                imagePath = _lockImagePath;
                cssClass += " lockedPerm";
                //altText is set based on Value
            }

            if (!SupportsDenyMode)
            {
                cssClass += " noDenyPerm";
            }

            if (IsFullControl)
            {
                cssClass += " fullControl";
            }

            if (IsView && !Locked)
            {
                cssClass += " view";
            }

            if (!String.IsNullOrEmpty(PermissionKey) && !IsView && !IsFullControl)
            {
                cssClass += " " + PermissionKey.ToLowerInvariant();
            }

            writer.Write("<img src='{0}' alt='{1}' />", imagePath, altText);

            writer.AddAttribute("class", cssClass);
            base.Render(writer);
        }
        private void RequestPermission()
        {
            PermissionKey permKey            = new PermissionKey(HealthConstants.StepCount.HealthDataType, PermissionType.Read);
            ICollection <PermissionKey> list = new Collection <PermissionKey>()
            {
                permKey
            };
            HealthPermissionManager pmsManager         = new HealthPermissionManager(mStore);
            IHealthResultHolder     healthResultHolder = pmsManager.RequestPermissions(list);

            healthResultHolder.SetResultListener(new CustomSetResultListener(mReporter, this));
        }
        public void OnResult(Java.Lang.Object result)
        {
            PermissionResult result1 = (PermissionResult)result;
            IDictionary <PermissionKey, Java.Lang.Boolean> resultMap = result1.ResultMap;
            PermissionKey permKey = new PermissionKey(HealthConstants.StepCount.HealthDataType, PermissionType.Read);

            if (resultMap[permKey].BooleanValue().Equals(Java.Lang.Boolean.False))
            {
            }
            else
            {
                mReporter.Start(mStepCountObserver);
            }
        }
Exemplo n.º 12
0
		private async Task UpdatePermissionName(IOwinContext context)
		{
			var key = new PermissionKey(context.GetRouteValue("key"));
			var dto = context.ReadJson<EditPermissionDto>();

			var permission = _collectionsReadModel.Permissions.Single(p => p.Key == key);

			_mediator.Publish(new ChangePermissionNameCommand(
				context.GetOperator(),
				permission.ID,
				dto.Name
			));

			await Task.Yield();
		}
Exemplo n.º 13
0
        private PermissionKey ParsePermissionNode(XmlNode node)
        {
            string text  = string.Empty;
            string value = string.Empty;

            if (node.Attributes != null && node.Attributes.Count > 0)
            {
                foreach (XmlAttribute attr in node.Attributes)
                {
                    if (string.Equals(attr.Name, "Text", StringComparison.OrdinalIgnoreCase))
                    {
                        text = attr.Value;
                    }
                    if (string.Equals(attr.Name, "Value", StringComparison.OrdinalIgnoreCase))
                    {
                        value = attr.Value;
                    }
                }
            }
            List <PermissionKey> ps = null;

            if (node.ChildNodes != null && node.ChildNodes.Count > 0)
            {
                ps = new List <PermissionKey>(node.ChildNodes.Count);
                foreach (XmlNode nn in node.ChildNodes)
                {
                    if (nn.NodeType == XmlNodeType.Element && node.Name == "Permission")
                    {
                        var node1 = ParsePermissionNode(nn);
                        if (string.IsNullOrWhiteSpace(node1.Value) == false ||
                            (node1.PermissionKeys != null && node1.PermissionKeys.Count > 0))
                        {
                            ps.Add(node1);
                        }
                    }
                }
            }
            PermissionKey p = new PermissionKey
            {
                Text           = text,
                Value          = value,
                PermissionKeys = ps == null ? new List <PermissionKey>(0) : ps
            };

            return(p);
        }
Exemplo n.º 14
0
        /// <summary>
        /// java 側に問い合わせてパーミッション許可のリクエストを出す。
        /// AndroidManifest.xml にパーミッション使用の宣言も必要。宣言されていないものをリクエストすると例外が出る。
        /// </summary>
        /// <param name="permission"></param>
        public static void Request(PermissionKey permission)
        {
            if (Application.platform != RuntimePlatform.Android)
            {
                return;
            }
            //if (IsPermitted(permission)) { return; }

            string className      = AndroidPermission.UtilityClassName;
            string methodName     = AndroidPermission.RequestMethodName;
            string permissionName = AndroidPermission.Permissions[permission];

            AndroidJavaObject javaObject = new AndroidJavaObject(className);
            string            result     = javaObject.CallStatic <string>(methodName, permissionName);

            Debug.Log(result);
        }
Exemplo n.º 15
0
        /// <summary>
        /// java 側に問い合わせて、パーミッションの許可が降りているかどうか確認する。
        /// Android OS のバージョンが Marshmallow 以前か、実行環境がAndroid 以外の場合にも true を返す。
        /// </summary>
        /// <param name="permission"></param>
        /// <returns> </returns>
        public static bool IsPermitted(PermissionKey permission)
        {
            if (Application.platform != RuntimePlatform.Android)
            {
                return(true);
            }

            string className      = AndroidPermission.UtilityClassName;
            string methodName     = AndroidPermission.IsPermittedMethodName;
            string permissionName = AndroidPermission.Permissions[permission];

            AndroidJavaObject javaObject = new AndroidJavaObject(className);
            bool result = javaObject.CallStatic <bool>(methodName, permissionName);

            Debug.Log(permission + " IsPermitted : " + result + Environment.NewLine);

            return(result);
        }
        private Java.Lang.Boolean IsPermissionAcquired()
        {
            PermissionKey           permKey    = new PermissionKey(HealthConstants.StepCount.HealthDataType, PermissionType.Read);
            HealthPermissionManager pmsManager = new HealthPermissionManager(mStore);

            try
            {
                ICollection <PermissionKey> list = new Collection <PermissionKey>()
                {
                    permKey
                };
                IDictionary <PermissionKey, Java.Lang.Boolean> resultMap = pmsManager.IsPermissionAcquired(list);
                return(resultMap[permKey]);
            }
            catch (System.Exception e)
            {
            }
            return(new Java.Lang.Boolean(false));
        }
 public DuplicatePermissionException(PermissionKey key)
     : base($"There is already a Permission with the key '{key}'")
 {
 }
Exemplo n.º 18
0
 public PageAuthorizationAttribute(Type module, PermissionKey permission)
 {
     _permissions = module.BaseType != typeof(EntityBase) ? null : new[] { string.Format("Edo:{0}:{1}", module.Name, permission) };
 }
Exemplo n.º 19
0
        private static void AddPermission(string key, string keyName, string keyDescription, string groupName, PermissionValueTypes type = PermissionValueTypes.Classic)
        {
            _actualPermissionKeys.Add(key);

            PermissionKey permissionKey = db.PermissionKeys.FirstOrDefault(o => o.Key == key);

            if (permissionKey != null)
            {
                permissionKey.KeyName        = keyName;
                permissionKey.GroupName      = groupName;
                permissionKey.KeyDescription = keyDescription;
                db.SaveChanges();
                return;
            }
            permissionKey = new PermissionKey()
            {
                Key            = key,
                KeyName        = keyName,
                KeyDescription = keyDescription,
                GroupName      = groupName
            };
            List <PermissionValue> permissionValueList;

            switch (type)
            {
            case PermissionValueTypes.Classic:
                permissionValueList = new List <PermissionValue>
                {
                    new PermissionValue()
                    {
                        PermissionKey = key,
                        Value         = "false",
                        Name          = "Запрещено",
                        IsDefault     = true
                    },
                    new PermissionValue()
                    {
                        PermissionKey = key,
                        Value         = "true",
                        Name          = "Разрешено",
                        IsDefault     = false
                    },
                };
                break;

            case PermissionValueTypes.Tree:
                permissionValueList = new List <PermissionValue>
                {
                    new PermissionValue()
                    {
                        PermissionKey = key,
                        Value         = "employee",
                        Name          = "Только себя",
                        IsDefault     = true
                    },
                    new PermissionValue()
                    {
                        PermissionKey = key,
                        Value         = "departament",
                        Name          = "Подразделение",
                        IsDefault     = false
                    },
                    new PermissionValue()
                    {
                        PermissionKey = key,
                        Value         = "all",
                        Name          = "Вся организация",
                        IsDefault     = false
                    },
                };
                break;

            default:
                throw new Exception("этого не должно произойти никогда");
            }
            db.PermissionValues.AddRange(permissionValueList);
            db.PermissionKeys.Add(permissionKey);
            var dbPermissionRoleKeys = new List <PermissionRoleKey>();
            var roleIds = db.PermissionRoles.Select(x => x.Id).ToList();

            foreach (var roleId in roleIds)
            {
                var dbKey = new PermissionRoleKey();
                dbKey.PermissionKey    = key;
                dbKey.PermissionRoleId = roleId;
                dbKey.PermissionValue  = permissionValueList.Single(x => x.IsDefault).Value;
                dbPermissionRoleKeys.Add(dbKey);
            }
            db.PermissionRoleKeys.AddRange(dbPermissionRoleKeys);
            db.SaveChanges();
        }
Exemplo n.º 20
0
 public bool CanCreatePermission(PermissionKey key)
 {
     return _keys.ContainsValue(key) == false;
 }
Exemplo n.º 21
0
		private async Task CheckPermission(IOwinContext context)
		{
			var userKey = new UserKey(context.GetRouteValue("user-key"));
			var permissionKey = new PermissionKey(context.GetRouteValue("permission-key"));

			var user = _collectionsReadModel.Users.Single(u => u.Key == userKey);
			var permission = _collectionsReadModel.Permissions.Single(p => p.Key == permissionKey);

			var result = new
			{
				Allowed = _authReadModel.CanUserPerformAction(user.ID, permission.ID)
			};

			await context.WriteJson(result, _settings);
		}