当我尝试从tomcat(springboot)上的其他服务器发送请求时,看到错误。告诉我如何解决这个问题?我使用的是Java 1.8,春季:2.1.2.RELEASE。 问题恰恰是服务器在处理来自另一台服务器的请求时。
错误:
2019-02-18 23:37:30.150 ERROR 7444 --- [nio-8080-exec-8]
w.a.UsernamePasswordAuthenticationFilter : An internal error occurred while
trying to authenticate the user.
WebMvcConfig:
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
private final long MAX_AGE_SECS = 3600;
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("HEAD", "OPTIONS", "GET", "POST", "PUT", "PATCH", "DELETE")
.maxAge(MAX_AGE_SECS);
}
}
SecurityConfig:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private final UserDetailsServiceImpl userDetailsService;
@Autowired
public SecurityConfig(UserDetailsServiceImpl userDetailsService) {
this.userDetailsService = userDetailsService;
}
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth
.userDetailsService(userDetailsService).passwordEncoder(NoOpPasswordEncoder.getInstance());
}
@Bean(name = BeanIds.AUTHENTICATION_MANAGER)
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.cors().and().csrf().disable()
.authorizeRequests().antMatchers("/resources/**").permitAll()
.anyRequest().authenticated()
.and()
.httpBasic()
.and()
.formLogin().loginPage("/login").permitAll()
.permitAll()
.defaultSuccessUrl("/user/getrole")
.and()
.logout()
.logoutSuccessUrl("/login")
.permitAll();
}
}