spring-boot - 如何避免使用 Spring Ssecurity 和 SAML 登录页面?
问题描述
我正在尝试当用户通过 Saml2 登录到我的系统时,它会根据他的域自动将他重定向到关联的配置,而不必像显示的那样通过登录页面。
比如用户:user1@company1.com,我想自动重定向到域(company1>singlesignon.url)对应的认证页面,而不必经过这个中间。
我曾尝试使用 Saml2SecurityConfig 解决此问题,但我不知道如何正确设置它。
怎么可能做到?
security:
saml2:
relyingparty:
registration:
company1:
identityprovider:
entity-id:
verification.credentials:
- certificate-location:
singlesignon.url: https://login.microsoftonline.com/XXXX/saml2
singlesignon.sign-request:
company2:
identityprovider:
entity-id:
verification.credentials:
- certificate-location:
singlesignon.url:
singlesignon.sign-request:
Saml2Config
public class Saml2Config extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
OpenSamlAuthenticationProvider authenticationProvider = new OpenSamlAuthenticationProvider();
authenticationProvider.setResponseAuthenticationConverter(responseToken -> {
Saml2Authentication authentication = OpenSamlAuthenticationProvider
.createDefaultResponseAuthenticationConverter()
.convert(responseToken);
Assertion assertion = responseToken.getResponse().getAssertions().get(0);
String username = assertion.getSubject().getNameID().getValue();
UserDetails userDetails = inMemoryUserDetailsManager().loadUserByUsername(username);
authentication.setDetails(userDetails);
return authentication;
});
http
.requestMatchers()
.antMatchers("/login/**","/saml2/**")
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.saml2Login().authenticationManager(new ProviderManager(authenticationProvider))
.and().csrf().disable();
}
}
解决方案
customer.service.com
我通常看到组织通过用户的电子邮件地址(如 Office 365 门户如何做到这一点)或通过客户特定的 FQDN(如
如果您使用电子邮件地址,则应将其放入 AuthnRequest 的主题中,以便 IdP 可以在登录屏幕中使用它。
推荐阅读
- ruby - wayback_machine_donwloader 尝试从网络存档下载“http://mexiko-lexikon.de”时出错
- macros - 是否可以拥有一个同时具有程序宏和逻辑的板条箱?
- javascript - 如何使用ajax从jsp调用java控制器方法
- javascript - ReactJS 嵌套 JSON 对象到输入更新处理程序?
- matlab - 如何在 MATLAB 中删除特定的 uicontextmenu 选项(例如在图例的菜单中)
- gdb - gdb:反汇编代码中对“测试”的调用是什么?
- c++ - 为什么 ID3D11DeviceContext::Flush() 方法在查询 GPU 状态期间被调用两次
- javascript - 异步 - 由多个基于 Promise 的 API 调用形成的组织结构图,返回相互依赖的数据
- android - android.support.test.espresso.InjectEventSecurityException 当我尝试使用 espresso 填充几个编辑文本时抛出
- mysql - MySQL Document Store - 创建索引时参数的值无效