Мне нужно решить 2 способа аутентификации:
- конечные точки привода с базой c
остальные конечные точки с oauth jwt token
Мы закончили oauth-аутентификация, но сейчас мы попытались расширить ее с помощью другой защиты для исполнительного механизма. Код ниже показывает, что мы пытались. Привод начинает работать с аутентификацией basi c, но oauth-аутентификация для остальных конечных точек не работает.
Мы можем вызывать любые конечные точки без маркера oauth.
@Configuration
@RequiredArgsConstructor
public class WebSecurityConfig {
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Order(2)
@Configuration
public class DefaultConfiguration extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsServiceImpl;
@Override
public void configure(HttpSecurity http) throws Exception {
http
.sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.authorizeRequests(authorizeRequests -> {
authorizeRequests.antMatchers("/unsecured**").permitAll().anyRequest().authenticated();
})
.csrf(AbstractHttpConfigurer::disable);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.userDetailsService(userDetailsServiceImpl)
.passwordEncoder(passwordEncoder());
}
@Bean(name = "authenticationManager")
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
final AuthenticationManager authenticationManager = super.authenticationManagerBean();
return authenticationManager;
}
}
@Order(1)
@Configuration
public class ActuatorConfiguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.requestMatchers(EndpointRequest.toAnyEndpoint()).hasRole("ADMIN")
.and().httpBasic();
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user")
.roles("ADMIN")
.password(passwordEncoder().encode("pass"));
}
}
}