コード例 #1
0
        private string GetUniqueKey(IPermission permission)
        {
            if (permission == null)
            {
                return(null);
            }

            return(PermissionIdentifierFormatter.GetUniqueIdentifier(permission));
        }
コード例 #2
0
        public IPermission GetByEntityAndPermissionType(string entityDefinitionCode, string permissionTypeCode)
        {
            if (string.IsNullOrEmpty(entityDefinitionCode) || string.IsNullOrEmpty(permissionTypeCode))
            {
                return(null);
            }
            var key = PermissionIdentifierFormatter.GetUniqueIdentifier(permissionTypeCode, entityDefinitionCode);

            return(_permissions.GetOrDefault(key));
        }
コード例 #3
0
        /// <summary>
        /// Formats the name of a policy that restricts authorization to
        /// a specific Cofoundry permission.
        /// </summary>
        /// <param name="permission">
        /// The permission to restrict the policy to.
        /// </param>
        /// <returns>Namespaced policy name in the format 'Cofoundry_Permission_{identifier}'</returns>
        public static string Permission(IPermission permission)
        {
            if (permission == null)
            {
                throw new ArgumentEmptyException(nameof(permission));
            }

            var identifier = PermissionIdentifierFormatter.GetUniqueIdentifier(permission);

            return($"Cofoundry_Permission_{identifier}");
        }
コード例 #4
0
        /// <summary>
        /// Formats the name of a policy that restricts authorization to
        /// a specific Cofoundry permission.
        /// </summary>
        /// <param name="permissionTypeCode">
        /// The 6 character permission code to restrict the policy to.
        /// </param>
        /// <param name="entityDefinitionCode">
        /// The 6 character custom entity definition code to restrict the policy to. Note that this is
        /// the code for a permission that is not scoped to an entity.
        /// </param>
        /// <returns>Namespaced policy name in the format 'Cofoundry_Permission_{identifier}'</returns>
        public static string Permission(string permissionTypeCode, string entityDefinitionCode)
        {
            if (string.IsNullOrWhiteSpace(permissionTypeCode))
            {
                throw new ArgumentEmptyException(nameof(permissionTypeCode));
            }
            if (string.IsNullOrWhiteSpace(entityDefinitionCode))
            {
                throw new ArgumentEmptyException(nameof(entityDefinitionCode));
            }

            var identifier = PermissionIdentifierFormatter.GetUniqueIdentifier(permissionTypeCode, entityDefinitionCode);

            return($"Cofoundry_Permission_{identifier}");
        }
コード例 #5
0
        /// <summary>
        /// Formats the name of a policy that restricts authorization to
        /// a specific Cofoundry permission. This version is designed for
        /// permissions that are no scoped to a specific entity type.
        /// </summary>
        /// <param name="permissionTypeCode">
        /// The 6 character permission code to restrict the policy to. Note that this is
        /// the code for a permission that is not scoped to an entity.
        /// </param>
        /// <returns>Namespaced policy name in the format 'Cofoundry_Permission_{identifier}'</returns>
        public static string Permission(string permissionTypeCode)
        {
            if (string.IsNullOrWhiteSpace(permissionTypeCode))
            {
                throw new ArgumentEmptyException(nameof(permissionTypeCode));
            }
            if (permissionTypeCode.Length != 6)
            {
                // Ensure that this parameter isn't used for the 12 character identifier
                throw new ArgumentException($"The {nameof(permissionTypeCode)} parameter should be a 6 charcter permission type code, the specified value is {permissionTypeCode.Length} characters.", nameof(permissionTypeCode));
            }

            var identifier = PermissionIdentifierFormatter.GetUniqueIdentifier(permissionTypeCode);

            return($"Cofoundry_Permission_{identifier}");
        }
コード例 #6
0
 /// <summary>
 /// Creates a unique code that represents this permission by combining the
 /// entity definition code and the permission code. This is useful when
 /// representing the permission as a unique string identifier.
 /// </summary>
 /// <param name="permission">Permission to get the unique code for.</param>
 /// <returns>A string identifier that uniquely identifies this permission.</returns>
 public static string GetUniqueIdentifier(this IPermission permission)
 {
     return(PermissionIdentifierFormatter.GetUniqueIdentifier(permission));
 }
コード例 #7
0
        public IPermission GetByCode(string permissionTypeCode, string entityDefinitionCode)
        {
            var key = PermissionIdentifierFormatter.GetUniqueIdentifier(permissionTypeCode, entityDefinitionCode);

            return(_permissions.GetOrDefault(key));
        }