コード例 #1
0
        public static SecurityCredential Acquire(SspiPackage package, string username, MongoIdentityEvidence evidence)
        {
            long timestamp;

            var credential = new SecurityCredential();

            RuntimeHelpers.PrepareConstrainedRegions();
            try { }
            finally
            {
                uint result;
                var  passwordEvidence = evidence as PasswordEvidence;
                if (passwordEvidence == null)
                {
                    result = Win32.AcquireCredentialsHandle(
                        null,
                        package.ToString(),
                        SecurityCredentialUse.Outbound,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        0,
                        IntPtr.Zero,
                        ref credential._sspiHandle,
                        out timestamp);
                }
                else
                {
                    using (var authIdentity = new AuthIdentity(username, passwordEvidence.SecurePassword))
                    {
                        // TODO: make this secure by using SecurePassword
                        result = Win32.AcquireCredentialsHandle(
                            null,
                            package.ToString(),
                            SecurityCredentialUse.Outbound,
                            IntPtr.Zero,
                            authIdentity,
                            0,
                            IntPtr.Zero,
                            ref credential._sspiHandle,
                            out timestamp);
                    }
                }
                if (result != Win32.SEC_E_OK)
                {
                    credential.SetHandleAsInvalid();
                    throw Win32.CreateException(result, "Unable to acquire credential.");
                }
            }
            return(credential);
        }
コード例 #2
0
        public static SecurityCredential Acquire(SspiPackage package, string username, MongoIdentityEvidence evidence)
        {
            long timestamp;

            var credential = new SecurityCredential();
            RuntimeHelpers.PrepareConstrainedRegions();
            try { }
            finally
            {
                uint result;
                var passwordEvidence = evidence as PasswordEvidence;
                if (passwordEvidence == null)
                {
                    result = Win32.AcquireCredentialsHandle(
                        null,
                        package.ToString(),
                        SecurityCredentialUse.Outbound,
                        IntPtr.Zero,
                        IntPtr.Zero,
                        0,
                        IntPtr.Zero,
                        ref credential._sspiHandle,
                        out timestamp);

                }
                else
                {
                    using(var authIdentity = new AuthIdentity(username, passwordEvidence.SecurePassword))
                    {
                        // TODO: make this secure by using SecurePassword
                        result = Win32.AcquireCredentialsHandle(
                            null,
                            package.ToString(),
                            SecurityCredentialUse.Outbound,
                            IntPtr.Zero,
                            authIdentity,
                            0,
                            IntPtr.Zero,
                            ref credential._sspiHandle,
                            out timestamp);
                    }
                }
                if (result != Win32.SEC_E_OK)
                {
                    credential.SetHandleAsInvalid();
                    throw Win32.CreateException(result, "Unable to acquire credential.");
                }
            }
            return credential;
        }
コード例 #3
0
ファイル: Win32.cs プロジェクト: neo2018/mongo-csharp-driver
 public static extern uint AcquireCredentialsHandle(
     string principal,
     string package,
     SecurityCredentialUse credentialUsage,
     IntPtr logonId,
     AuthIdentity identity,
     int keyCallback,
     IntPtr keyArgument,
     ref SspiHandle credentialHandle,
     out long timestamp);