Настройка Spring Security WebAuthnJAVA

Программисты JAVA общаются здесь
Anonymous
Настройка Spring Security WebAuthn

Сообщение Anonymous »

У меня есть проблема с реализацией WebAuthn
На данный момент у меня есть авторизация токена JWT с помощью пользовательского userDetailsService и userDetails .
Я хочу получить jwt token после успешной авторизации. /> Проблемы :
  • Я получил расширение java.lang.illegalStateException: отсутствующий пользовательскую черту Bean
. UserDetailsService Bean он должен использовать. Итак, есть вопрос: Как установить мой пользовательский пользователь пользователей userdetailsservice в webauthn?@Configuration
@EnableWebSecurity
@EnableMethodSecurity
@AllArgsConstructor
public class SecurityConfig {

JwtAuthFilter jwtAuthFilter;

@Bean
public UserDetailsService userDetailsService() {
return new UserDetailsServiceImpl();
}

@Bean
CorsConfigurationSource corsConfigurationSource() {
CorsConfiguration configuration = new CorsConfiguration();

configuration.setAllowedOrigins(Arrays.asList(
"ORIGINS"
));
configuration.setAllowedHeaders(List.of("*"));
configuration.setAllowedMethods(List.of("*"));
configuration.setAllowCredentials(true);

UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}

@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http.cors(Customizer.withDefaults()).csrf(AbstractHttpConfigurer::disable);
http.authorizeHttpRequests(auth -> auth.requestMatchers("/api/admin/**").hasRole("ADMIN").requestMatchers(
"PUBLIC ROUTERS"
).permitAll().anyRequest().authenticated());
http.sessionManagement(manager -> manager.sessionCreationPolicy(SessionCreationPolicy.STATELESS));
http.authenticationManager(authenticationProvider());
http.logout(logout -> logout.clearAuthentication(true).invalidateHttpSession(true).deleteCookies("JSESSIONID"));
http.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class);
http.exceptionHandling(handler -> handler.authenticationEntryPoint(new HttpStatusEntryPoint(HttpStatus.FORBIDDEN)));
// **Problem code**
http.webAuthn(web-> web
.allowedOrigins("localhost",
"https://app-test.1autokolonna.ru/",
"https://server-test.1autokolonna.ru/",
"https://app.1autokolonna.ru/",
"https://server.1autokolonna.ru/"
)
.rpId("1autokolonna.ru")
.rpName("1Autokolonna rely party")
);
// **Problem code**

return http.build();
}

@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}

@Bean
public AuthenticationManager authenticationProvider() {
DaoAuthenticationProvider authenticationProvider = new DaoAuthenticationProvider(userDetailsService());
authenticationProvider.setPasswordEncoder(passwordEncoder());
return new ProviderManager(authenticationProvider);
}
}
< /code>
@Component
public class UserDetailsServiceImpl implements UserDetailsService {

@Autowired
private UserRepository userRepository;

private static final Logger logger = LoggerFactory.getLogger(UserDetailsServiceImpl.class);

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
logger.debug("Entering in loadUserByUsername Method...");
User user = userRepository.findByPhone(username);
if(user == null){
logger.error("Username not found: " + username);
throw new UsernameNotFoundException("could not found user..!!");
}
return new CustomUserDetails(user);
}
}
< /code>
public class CustomUserDetails extends User implements UserDetails {

private final String username;
private final String password;
Collection

Подробнее здесь: https://stackoverflow.com/questions/796 ... irguration

Вернуться в «JAVA»