标签: windows-authentication

如何在C#中找到用户名/身份

我需要使用C#以编程方式查找用户名.具体来说,我想让系统/网络用户连接到当前进程.我正在编写一个使用Windows集成安全性的Web应用程序.

.net c# identity windows-authentication

16
推荐指数
2
解决办法
3万
查看次数

Windows身份验证在IIS Express中无效,使用Visual Studio 2013,Windows 8进行调试

我刚刚将我的应用程序从Visual Studio 2012升级到Visual Studio 2013.我的Windows身份验证不再起作用了.它给了我以下错误.

     HTTP Error 401.2 - Unauthorized
     You are not authorized to view this page due to invalid authentication headers.
Run Code Online (Sandbox Code Playgroud)

在visual studio中,可以选择从网站属性本身进行身份验证.所以我禁用了匿名访问并启用了Windows身份验证,但是它要求我输入用户名和密码,如下面的弹出窗口所示.即使我在这里提供域凭据.它仍然一次又一次地给我这个弹出窗口.

在此输入图像描述 在此输入图像描述

Web配置:

     <authentication mode="Windows" />
     <authorization>
     <deny users="?" />
     </authorization>
     <identity impersonate="false" />
     <trace enabled="true" />
Run Code Online (Sandbox Code Playgroud)

IIS Express aspnetConfig:

     <authentication>

            <anonymousAuthentication enabled="false" userName="" />

            <basicAuthentication enabled="false" />

            <clientCertificateMappingAuthentication enabled="false" />

            <digestAuthentication enabled="false" />

            <iisClientCertificateMappingAuthentication enabled="false">
            </iisClientCertificateMappingAuthentication>

            <windowsAuthentication enabled="true">
                <providers>
                    <add value="Negotiate" />
                    <add value="NTLM" />
                </providers>
            </windowsAuthentication>

        </authentication>

        <authorization>
            <add accessType="Allow" users="*" />
        </authorization>



        <location path="Path"> …
Run Code Online (Sandbox Code Playgroud)

windows-authentication iis-express visual-studio-2013

16
推荐指数
3
解决办法
4万
查看次数

带有Windows身份验证的WebAPI CORS - 允许匿名选项请求

我有一个运行Windows身份验证的WebAPI 2 REST服务.它与网站分开托管,因此我使用ASP.NET CORS NuGet包启用了CORS.我的客户端站点正在使用AngularJS.

到目前为止,这是我经历过的:

  1. 我没有设置withCredentials,因此CORS请求返回401.通过在我的$ httpProvider配置中添加withCredentials解决了这个问题.
  2. 接下来,我使用通配符源设置了EnableCorsAttribute,使用凭据时不允许这样做.通过设置明确的原始列表解决.
  3. 这使我的GET请求成功,但我的POST发出了预检请求,而我没有创建任何控制器操作来支持OPTIONS动词.为了解决这个问题,我将MessageHandler实现为全局OPTIONS处理程序.它只是为任何OPTIONS请求返回200.我知道这不完美,但现在在Fiddler工作.

我被困的地方 - 我的Angular预检电话不包括凭据.根据这个答案,这是设计,因为OPTIONS请求被设计为匿名.但是,Windows身份验证使用401停止请求.

我已经尝试将[AllowAnonymous]属性放在我的MessageHandler上.在我的开发计算机上,它可以工作 - OPTIONS动词不需要身份验证,但其他动词可以.但是,当我构建并部署到测试服务器时,我将继续在我的OPTIONS请求中获得401.

使用Windows身份验证时,是否可以在我的MessageHandler上应用[AllowAnonymous]?如果是的话,有关如何做的任何指导?或者这是一个错误的兔子洞,我应该看一个不同的方法?

更新:我能够通过在IIS中的站点上设置Windows身份验证和匿名身份验证来使其工作.这导致一切都允许匿名,所以我添加了一个全局的Authorize过滤器,同时保留了MessageHandler上的AllowAnonymous.

然而,这感觉就像一个黑客...我一直都明白只应该使用一种身份验证方法(不混合).如果有人有更好的方法,我会很感激听到它.

windows-authentication cors asp.net-web-api angularjs

16
推荐指数
3
解决办法
2万
查看次数

asp.net 5中的Windows身份验证

我正在ASP .NET 5,MVC 6中构建一个Intranet应用程序.我想知道如何启用Windows身份验证.默认项目模板仅支持单个用户帐户.

