public void Two_keys_with_different_values_by_case()
        {
            var one = new PermissionKey("one");
            var two = new PermissionKey("ONE");

            one.ShouldBe(two);
        }
		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);
		}
        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;
 }
        public void Two_different_keys()
        {
            var one = new PermissionKey("one");
            var two = new PermissionKey("two");

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

            output.ShouldBe(input);
        }
Beispiel #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()));
 }
 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);
            }
        }
		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();
		}
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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}'")
 {
 }
 public PageAuthorizationAttribute(Type module, PermissionKey permission)
 {
     _permissions = module.BaseType != typeof(EntityBase) ? null : new[] { string.Format("Edo:{0}:{1}", module.Name, permission) };
 }
        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();
        }
 public bool CanCreatePermission(PermissionKey key)
 {
     return _keys.ContainsValue(key) == false;
 }
Beispiel #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);
		}