ResourceServerConfig.java 1.1 KB

123456789101112131415161718192021222324252627
  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. "/user/findUserIdsByPermissonOrg",
  18. "/v2/**")
  19. .permitAll() //配置不需要身份认证的请求路径
  20. .anyRequest().authenticated() //其他所有访问路径都需要身份认证
  21. .and()
  22. .httpBasic();
  23. }
  24. }