public static SafeFreeCredentials AcquireDefaultCredential(SSPIInterface secModule, string package, Interop.SspiCli.CredentialUse intent) { if (GlobalLog.IsEnabled) { GlobalLog.Print("SSPIWrapper::AcquireDefaultCredential(): using " + package); } if (SecurityEventSource.Log.IsEnabled()) { SecurityEventSource.Log.AcquireDefaultCredential(package, intent); } SafeFreeCredentials outCredential = null; int errorCode = secModule.AcquireDefaultCredential(package, intent, out outCredential); if (errorCode != 0) { #if TRACE_VERBOSE if (GlobalLog.IsEnabled) { GlobalLog.Print("SSPIWrapper::AcquireDefaultCredential(): error " + Interop.MapSecurityStatus((uint)errorCode)); } #endif if (NetEventSource.Log.IsEnabled()) { NetEventSource.PrintError(NetEventSource.ComponentType.Security, SR.Format(SR.net_log_operation_failed_with_error, "AcquireDefaultCredential()", String.Format(CultureInfo.CurrentCulture, "0X{0:X}", errorCode))); } throw new Win32Exception(errorCode); } return(outCredential); }
public static SafeFreeCredentials AcquireDefaultCredential(SSPIInterface SecModule, string package, CredentialUse intent) { GlobalLog.Print("SSPIWrapper::AcquireDefaultCredential(): using " + package); if (Logging.On) { Logging.PrintInfo(Logging.Web, "AcquireDefaultCredential(" + "package = " + package + ", " + "intent = " + intent + ")"); } SafeFreeCredentials outCredential = null; int errorCode = SecModule.AcquireDefaultCredential(package, intent, out outCredential); if (errorCode != 0) { #if TRAVE GlobalLog.Print("SSPIWrapper::AcquireDefaultCredential(): error " + SecureChannel.MapSecurityStatus((uint)errorCode)); #endif if (Logging.On) { Logging.PrintError(Logging.Web, SR.GetString(SR.net_log_operation_failed_with_error, "AcquireDefaultCredential()", String.Format(CultureInfo.CurrentCulture, "0X{0:X}", errorCode))); } throw new Win32Exception(errorCode); } return(outCredential); }
public static SafeFreeCredentials AcquireDefaultCredential(SSPIInterface SecModule, string package, CredentialUse intent) { if (Logging.On) { Logging.PrintInfo(Logging.Web, string.Concat(new object[] { "AcquireDefaultCredential(package = ", package, ", intent = ", intent, ")" })); } SafeFreeCredentials outCredential = null; int error = SecModule.AcquireDefaultCredential(package, intent, out outCredential); if (error == 0) { return outCredential; } if (Logging.On) { Logging.PrintError(Logging.Web, SR.GetString("net_log_operation_failed_with_error", new object[] { "AcquireDefaultCredential()", string.Format(CultureInfo.CurrentCulture, "0X{0:X}", new object[] { error }) })); } throw new Win32Exception(error); }
public static SafeFreeCredentials AcquireDefaultCredential(SSPIInterface SecModule, string package, CredentialUse intent) { if (Logging.On) { Logging.PrintInfo(Logging.Web, string.Concat(new object[] { "AcquireDefaultCredential(package = ", package, ", intent = ", intent, ")" })); } SafeFreeCredentials outCredential = null; int error = SecModule.AcquireDefaultCredential(package, intent, out outCredential); if (error == 0) { return(outCredential); } if (Logging.On) { Logging.PrintError(Logging.Web, SR.GetString("net_log_operation_failed_with_error", new object[] { "AcquireDefaultCredential()", string.Format(CultureInfo.CurrentCulture, "0X{0:X}", new object[] { error }) })); } throw new Win32Exception(error); }
public static SafeFreeCredentials AcquireDefaultCredential(SSPIInterface secModule, string package, Interop.SspiCli.CredentialUse intent) { if (NetEventSource.IsEnabled) { NetEventSource.Enter(null, package); NetEventSource.Log.AcquireDefaultCredential(package, intent); } SafeFreeCredentials outCredential = null; int errorCode = secModule.AcquireDefaultCredential(package, intent, out outCredential); if (errorCode != 0) { if (NetEventSource.IsEnabled) { NetEventSource.Error(null, System.StringsHelper.Format(Strings.net_log_operation_failed_with_error, nameof(AcquireDefaultCredential), $"0x{errorCode:X}")); } throw new Win32Exception(errorCode); } return(outCredential); }
public static SafeFreeCredentials AcquireDefaultCredential(SSPIInterface SecModule, string package, CredentialUse intent) { SafeFreeCredentials outCredential = null; string currentIdentityKey = null; bool isIdentityCached; if (s_DefaultCredentialsHandleCacheEnabled) { currentIdentityKey = string.Format("{0}_{1}_{2}", package, intent.ToString(), WindowsIdentity.GetCurrent().Name); isIdentityCached = s_DefaultCredentialsHandleCache.Value.TryGetValue(currentIdentityKey, out outCredential); } else { isIdentityCached = false; } GlobalLog.Print("SSPIWrapper::AcquireDefaultCredential(): using " + package); if (Logging.On) { if (currentIdentityKey == null) { // We aren't using the cache but it's still useful to log the current identity for diagnostics. currentIdentityKey = string.Format("{0}_{1}_{2}", package, intent.ToString(), WindowsIdentity.GetCurrent().Name); } Logging.PrintInfo(Logging.Web, "AcquireDefaultCredential(" + "package = " + package + ", " + "intent = " + intent + ", " + "identity = " + currentIdentityKey + ", " + "cached = " + isIdentityCached + ")"); } if (!isIdentityCached) { int errorCode = SecModule.AcquireDefaultCredential(package, intent, out outCredential); if (errorCode != 0) { #if TRAVE GlobalLog.Print("SSPIWrapper::AcquireDefaultCredential(): error " + SecureChannel.MapSecurityStatus((uint)errorCode)); #endif if (Logging.On) { Logging.PrintError(Logging.Web, SR.GetString(SR.net_log_operation_failed_with_error, "AcquireDefaultCredential()", String.Format(CultureInfo.CurrentCulture, "0X{0:X}", errorCode))); } throw new Win32Exception(errorCode); } if (s_DefaultCredentialsHandleCacheEnabled && s_DefaultCredentialsHandleCache.Value.Count < s_DefaultCredentialsHandleCacheSize) { try { s_DefaultCredentialsHandleCache.Value.TryAdd(currentIdentityKey, outCredential); } catch (OverflowException) { // Unlikely to be thrown since it requires Int32.MaxValue items to already be in the cache. // But we don't want to throw a new exception. So, we'll ignore this error and accept that // the handle won't be cached. } } } return(outCredential); }