栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Spring Boot Actuator-无法禁用/ info端点

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Spring Boot Actuator-无法禁用/ info端点

最后,我设法解决了我的问题。我仅在执行器中启用了/ info和/ health端点。为了只允许具有ADMIN角色的用户访问/
info端点,我需要混合执行器管理安全性和spring安全性配置。

所以我的 application.yml 看起来像这样:

endpoints.enabled: falseendpoints:    info.enabled: true    health.enabled: truemanagement.security.role: ADMIN

像这样的spring安全配置(我需要更改 ManagementSecurityConfig的 顺序以具有更高的优先级):

@Configuration@EnableWebSecurity@EnableGlobalMethodSecurity(prePostEnabled = true)public class SecurityConfiguration {    @Configuration    protected static class AuthenticationSecurity extends GlobalAuthenticationConfigurerAdapter {        @Autowired        private AuthenticationProvider authenticationProvider;        public AuthenticationSecurity() { super();        }        @Override        public void init(AuthenticationManagerBuilder auth) throws Exception {  auth.inMemoryAuthentication().withUser("admin").password("secret").roles("ADMIN");        }    }    @Configuration    @Order(Ordered.HIGHEST_PRECEDENCE + 2)    public static class ManagementSecurityConfig extends WebSecurityConfigurerAdapter {        @Override        protected void configure(HttpSecurity http) throws Exception { http.csrf().disable()         .requestMatchers()         .antMatchers("/info/**")         .and()         .authorizeRequests()         .anyRequest().hasRole("ADMIN")         .and()         .httpBasic();        }    }    @Configuration    public static class ApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {        protected void configure(HttpSecurity http) throws Exception { // API security configuration        }    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/615664.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号