1

Accutly I work on Project with Jwt Authentication and I add a webservice for another project call that. and want to add Basic authentication for this service but another service must be work with jwt, is it possible we have two type authentication on spring boot?

this is my SecurityConfigurer for jwt and I want to add basic authentication.

@EnableWebSecurity
public class SecurityConfigurer extends WebSecurityConfigurerAdapter {


private JwtRequestFilter jwtRequestFilter;
private Environment environment;
private UserService userService;
private BCryptPasswordEncoder bCryptPasswordEncoder;

@Autowired
public SecurityConfigurer(Environment environment, UserService userService, BCryptPasswordEncoder bCryptPasswordEncoder, JwtRequestFilter jwtRequestFilter)
{
    this.environment = environment;
    this.userService = userService;
    this.bCryptPasswordEncoder = bCryptPasswordEncoder;
    this.jwtRequestFilter = jwtRequestFilter;
}

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userService).passwordEncoder(bCryptPasswordEncoder);
}


@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
    httpSecurity.csrf().disable()
            .authorizeRequests().antMatchers("/api/v1/users/authentication").permitAll()
            .antMatchers("/**").permitAll()
            .anyRequest().authenticated()
            .and()
            .exceptionHandling()
            .and().sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
    httpSecurity.cors();
}

@Override
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
    return super.authenticationManagerBean();
}

}

dariosicily
  • 4,239
  • 2
  • 11
  • 17
mostafa
  • 31
  • 4

0 Answers0