Guest User

Untitled

a guest
Oct 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. My spring Boot application will be getting request from two sources.
  2. Based on header I want to use JWT based authentication and if JWT is not present in header will use basic authentication.
  3. Is there a way to configure this condition in spring security?
  4.  
  5. Current Code snippet is below :
  6.  
  7. @Configuration
  8. @EnableWebSecurity
  9. public class SecurityConfig extends WebSecurityConfigurerAdapter {
  10.  
  11. @Autowired
  12. private CustomAuthenticationEntryPoint authEntryPoint;
  13.  
  14. @Value("${security.user.name}")
  15. private String userName;
  16.  
  17. @Value("${security.user.password}")
  18. private String userPassword;
  19.  
  20. @Override
  21. protected void configure(HttpSecurity http) throws Exception {
  22. http.csrf().disable()
  23. .authorizeRequests()
  24. .antMatchers(HttpMethod.GET,"/api/check").permitAll()
  25. .anyRequest().authenticated()
  26. .and().httpBasic()
  27. .and().exceptionHandling()
  28. .authenticationEntryPoint(authEntryPoint)
  29. .and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
  30.  
  31. http.addFilterBefore(new StargateAuthenticationFilter(), BasicAuthenticationFilter.class);
  32. }
Add Comment
Please, Sign In to add comment