You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.7 KiB

  1. package com.mdp;
  2. import com.mdp.safe.client.jwt.JwtAuthenticationConverter;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  5. import org.springframework.security.config.annotation.web.builders.WebSecurity;
  6. import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  7. import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  8. import org.springframework.security.oauth2.jwt.JwtDecoder;
  9. /**
  10. * com.qqkj.WebSecurityConfig
  11. *
  12. * @author chenyc
  13. * @date 2019/10/10
  14. */
  15. @EnableWebSecurity
  16. public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  17. @Autowired
  18. JwtAuthenticationConverter jwtConverter;
  19. @Autowired
  20. JwtDecoder jwtDecoder;
  21. @Override
  22. public void configure(WebSecurity web) throws Exception {
  23. web.ignoring().antMatchers("/webjars/**","/**/arc/image/**/**.*");
  24. }
  25. /**
  26. * 允许匿名访问所有接口 主要是 oauth 接口
  27. * @param http
  28. * @throws Exception
  29. */
  30. @Override
  31. protected void configure(HttpSecurity http) throws Exception {
  32. http.authorizeRequests().antMatchers("/**/arc/image/**","/**/arc/archive/showArchive","/**/arc/file/**","/**/arc/archive/listNews",
  33. "/**/arc/category/list/tree").permitAll().anyRequest().authenticated().and().oauth2Client().and().logout().disable();
  34. http.oauth2Client().and().logout().disable();
  35. http.formLogin().usernameParameter("userloginid");
  36. http.oauth2Login();
  37. http.oauth2ResourceServer().jwt().decoder(jwtDecoder).jwtAuthenticationConverter(jwtConverter);
  38. http.csrf().disable();
  39. }
  40. }