我有一个在端口8081上运行此配置的Spring Boot App:
@Configuration
@EnableMethodSecurity
public class WebSecurityConfig { // extends WebSecurityConfigurerAdapter {
private final JwtUtils jwtUtils;
private final UserDetailsServiceImpl userDetailsService;
private final AuthEntryPointJwt unauthorizedHandler;
public WebSecurityConfig(JwtUtils jwtUtils,
UserDetailsServiceImpl userDetailsService,
AuthEntryPointJwt unauthorizedHandler) {
this.jwtUtils = jwtUtils;
this.userDetailsService = userDetailsService;
this.unauthorizedHandler = unauthorizedHandler;
}
@Bean
public AuthTokenFilter authenticationJwtTokenFilter() {
return new AuthTokenFilter(jwtUtils, userDetailsService);
}
@Bean
public DaoAuthenticationProvider authenticationProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService);
authProvider.setPasswordEncoder(passwordEncoder());
return authProvider;
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http.csrf(AbstractHttpConfigurer::disable)
.exceptionHandling(exception -> exception.authenticationEntryPoint(unauthorizedHandler))
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeHttpRequests(auth ->
auth.requestMatchers("/api/auth/**").permitAll()
.requestMatchers("/actuator/**").permitAll()
.requestMatchers("/actuator/metrics").permitAll()
.requestMatchers("/api/languages").permitAll()
.requestMatchers("/api/actuator/health").permitAll()
.requestMatchers("/api/auth/sendMailOTP").permitAll()
.requestMatchers("/api/messages/**").permitAll()
.requestMatchers("/api/auth/socialSignin").permitAll()
.requestMatchers("/api/geoDetails").permitAll()
.requestMatchers("/api/legalinfo/**").permitAll()
.requestMatchers("/api/legalinfo/*").permitAll()
.requestMatchers("/api/legalinfo/eula").permitAll()
.requestMatchers("/api/users/uploadFile/**").permitAll()
.requestMatchers("/api/users/sendEmail").permitAll()
.requestMatchers("/api/legalinfo/privacy").permitAll()
.requestMatchers("/api/changeuserpassword").permitAll()
.requestMatchers("/api/forgotmypassword").permitAll()
.requestMatchers("/api/validateEmail").permitAll()
.requestMatchers("/api/checkToken").permitAll()
.requestMatchers("/api/checkOTPToken").permitAll()
.anyRequest().authenticated()
);
http.authenticationProvider(authenticationProvider());
http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
return http.build();
}
}
正在做的事:http://172.105.90.17:8081/actuator/health
我得到了:
{
"status": "UP"
}
但访问:http://172.105.90.17:8081/actuator/metrics
我收到:
{
"message": "Full authentication is required to access this resource"
}
在控制台中:
2024-01-24 06:47:28.884 DEBUG [] o.s.b.f.s.DefaultListableBeanFactory@registerDependentBeans(952) - Autowiring by type from bean name 'webEndpointServletHandlerMapping' via factory method to bean named 'management.endpoints.web-org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties'
2024-01-24 06:47:28.884 DEBUG [] o.s.b.f.s.DefaultListableBeanFactory@registerDependentBeans(952) - Autowiring by type from bean name 'webEndpointServletHandlerMapping' via factory method to bean named 'environment'
2024-01-24 06:47:28.891 INFO [] o.s.b.a.e.web.EndpointLinksResolver@<init>(58) - Exposing 1 endpoint(s) beneath base path '/actuator'
2024-01-24 06:47:28.905 DEBUG [] o.s.b.f.s.DefaultListableBeanFactory@getSingleton(225) - Creating shared instance of singleton bean 'controllerEndpointHandlerMapping'