[英]Keycloak authentication for a Spring Boot SOAP webservice based on custom atribute
我們正在使用Keycloak保護Spring Boot SOAP應用程序。 我們希望基於來自密鑰斗篷中用戶屬性的信息來處理對應用程序的授權,這與標准的“基於角色”的訪問相反。
例如,我們可以使用具有以下配置的標准keycloak彈簧引導適配器:
keycloak.security-constraints[0].authRoles[0]=special-role
keycloak.security-constraints[0].securityCollections[0].patterns[0]=/service/*
這將確保只有具有“特殊角色”的用戶才能訪問該服務。 但是是否可以編寫一個自定義過濾器來查看用戶屬性而不是角色的值?
我們來到的解決方案是將Spring Security適配器用於Keycloak,然后指定我們自己的bean來檢查令牌:
@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)")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.