TryParseUsername() static private method

Tries to parse the string as a username to get the SDDL format of a SID.
static private TryParseUsername ( string username, string &sddl ) : bool
username string The string to parse as a username.
sddl string The SDDL format of a SID to return.
return bool
Ejemplo n.º 1
0
        public void TryParseUsernameTest()
        {
            string param = null;

            // Test a string without backslashes.
            Assert.IsFalse(SidAttribute.TryParseUsername(@"foo", out param));
            Assert.IsNull(param);

            // Test a string with backslashes but not a valid username.
            Assert.IsFalse(SidAttribute.TryParseUsername(@"foo\bar\baz", out param));
            Assert.IsNull(param);

            // Test a valid username.
            Assert.IsTrue(SidAttribute.TryParseUsername(CurrentUsername, out param));
            Assert.AreEqual <string>(CurrentSID, param);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Transforms user account identifiers to security identifiers.
        /// </summary>
        /// <param name="engineIntrinsics">Provides access to the APIs for managing the transformation context.</param>
        /// <param name="inputData">The parameter argument that is to be transformed.</param>
        /// <returns>The transformed object.</returns>
        public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
        {
            // null may be allowed, so pass it through.
            if (inputData == null)
            {
                return(null);
            }

            // Convert account information to SDDL format.
            string username;

            if (LanguagePrimitives.TryConvertTo <string>(inputData, out username))
            {
                string sddl;
                if (SidAttribute.TryParseUsername(username, out sddl))
                {
                    return(sddl);
                }
            }

            // Fallback to returning the original input data to further transformations.
            return(inputData);
        }