ResourceServerConfig.java 1.1 KB

1234567891011121314151617181920212223242526
  1. package com.huaxu.config;
  2. import org.springframework.context.annotation.Configuration;
  3. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  4. import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
  5. import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
  6. @Configuration
  7. @EnableResourceServer
  8. public class ResourceServerConfig extends ResourceServerConfigurerAdapter {
  9. @Override
  10. public void configure(HttpSecurity http) throws Exception {
  11. http
  12. .csrf().disable()
  13. .requestMatchers().antMatchers("/**")
  14. .and()
  15. .authorizeRequests()
  16. .antMatchers("/swagger-ui.html","/webjars/**", "/webjars/**", "/swagger-resources/**",
  17. "/v2/**")
  18. .permitAll() //配置不需要身份认证的请求路径
  19. .anyRequest().authenticated() //其他所有访问路径都需要身份认证
  20. .and()
  21. .httpBasic();
  22. }
  23. }