AzMan为不同的服务器提供不同的结果

时间:2011-05-05 09:05:50

标签: c# iis iis-7.5 azman

我们有两个理论上 相同的网络服务器,但在执行AzMan授权检查时会产生不同的结果。

我们在两台机器上运行相同的网站(字面上是相同的网站 - 它是从一个到另一个的XCOPYed,它在同一个服务帐户下运行)。所有这些网站都会对AzMan数据库(位于单独的SQL服务器上)执行授权检查。

但是,在工作网站(WebA)上,此检查会返回0(即“用户已获得授权”),而在损坏的网站(WebB)上,此检查将返回5(即“用户未被授权”)。我们期望在这两个网站上0。同一个用户从同一台PC访问这两个网站。

有没有人对我们可以检查的事情有任何想法?

环境详情

  • Windows Server 2008 R2
  • 相同的AD域
  • IIS 7.5
  • .NET 3.5
  • AzMan数据库在SQL Server 2005 / Windows Server 2008 R2上运行。

代码

AzAuthorizationStoreClass authStore = new AzAuthorizationStoreClass();

// initialise the store
authStore.Initialize(0, "mssql://Driver={SQL Server};Server={OURDBSERVER};Trusted_Connection={Yes};/OURDATABASE/OURAPPLICATION", null);

// open the store
IAzApplication2 authApp = authStore.OpenApplication2("OURAPPLICATION", null);

// get the identity of the user NOT the service account
WindowsIdentity identity = Thread.CurrentPrincipal.Identity as WindowsIdentity;

// and from that derive the token
ulong userToken = (ulong)identity.Token.ToInt64();

// get the context based on the token
IAzClientContext3 clientContext = 
    (IAzClientContext3)authApp.InitializeClientContextFromToken(userToken, null);

// get the operation object based on the id
IAzOperation2 azManOperation = (IAzOperation2)authApp.OpenOperation(operationId, null);

// generate an audit identifier
string auditIdentifer = 
    string.Format("{0}{1} : O:{2}", "{the_correct_id}", identity.Name, operationId);

uint accessResult = clientContext.AccessCheck2(auditIdentifer, string.Empty, azManOperation.OperationID);

return accessResult.ToString();

非常感谢,

RB。

2 个答案:

答案 0 :(得分:2)

感谢David Hall指出我正确的方向。

调查显示,这两个网站都启用了Windows身份验证和匿名访问。但是,在一个网站上,用户正在正确登录,而在破碎的网站上,它又回到了匿名模式。

禁用匿名访问通过确保用户登录到两个网站来解决此问题。

然而,这又留下了另一个问题:为什么浏览器在一个网站上匿名登录而不是另一个网站 - 我认为是ServerFault的一个。

答案 1 :(得分:0)

在我们的例子中,我们使用ASP.NET模拟而不是匿名。 Tt正在开发Windows 7 Enterprise x64开发机器而不是Windows Server 2008 R2 x64测试服务器。两个应用程序池都使用相同的域帐户凭据设置完全相同。

事实证明,ASP.NET假冒是该问题的根本原因。禁用ASP.NET模拟后,App Pool帐户现在用作成功连接到AzMan存储的凭据。连接到Active Directory或SQL Server中的AzMan存储时发生了同样的问题。

为清楚起见,我得到的错误是:Value does not fall within the expected range. from AzAuthorizationStoreClass.Initialize()

我的最终连接字符串是:

<add name="AzPolicyStore" connectionString="mssql://Driver={SQL
  Server};Server=sqlserver\instance;/DatabaseName/AzStore" />
相关问题