Уважаемые,
Нужна помощь в следующем вопросе.
Я пытаюсь создать общую библиотеку аутентификации для использования несколькими приложениями MFE. эта библиотека зависит от Spring Web Security. Проблема в том, что реализация WebSecurityConfigurerAdapter не применяется, если она находится внутри библиотеки, однако, если она используется непосредственно в приложении, она будет работать.
Ошибка: ПАРАМЕТРЫ Сбой методов
Метод Over Configure () вызывается при запуске приложения в обоих случаях (внутри библиотеки, непосредственно внутри приложения)
Ниже приведен снимок экрана с запросом об успешном выполнении (непосредственно внутри приложения) успех внутри приложения напрямую
Ниже приведен снимок экрана с ошибочным запросом (внутри библиотеки) Сбой внутри библиотеки
Ниже приведена реализация WebSecurityConfigurerAdapter:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class JWTWebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private JwtUnAuthorizedResponseAuthenticationEntryPoint jwtUnAuthorizedResponseAuthenticationEntryPoint;
@Autowired
private UserDetailsService jwtInMemoryUserDetailsService;
@Autowired
private JwtTokenAuthorizationOncePerRequestFilter jwtAuthenticationTokenFilter;
@Value("${jwt.get.token.uri}")
private String authenticationPath;
@Bean
public PasswordEncoder passwordEncoderBean() {
return new BCryptPasswordEncoder();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(jwtInMemoryUserDetailsService)
.passwordEncoder(passwordEncoderBean());
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity
.csrf().disable()
.exceptionHandling().authenticationEntryPoint(jwtUnAuthorizedResponseAuthenticationEntryPoint).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
.authorizeRequests()
.anyRequest().authenticated();
httpSecurity
.addFilterBefore(jwtAuthenticationTokenFilter, UsernamePasswordAuthenticationFilter.class);
httpSecurity
.headers()
.frameOptions().sameOrigin() //H2 Console Needs this setting
.cacheControl(); //disable caching
}
@Override
public void configure(WebSecurity webSecurity) throws Exception {
webSecurity
.ignoring()
.antMatchers(
HttpMethod.POST,
authenticationPath
)
.antMatchers(HttpMethod.OPTIONS, "/**")
.and()
.ignoring()
.antMatchers(
HttpMethod.GET,
"/" //Other Stuff You want to Ignore
)
.and()
.ignoring()
.antMatchers("/h2-console/**/**");//Should not be in Production!
}
}
Заключение Нет, я создаю библиотеку, которая использует Spring Security внутри этой библиотеки реализации WebSecurityConfigurerAdapter. добавив эту библиотеку в качестве зависимости для другого приложения, она не будет работать. Хотя, если использовать эту реализацию непосредственно на самом приложении, будет работать нормально. Примечание. В этой библиотеке есть фильтр и все, что связано с реализацией JWT, которая будет многократно используемой библиотекой для нескольких приложений.