c# windows-authentication asp.net-core-mvc asp.net-core

16
推荐指数
4
解决办法
1万
查看次数

通过JDBC从Linux机器进行Windows身份验证连接到SQL Server

我希望能够使用jdbc和Windows身份验证连接到SQL Server.我在互联网上看到一些答案说我应该将以下属性添加到连接字符串:

integratedSecurity=true;
Run Code Online (Sandbox Code Playgroud)

并且还添加

sqljdbc_auth.dll
Run Code Online (Sandbox Code Playgroud)

到java路径.

但据我所知,只有在我从Windows机器上连接时才适用.当我在Linux机器上尝试这个时,我得到:

java.sql.SQLException: This driver is not configured for integrated authentication
Run Code Online (Sandbox Code Playgroud)

我的问题是我如何从Linux机器上做到这一点.

谢谢

java sql-server jdbc windows-authentication

16
推荐指数
3
解决办法
3万
查看次数

没有以明文形式存储的密码的Hibernate身份验证

我的目标是以安全的方式使用JDBC/Hibernate对数据库进行身份验证,而无需以纯文本形式存储密码.代码示例赞赏.我已经在使用华夫饼干对用户进行身份验证,因此如果有某种方法可以使用从用户那里获得的凭证,并将其转发给数据库,那就太好了.

两个问题:

  1. 在Web服务器,sql数据库和显然客户端浏览器上使用tomcat/hibernate/spring进行多跳认证(客户端,Web服务器和数据库都是不同的机器)的推荐方法是什么?
  2. 我还想找到一种方法来使用单个用户帐户进行身份验证,只要该用户帐户的信息不是以纯文本形式存储在任何地方.用户帐户将需要DB上的读/写权限.

我找到了一些有关在此线程中连接到SQL Server的有用信息.但是,我期待Tomcat将在默认帐户下运行,例如本地系统或其他东西.据我所知,该帐户不能用于对数据库进行Windows身份验证.

我的解决方案:

我最终使用上述线程中提到的方法.它不是将Tomcat服务作为本地系统运行,而是以用户身份运行.该用户有权访问数据库.我的hibernate配置文件配置如下:

    <property name="hibernate.connection.url">
jdbc:sqlserver://system:port;databaseName=myDb;integratedSecurity=true;
</property>
Run Code Online (Sandbox Code Playgroud)

对那些提供回复的人

我感谢大家的帮助,我将尝试一些线程中提到的技术.我对某些响应的问题是它们需要对称加密,这需要一个密钥.保持密钥的秘密几乎与将密码以纯文本格式存储完全相同.

java sql hibernate windows-authentication

15
推荐指数
4
解决办法
1万
查看次数

具有自定义角色的ASP.NET MVC和Windows身份验证

我试图在我的ASP.NET MVC2应用程序中实现Windows身份验证.我遵循了官方文档建议的所有步骤:

<authentication mode="Windows" />

<authorization>
  <deny users="?" />
</authorization>
Run Code Online (Sandbox Code Playgroud)

我已经指定了NTLM身份验证.到现在为止还挺好.一切正常.我想检查登录我的数据库的用户.我想从我的表中获取角色,然后使用自定义属性管理授权.
我不想使用会员和角色提供者. 我已经有我的表用户/角色,因为他们已经被用于互联网应用程序(这是内联网应用程序).

在我的Internet App中,我有一个用户输入数据的表单.表单将发布到控制器,该控制器将检查所有内容并使用登录用户的用户(和角色)创建cookie.

在我的global.asax中,我捕获了AuthenticateRequest事件,在那里我读取了cookie并创建了一个自定义主体,我在整个应用程序中使用它来检查授权.

如何使用Windows身份验证实现此功能?

asp.net asp.net-mvc windows-authentication

15
推荐指数
2
解决办法
2万
查看次数

System.DirectoryServices - 服务器无法运行

我在网站上收到错误,我使用Windows身份验证.

奇怪的事情:

  • 仅当用户尚未保存到数据库中时才会出现(新的未知用户)
  • 只出现在实时系统上,在本地开发环境中一切都很好

这是我在日志邮件中得到的:

来源:System.DirectoryServices

消息:服务器无法运行.

跟踪:
在System.DirectoryServices.DirectoryEntry.Bind(布尔throwIfFail)
在System.DirectoryServices.DirectoryEntry.Bind()
在System.DirectoryServices.DirectoryEntry.get_AdsObject()
在System.DirectoryServices.DirectorySearcher.FindAll(布尔findMoreThanOne)
在的System.DirectoryServices
.DirectorySearcher.FindOne ()在Smarthouse.Labs.DataAccess.UserListManager.SaveUser(String windowsUserName)

