我是 saml 2.0 的新手。我试图了解 saml 2.0 springboot 扩展。我看到了 Vincenzo De Notaris 和 Thomas Darimont 的示例应用程序。
这里是 git hub 示例:https://github.com/vdenotaris/spring-boot-security-saml-sample
在saml security config中,需要定义keymanager bean。因为 saml 扩展使用私钥签名和公共证书进行验证。如果我错了,请纠正我。
这里是 bean 定义。
@Bean
public KeyManager keyManager() {
DefaultResourceLoader loader = new DefaultResourceLoader();
Resource storeFile = loader
.getResource("classpath:/saml/samlKeystore.jks");
String storePass = "nalle123";
Map<String, String> passwords = new HashMap<>();
passwords.put("apollo", "nalle123");
String defaultKey = "apollo";
return new JKSKeyManager(storeFile, storePass, passwords, defaultKey);
}
here samlKeystore.jks 有一个过期的私钥,别名是 'apollo'.
还有两个别名为'ssocircle'和'startcom'的公共证书。
当我运行应用程序时,我看到只有私钥用于对消息进行签名。我看不到证书 ssocircle 的使用位置。我能够看到 ssocircle 登录页面并能够登录。
我从Keystore中删除了这个证书,我尝试再次登录,我仍然得到登录页面并且我能够成功登录。
keycloak也一样。 samlKeystore.jks 需要导入到客户端的密钥部分。我似乎不明白公共证书的必要性。
重现 重现行为的步骤。
从 https://github.com/vdenotaris/spring-boot-security-saml-sample 中查看代码。 在 resources/saml 文件夹中,从 samlKeystore.jks 中删除 ssocircle 证书,构建项目,然后运行 spring-boot 应用程序。 点击第三方登录时,成功登陆登录页面,允许您登录。
预期行为 它不应该允许您在没有有效证书的情况下登录。
想了解公证书的作用。它如何在生产环境中工作
这里是 keycloak 实现的链接: https://blog.codecentric.de/secure-spring-boot-app-saml-keycloak
当 SAML Spring 扩展从 IDP 接收到 SAML SSO 响应时,将使用身份提供者的证书(在您的情况下为 SSOCircle)。 SAML 响应或断言本身由 IDP 使用 IDP 的私钥签名。证书持有公钥,可用于验证签名。
在不涉及 IDP 证书的情况下,重定向到 IDP 的登录页面。 IDP 的登录不在 SAML 的范围内。您需要注意作为 POST 请求发送回 SPRING SAML 扩展的响应。