/// <summary> /// Acquires security credentials for a current security principal /// </summary> public SecurityCredentials AcquireSecurityCredentials( SecurityCredentialsType credType, IDictionary authData) { // prepare context usage uint credUsage = 0; if ((credType & SecurityCredentialsType.InBound) != 0) credUsage |= SSPINative.SECPKG_CRED_INBOUND; if ((credType & SecurityCredentialsType.OutBound) != 0) credUsage |= SSPINative.SECPKG_CRED_OUTBOUND; // prepare identity information SSPINative.SecWinNTAuthIdentity authIdentity = new SSPINative.SecWinNTAuthIdentity(); if (authData != null) { string userName = (string)authData["user"]; if (userName != null) { authIdentity.User = userName; authIdentity.UserLength = userName.Length; } string domain = (string)authData["domain"]; if (domain != null) { authIdentity.Domain = domain; authIdentity.DomainLength = domain.Length; } string password = (string)authData["password"]; if (password != null) { authIdentity.Password = password; authIdentity.PasswordLength = password.Length; } } // acquire credentials Int64 credHandle; Int64 credExpiry; int error = SSPINative.AcquireCredentialsHandle( null, _secPackage.Name, credUsage, IntPtr.Zero, authIdentity, IntPtr.Zero, IntPtr.Zero, out credHandle, out credExpiry); if (error < 0) throw new SSPIException(Marshal.GetLastWin32Error(), "Could not acquire credentials handle"); // create credentials object return new SecurityCredentials(_secPackage, credHandle, credExpiry, credType); }
internal SecurityCredentials( SecurityPackage secPackage, Int64 credHandle, Int64 credExpiry, SecurityCredentialsType credType) { // parameters validation if (secPackage == null) throw new ArgumentNullException("secPackage"); if (credHandle == 0) throw new ArgumentNullException("credHandle"); _secPackage = secPackage; _credHandle = credHandle; _credExpiry = credExpiry; _credType = credType; }
internal SecurityCredentials( SecurityPackage secPackage, Int64 credHandle, Int64 credExpiry, SecurityCredentialsType credType) { // parameters validation if (secPackage == null) { throw new ArgumentNullException("secPackage"); } if (credHandle == 0) { throw new ArgumentNullException("credHandle"); } _secPackage = secPackage; _credHandle = credHandle; _credExpiry = credExpiry; _credType = credType; }
/// <summary> /// Acquires security credentials for a current security principal /// </summary> public SecurityCredentials AcquireSecurityCredentials( SecurityCredentialsType credType, IDictionary authData) { // prepare context usage uint credUsage = 0; if ((credType & SecurityCredentialsType.InBound) != 0) { credUsage |= SSPINative.SECPKG_CRED_INBOUND; } if ((credType & SecurityCredentialsType.OutBound) != 0) { credUsage |= SSPINative.SECPKG_CRED_OUTBOUND; } // prepare identity information SSPINative.SecWinNTAuthIdentity authIdentity = new SSPINative.SecWinNTAuthIdentity(); if (authData != null) { string userName = (string)authData["user"]; if (userName != null) { authIdentity.User = userName; authIdentity.UserLength = userName.Length; } string domain = (string)authData["domain"]; if (domain != null) { authIdentity.Domain = domain; authIdentity.DomainLength = domain.Length; } string password = (string)authData["password"]; if (password != null) { authIdentity.Password = password; authIdentity.PasswordLength = password.Length; } } // acquire credentials Int64 credHandle; Int64 credExpiry; int error = SSPINative.AcquireCredentialsHandle( null, _secPackage.Name, credUsage, IntPtr.Zero, authIdentity, IntPtr.Zero, IntPtr.Zero, out credHandle, out credExpiry); if (error < 0) { throw new SSPIException(Marshal.GetLastWin32Error(), "Could not acquire credentials handle"); } // create credentials object return(new SecurityCredentials(_secPackage, credHandle, credExpiry, credType)); }