在生产环境中,我想禁用/actuator端点,但仍然允许使用/actuator/health。我已经使用SecurityConfigurerAdapter尝试了下面的代码,但它返回了500。我想返回一个404,并得到一个“页面未找到”的错误页面。任何帮助都是非常感谢的。
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
if(isProd) {
http.authorizeRequests().antMatchers("/actuator/", "/actuator").denyAll();
}
}发布于 2019-10-22 17:52:24
@Configuration
@EnableWebSecurity
//@EnableOAuth2Sso
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private JwtAuthenticationEntryPoint jwtAuthenticationEntryPoint;
@Autowired
private JwtRequestFilter jwtRequestFilter;
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
// dont authenticate this particular request
.authorizeRequests()
.antMatchers(
"/api/login",
"/user/create-new-user",
"/user/get-verification",
"/user/pwd-reset",
"/user/pwd-reset/verification",
"/api/swagger-ui.html")
.permitAll()
// .antMatchers("/**").permitAll().hasRole("ADMIN")
.anyRequest()
.fullyAuthenticated()
.and()
.exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint).and().sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
// .and()
// .logout()
// .logoutRequestMatcher(new AntPathRequestMatcher("/api/logout")).logoutSuccessUrl("/https://www.baeldung.com/spring-security-logout")
// .invalidateHttpSession(true).deleteCookies("JSESSIONID");
// Add a filter to validate the tokens with every request
http
.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
}
}或者使用这种方式
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/home").access("hasRole('USER')")
.antMatchers("/admin/**").hasRole("ADMIN")
.and()
// some more method calls
.formLogin();
}发布于 2019-10-22 17:04:26
你不需要使用Spring Security。
这可以使用属性进行配置:
默认情况下,健康和信息是通过web公开的。
因此您可以在生产和开发中使用来运行您的应用程序
-Dmanagement.endpoints.web.exposure.include=*https://stackoverflow.com/questions/58500599
复制相似问题