null - Null : AssertionConsumerService => saml2AuthnResponse.CreateSession 期间的对象引用
问题描述
我在 MVC.NET(4.7.2 框架)中运行 ITFoxtec.Identity.Saml2.Mvc(v4.5.0)。而且我的 IdP 说已成功通过身份验证...正在重定向回来...但是当我从 IdP 收到响应时-我在此调用中得到了一个空异常。不幸的是,它没有给我一个行号或任何有助于追踪它的东西。
saml2AuthnResponse.CreateSession()
我尝试了多种构建 nuget 包的方法,以使其在失败的地方注销 - 但到目前为止,在从包外部使用/引用时没有运气。我在 web.config 中设置了如下其他设置:
<add key="Saml2:CertificateValidationMode" value="PeerOrChainTrust" />
<add key="Saml2:RevocationMode" value="NoCheck" />
我的 AssertionConsumerService 与您网站上的示例几乎相同:
public ActionResult AssertionConsumerService()
{
var binding = new Saml2PostBinding();
var saml2AuthnResponse = new Saml2AuthnResponse(config);
binding.Unbind(Request.ToGenericHttpRequest(), saml2AuthnResponse);
saml2AuthnResponse.CreateSession(claimsAuthenticationManager: new SAMLDefaultClaimsAuthenticationManager());
var returnUrl = binding.GetRelayStateQuery()[relayStateReturnUrl];
return Redirect(string.IsNullOrWhiteSpace(returnUrl) ? Url.Content("~/") : returnUrl);
}
在 Saml2ResponseExtensions.cs CreateSession() ln.19 上的 printf 调试中,我可以说它(可能?)不会在这一行之前抛出(因为我可以复制+粘贴在我的外部范围内重新创建所有前面的变量,没有问题)。
var sessionSecurityToken = lifetime.HasValue
? new SessionSecurityToken(transformedPrincipal, lifetime.Value)
...
@AndersRevsgaard 有什么想法吗?
解决方案
我跟踪到这一行,这会引发 Null ref 错误:
FederatedAuthentication.SessionAuthenticationModule.AuthenticateSessionSecurityToken(sessionSecurityToken, true);
虽然仍然很神秘,但这个答案解决了这个问题: 是什么让 FederatedAuthentication.SessionAuthenticationModule 返回 NULL? 通过向 web.config 添加一些部分。
<configSections>
<section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</configSections>
<system.web>
<authentication mode="None" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</modules>
</system.webServer>
<system.identityModel.services>
<federationConfiguration>
<cookieHandler requireSsl="false" />
</federationConfiguration>
</system.identityModel.services>
您可以查看 ITFoxTec 测试 web.config 以获取完整示例: https ://github.com/ITfoxtec/ITfoxtec.SAML2/blob/master/WebAppTest/Web.config
推荐阅读
- linux - 使用 gitlab 进行持续部署
- javascript - CKEditor - 如何获取模板属性
- clob - ORA-60019: 在范围大小为 8 的表空间中创建大小为 14 的初始范围
- c++ - 使用 DirectX 桌面框架的消费者-生产者线程
- django - 如何将 CreateView 中的表单(与通用内容类型连接到 detailview 中的模型)转换为 DetailView?
- julia - 朱莉娅和大数字
- r - 无法排除 Twitter Dataframe R 中的行
- laravel - 在路由中同时调用中间件和控制器方法
- java - Java Spring 一个类的多个节点
- dialogflow-es - 富媒体的意图行动