ResourceServerConfigurer.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package com.diagbot.config;
  2. import org.slf4j.Logger;
  3. import org.slf4j.LoggerFactory;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.context.annotation.Configuration;
  6. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  7. import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
  8. import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
  9. import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
  10. import org.springframework.security.oauth2.provider.token.TokenStore;
  11. /**
  12. * @Description: 权限资源配置类
  13. * @author: gaodm
  14. * @time: 2018/8/2 14:21
  15. */
  16. @Configuration
  17. @EnableResourceServer
  18. public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {
  19. Logger log = LoggerFactory.getLogger(ResourceServerConfigurer.class);
  20. @Override
  21. public void configure(HttpSecurity http) throws Exception {
  22. http
  23. .csrf().disable()
  24. .authorizeRequests()
  25. .regexMatchers(".*swagger.*",".*v2.*",".*webjars.*","/user/login.*","/user/registry.*","/user/test.*","/druid.*","/actuator.*","/hystrix.*","/hi.*","/test.*").permitAll()
  26. .antMatchers("/userver/getImgVerification").permitAll()
  27. .antMatchers("/userver/verifyImgVerification").permitAll()
  28. .antMatchers("/userver/getSmsWithRegister").permitAll()
  29. .antMatchers("/userver/getSmsWithResetPassword").permitAll()
  30. .antMatchers("/userver/verifySmsVerification").permitAll()
  31. .antMatchers("/user/resetPassword").permitAll()
  32. .antMatchers("/getUserEnumsData").permitAll()
  33. .antMatchers("/userInfo/getUserInfoPag").permitAll()
  34. .antMatchers("/user/getPermission").permitAll()
  35. .antMatchers("/userInfo/updateUserInfoAll").permitAll()
  36. .antMatchers("/userInfo/updateDeleted").permitAll()
  37. .antMatchers("/user/index").permitAll()
  38. .antMatchers("/**").authenticated();
  39. // .antMatchers("/**").permitAll();
  40. }
  41. @Override
  42. public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
  43. log.info("Configuring ResourceServerSecurityConfigurer ");
  44. resources.resourceId("user-service").tokenStore(tokenStore);
  45. }
  46. @Autowired
  47. TokenStore tokenStore;
  48. }