我们使用 Keycloak 来保护 Spring Boot SOAP 应用程序。我们希望根据 keycloak 中用户属性的信息来处理对应用程序的授权,而不是标准的“基于角色”访问。
例如,我们可以使用标准的 keycloak spring boot 适配器,配置如下:
keycloak.security-constraints[0].authRoles[0]=special-role
keycloak.security-constraints[0].securityCollections[0].patterns[0]=/service/*
这将确保只有具有“特殊角色”的用户才能访问该服务。但是是否可以编写自定义过滤器来查看用户属性的值而不是角色的值?
最佳答案
我们找到的解决方案是使用 Keycloak 的 Spring Security 适配器,然后指定我们自己的 bean 来检查 token :
@Component
public class WebSecurity {
public boolean check(Authentication authentication) throws Exception {
boolean result = false;
...
return result;
}
}
// In the web security configuration
http
.authorizeRequests()
.antMatchers(HttpMethod.POST, SOME_URL)
.access("@webSecurity.check(authentication)")
关于java - 基于自定义属性的 Spring Boot SOAP Web 服务的 Keycloak 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57598156/