ResourceServerConfigurer.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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.Bean;
  6. import org.springframework.context.annotation.ComponentScan;
  7. import org.springframework.context.annotation.Configuration;
  8. import org.springframework.core.io.ClassPathResource;
  9. import org.springframework.core.io.Resource;
  10. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  11. import org.springframework.security.jwt.crypto.sign.RsaVerifier;
  12. import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
  13. import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
  14. import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
  15. import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
  16. import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
  17. import org.springframework.util.FileCopyUtils;
  18. import java.io.IOException;
  19. /**
  20. * @Description: 权限资源配置类
  21. * @author: gaodm
  22. * @time: 2018/8/2 14:21
  23. */
  24. @Configuration
  25. @EnableResourceServer
  26. @ComponentScan({"com.diagbot.config"})
  27. public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {
  28. Logger log = LoggerFactory.getLogger(ResourceServerConfigurer.class);
  29. @Override
  30. public void configure(HttpSecurity http) throws Exception {
  31. http.cors()
  32. .and()
  33. .csrf().disable()
  34. .authorizeRequests()
  35. .regexMatchers(".*swagger.*", ".*v2.*", ".*webjars.*", "/druid.*", "/actuator.*", "/hystrix.*").permitAll()
  36. .antMatchers("/sys/user/getJwt").permitAll()
  37. .antMatchers("/sys/user/getJwtNoPass").permitAll()
  38. .antMatchers("/sys/user/refreshJwt").permitAll()
  39. .antMatchers("/sys/user/checkToken").permitAll()
  40. .antMatchers("/sys/dictionaryInfo/getDictionary").permitAll()
  41. .antMatchers("/oauth/token").permitAll()
  42. .antMatchers("/oauth/check_token").permitAll()
  43. .antMatchers("/cache/clear").permitAll()
  44. .antMatchers("/qc/behospitalInfo/execule").permitAll()
  45. .antMatchers("/qc/behospitalInfo/analyze_rpc").permitAll()
  46. .antMatchers("/qc/behospitalInfo/analyze_api").permitAll()
  47. .antMatchers("/qc/behospitalInfo/analyze_run").permitAll()
  48. .antMatchers("/qc/module/getById").permitAll()
  49. .antMatchers("/qc/module/getModuleMap").permitAll()
  50. .antMatchers("/qc/cases/getQcCases").permitAll()
  51. .antMatchers("/qc/behospitalInfo/page").permitAll()
  52. .antMatchers("/qc/casesEntryHospital/getQcCasesEntryAll").permitAll()
  53. .antMatchers("/qc/casesEntryHospital/getQcCasesAll").permitAll()
  54. .antMatchers("/qc/behospitalInfo/getByBehospitalCode").permitAll()
  55. .antMatchers("/bas/dept/getList").permitAll()
  56. .antMatchers("/bas/dept/getListUser").permitAll()
  57. .antMatchers("/qc/behospitalInfo/page_dept").permitAll()
  58. .antMatchers("/qc/behospitalInfo/page_person").permitAll()
  59. .antMatchers("/qc/behospitalInfo/page_group").permitAll()
  60. .antMatchers("/qc/casesEntryHospital/findQcCasesEntry").permitAll()
  61. .antMatchers("/qc/dataimport/import").permitAll()
  62. .antMatchers("/qc/dataimport/test").permitAll()
  63. .antMatchers("/qc/behospitalInfo/exportExcel").permitAll()
  64. .antMatchers("/qc/behospitalInfo/exportQcresult").permitAll()
  65. .antMatchers("/qc/behospitalInfo/exportQcresultByDept").permitAll()
  66. .antMatchers("/qc/behospitalInfo/exportQcresultByGroup").permitAll()
  67. .antMatchers("/qc/abnormal/getQcAnnormalMode").permitAll()
  68. .antMatchers("/qc/dataimport/import").permitAll()
  69. .antMatchers("/qc/dataimport/dataimportPrepare").permitAll()
  70. .antMatchers("/qc/dataimport/test").permitAll()
  71. .antMatchers("/sys/user/pageset/getPageSet").permitAll()
  72. .antMatchers("/sys/user/pageset/savePageSet").permitAll()
  73. .antMatchers("/consoleByDept/getDept").permitAll()
  74. .antMatchers("/console/entryRejectPercent").permitAll()
  75. .antMatchers("/console/qcResultLevelPercent").permitAll()
  76. .antMatchers("/console/averageStatistics").permitAll()
  77. .antMatchers("/console/entryByDept").permitAll()
  78. .antMatchers("/console/entryCountGroupByCase").permitAll()
  79. .antMatchers("/console/entryCountGroupByCasePage").permitAll()
  80. .antMatchers("/console/entryCountGroupByEntry").permitAll()
  81. .antMatchers("/console/entryCountGroupByEntryPage").permitAll()
  82. .antMatchers("/console/entryGroupByEntryInnerPage").permitAll()
  83. .antMatchers("/console/getAverageDayNum").permitAll()
  84. .antMatchers("/console/getAverageDayNumPage").permitAll()
  85. .antMatchers("/console/getAverageFee").permitAll()
  86. .antMatchers("/console/getAverageFeePage").permitAll()
  87. .antMatchers("/console/getAverageScore").permitAll()
  88. .antMatchers("/console/getAverageScoreByDeptClass").permitAll()
  89. .antMatchers("/console/getAverageScoreByDeptPage").permitAll()
  90. .antMatchers("/console/getLevelResultDept").permitAll()
  91. .antMatchers("/console/homePageLevelLimit").permitAll()
  92. .antMatchers("/console/homePageLevelStatistics").permitAll()
  93. .antMatchers("/console/leaveHosCount").permitAll()
  94. .antMatchers("/console/levelPercentGroupByDeptPage").permitAll()
  95. .antMatchers("/console/levelStatistics").permitAll()
  96. .antMatchers("/console/levelStatisticsByDeptClass").permitAll()
  97. .antMatchers("/console/mrCount").permitAll()
  98. .antMatchers("/console/mrStatistics").permitAll()
  99. .antMatchers("/console/qcResultShortPage").permitAll()
  100. .antMatchers("/console/resultStatistics").permitAll()
  101. .antMatchers("/console/resultStatisticsByDeptPage").permitAll()
  102. .antMatchers("/console/homePageMRCount").permitAll()
  103. .antMatchers("/console/qcCheckStatistics").permitAll()
  104. .antMatchers("/console/unModifyMRStatistics").permitAll()
  105. .antMatchers("/consoleByDept/entryCountGroupByCaseAndDept").permitAll()
  106. .antMatchers("/consoleByDept/entryCountGroupByCaseAndDeptPage").permitAll()
  107. .antMatchers("/consoleByDept/entryCountGroupByEntryAndDept").permitAll()
  108. .antMatchers("/consoleByDept/entryCountGroupByEntryAndDeptPage").permitAll()
  109. .antMatchers("/consoleByDept/entryGroupByEntryAndDeptInnerPage").permitAll()
  110. .antMatchers("/consoleByDept/homePageLevelByDeptLimit").permitAll()
  111. .antMatchers("/consoleByDept/homePageLevelStatisticsByDept").permitAll()
  112. .antMatchers("/consoleByDept/leaveHosCountByDept").permitAll()
  113. .antMatchers("/consoleByDept/levelStatisticsByDept").permitAll()
  114. .antMatchers("/consoleByDept/mrCountByDept").permitAll()
  115. .antMatchers("/consoleByDept/qcResultShortByDeptPage").permitAll()
  116. .antMatchers("/consoleByDept/resultStatisticsByDeptAndDoctorPage").permitAll()
  117. .antMatchers("/console/export/homePageLevelExport").permitAll()
  118. .antMatchers("/console/export/entryGroupByEntryExport").permitAll()
  119. .antMatchers("/console/export/levelExport").permitAll()
  120. .antMatchers("/console/entryStatistics").permitAll()
  121. .antMatchers("/console/export/levelExport_TZ").permitAll()
  122. .antMatchers("/console/export/getAverageDayNumExport").permitAll()
  123. .antMatchers("/console/export/getAverageFeeExport").permitAll()
  124. .antMatchers("/console/export/levelPercentGroupByDeptExport").permitAll()
  125. .antMatchers("/console/export/entryCountGroupByEntryExport").permitAll()
  126. .antMatchers("/console/export/entryCountGroupByCaseExport").permitAll()
  127. .antMatchers("/console/export/entryStatisticsExport").permitAll()
  128. .antMatchers("/console/export/qcResultShortPageExport").permitAll()
  129. .antMatchers("/console/export/leaveHosMrPageExport").permitAll()
  130. .antMatchers("/console/export/qcCheckStatisticsExport").permitAll()
  131. .antMatchers("/qc/data/sendDoctorInfos").permitAll()
  132. .antMatchers("/qc/data/sendDeptInfos").permitAll()
  133. .antMatchers("/qc/data/sendRecordTypes").permitAll()
  134. .antMatchers("/qc/data/sendMrRecordIng").permitAll()
  135. .antMatchers("/qc/data/sendMrContent").permitAll()
  136. .antMatchers("/qc/data/sendMrRecord").permitAll()
  137. .antMatchers("/qc/data/sendPatientInfo").permitAll()
  138. .antMatchers("/qc/data/sendDoctorAdvice").permitAll()
  139. .antMatchers("/qc/data/sendHomePageIng").permitAll()
  140. .antMatchers("/qc/data/sendHomePage").permitAll()
  141. .antMatchers("/qc/data/sendHomeDiagnose").permitAll()
  142. .antMatchers("/qc/data/sendHomeOperation").permitAll()
  143. .antMatchers("/qc/data/sendCrisis").permitAll()
  144. .antMatchers("/qc/doctoradvice/getPage").permitAll()
  145. .antMatchers("/**").authenticated();
  146. // .antMatchers("/**").permitAll();
  147. }
  148. @Override
  149. public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
  150. log.info("Configuring ResourceServerSecurityConfigurer");
  151. resources.resourceId("user-service").tokenStore(new JwtTokenStore(jwtTokenEnhancerClient()));
  152. }
  153. @Autowired
  154. private CustomAccessTokenConverter customAccessTokenConverter;
  155. @Bean("jwtTokenEnhancerClient")
  156. protected JwtAccessTokenConverter jwtTokenEnhancerClient() {
  157. JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
  158. Resource resource = new ClassPathResource("public.cert");
  159. String publicKey;
  160. try {
  161. publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
  162. } catch (IOException e) {
  163. throw new RuntimeException(e);
  164. }
  165. converter.setVerifierKey(publicKey);
  166. //不设置这个会出现 Cannot convert access token to JSON
  167. converter.setVerifier(new RsaVerifier(publicKey));
  168. converter.setAccessTokenConverter(customAccessTokenConverter);
  169. log.info("Created jwtTokenEnhancerClient success");
  170. return converter;
  171. }
  172. }