コード例 #1
0
        /// <summary>
        /// Get AuthZ context's security attributes
        /// </summary>
        /// <param name="type">Specify the type of security attributes to query.</param>
        /// <param name="throw_on_error">Throw on error.</param>
        /// <returns>The security attributes.</returns>
        public NtResult <ClaimSecurityAttribute[]> GetSecurityAttributes(AuthZSecurityAttributeType type, bool throw_on_error)
        {
            var info_class = AttrTypeToInfoClass(type);

            using (var buf = QueryBuffer <ClaimSecurityAttributesInformation>(info_class, throw_on_error)) {
                if (!buf.IsSuccess)
                {
                    return(buf.Cast <ClaimSecurityAttribute[]>());
                }
                int struct_size = Marshal.SizeOf(typeof(ClaimSecurityAttributeV1));
                ClaimSecurityAttributesInformation r          = buf.Result.Result;
                List <ClaimSecurityAttribute>      attributes = new List <ClaimSecurityAttribute>();
                if (r.AttributeCount > 0)
                {
                    int    count  = r.AttributeCount;
                    IntPtr buffer = r.pAttributeV1;
                    while (count > 0)
                    {
                        attributes.Add(new ClaimSecurityAttribute(buffer, false));
                        count--;
                        buffer += struct_size;
                    }
                }
                return(new NtResult <ClaimSecurityAttribute[]>(NtStatus.STATUS_SUCCESS, attributes.ToArray()));
            }
        }
コード例 #2
0
        private static AUTHZ_CONTEXT_INFORMATION_CLASS AttrTypeToInfoClass(AuthZSecurityAttributeType type)
        {
            switch (type)
            {
            case AuthZSecurityAttributeType.Device:
                return(AUTHZ_CONTEXT_INFORMATION_CLASS.AuthzContextInfoDeviceClaims);

            case AuthZSecurityAttributeType.User:
                return(AUTHZ_CONTEXT_INFORMATION_CLASS.AuthzContextInfoUserClaims);

            default:
                return(AUTHZ_CONTEXT_INFORMATION_CLASS.AuthzContextInfoSecurityAttributes);
            }
        }