这是我实现DirectorySearch的方式:

private void SaveUser(string windowsUserName)
{
    string[] domainAndUser = windowsUserName.Split('\\');
    string domain = domainAndUser[0];
    string username = domainAndUser[1];

    DirectoryEntry entry = new DirectoryEntry("LDAP://" + domain);
    DirectorySearcher search = new DirectorySearcher(entry);

    try
    {
        // Bind to the native AdsObject to force authentication.
        search.Filter = "(SAMAccountName=" + username + ")";
        search.PropertiesToLoad.Add("cn");
        search.PropertiesToLoad.Add("sn");
        search.PropertiesToLoad.Add("givenName");
        search.PropertiesToLoad.Add("mail");

        SearchResult result = search.FindOne();

        if (result == null)
        {
            throw new Exception("No …
Run Code Online (Sandbox Code Playgroud)

asp.net directoryservices active-directory windows-authentication

15
推荐指数
1
解决办法
3万
查看次数

如何以特定域用户身份运行Internet Explorer Selenium测试?

我有一个ASP.NET MVC网站,它使用Windows身份验证来控制访问.我希望有一个specflow selenium测试,通过尝试以非授权用户身份访问该站点来检查配置是否正确.

由于我们使用域帐户来控制访问权限,因此没有用户名/密码登录屏幕.浏览器会自动将当前用户的凭据传递给站点.

因此,对于我的Selenium测试,我需要能够以特定用户身份运行Internet Explorer.

我发现了一些关于Windows模拟的文章,我可以在运行测试期间切换到我的测试用户(使用http://support.microsoft.com/kb/306158中的代码).然而,如果我然后创建一个InternetExplorerDriver它使用我的凭据而不是测试用户启动Internet Explorer(尽管这个问题和答案表明它应该工作https://sqa.stackexchange.com/questions/2277/using-selenium-webdriver- with-windows-authentication).

我也可以明确地启动Internet Explorer进程作为我的测试用户,但是我看不到将InternetExplorerDriver绑定到已经运行的Internet Explorer进程的方法,所以这可能是一个死胡同.

我的代码基本上来自上面的MSDN页面.在调试器中,我可以看到WindowsIdentity.GetCurrent().Name在测试的所有步骤中都是"testUser".

namespace MyProject.Specs
{
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using System;
using System.Runtime.InteropServices;
using System.Security.Principal;
using TechTalk.SpecFlow;

[Binding]
public class AuthorisationSteps
{
    public const int LOGON32_LOGON_INTERACTIVE = 2;
    public const int LOGON32_PROVIDER_DEFAULT = 0;
    private static WindowsImpersonationContext impersonationContext;
    private static IWebDriver driver;

    [BeforeScenario]
    public static void impersonateUser()
    {
        if (!impersonateValidUser("testUser", "testDomain", "password"))
        {
            throw new Exception();
        }
        driver = new InternetExplorerDriver();
    }

    [AfterScenario] …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc selenium windows-authentication specflow selenium-webdriver

15
推荐指数
2
解决办法
4779
查看次数

在ASP.NET中使用Windows身份验证

我正在尝试在我的ASP.NET应用程序中使用Windows身份验证.每当我尝试查看应用程序时,它都会将我发送到登录页面.如何在不通过浏览器手动登录的情况下使其工作?

web.config中

  <system.web>
    <authentication mode="Windows"></authentication>
    <anonymousIdentification enabled="false"/>
    <authorization>
      <deny users="?" />
      <allow users="*" />
    </authorization>
    <customErrors mode="Off"></customErrors>
    <identity impersonate="true"></identity>
    <compilation debug="true" targetFramework="4.0" />
    <httpRuntime />
  </system.web>
Run Code Online (Sandbox Code Playgroud)

更新IIS Express后出错

Most likely causes:
No authentication protocol (including anonymous) is selected in IIS.
Only integrated authentication is enabled, and a client browser was used that does not support integrated authentication.
Integrated authentication is enabled and the request was sent through a proxy that changed the authentication headers before they reach the Web server. …
Run Code Online (Sandbox Code Playgroud)

c# asp.net iis windows-authentication iis-express

15
推荐指数
4
解决办法
3万
查看次数