为keydepot角色动态定义springboot antmatcher

xzlaal3s  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(237)

我认识keydeap有几天了,它是一个非常有趣的工具。我现在遇到了一个困难,也许是因为我缺乏经验。我正在开发一个JavaSpringBoot应用程序,我想根据用户角色定义权限。我已经创建了一个领域,用户,定义的角色,基于这些角色创建了资源和权限。我还使用了权限评估工具来检查不同用户的不同权限。
当我在keydepowebsecurityconfigureadapt类中定义静态路由时,一切都正常,但我希望我可以这样做

  1. @Override
  2. protected void configure(HttpSecurity http) throws Exception {
  3. super.configure(http);
  4. ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry expressionInterceptUrlRegistry = http.cors() //
  5. .and()
  6. .csrf().disable()
  7. .anonymous().disable()
  8. .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
  9. .and()
  10. .authorizeRequests();
  11. for(String role : getRoles(KeycloakClientOrKeycloakRealm)) {
  12. for(String ressource : getAllowedRessourcesList(role)) {
  13. expressionInterceptUrlRegistry = expressionInterceptUrlRegistry.antMatchers(ressource).hasRole(role);
  14. }
  15. }
  16. expressionInterceptUrlRegistry.anyRequest().authenticated();
  17. }

对getroles(keydovetclientorkeycloakrealm)和getallowedressourceslist(role)函数有什么建议吗?我非常感谢你花时间阅读

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题