ResourceServerConfigurer.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  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/getCaptcha").permitAll()
  38. .antMatchers("/sys/user/getHospitalMark").permitAll()
  39. .antMatchers("/sys/user/getJwtNoPass").permitAll()
  40. .antMatchers("/sys/user/refreshJwt").permitAll()
  41. .antMatchers("/sys/user/checkToken").permitAll()
  42. .antMatchers("/sys/dictionaryInfo/getDictionary").permitAll()
  43. .antMatchers("/oauth/token").permitAll()
  44. .antMatchers("/oauth/check_token").permitAll()
  45. .antMatchers("/cache/clear").permitAll()
  46. .antMatchers("/qc/behospitalInfo/execule").permitAll()
  47. .antMatchers("/qc/behospitalInfo/analyze_rpc").permitAll()
  48. .antMatchers("/qc/behospitalInfo/analyze_api").permitAll()
  49. .antMatchers("/qc/behospitalInfo/analyze_run").permitAll()
  50. .antMatchers("/qc/module/getById").permitAll()
  51. .antMatchers("/qc/module/getModuleMap").permitAll()
  52. .antMatchers("/qc/cases/getQcCases").permitAll()
  53. .antMatchers("/qc/behospitalInfo/page").permitAll()
  54. .antMatchers("/qc/casesEntryHospital/getQcCasesEntryAll").permitAll()
  55. .antMatchers("/qc/casesEntryHospital/getQcCasesAll").permitAll()
  56. .antMatchers("/qc/behospitalInfo/getByBehospitalCode").permitAll()
  57. .antMatchers("/bas/dept/getList").permitAll()
  58. .antMatchers("/bas/dept/getListUser").permitAll()
  59. .antMatchers("/qc/behospitalInfo/page_dept").permitAll()
  60. .antMatchers("/qc/behospitalInfo/page_person").permitAll()
  61. .antMatchers("/qc/behospitalInfo/page_group").permitAll()
  62. .antMatchers("/qc/casesEntryHospital/findQcCasesEntry").permitAll()
  63. .antMatchers("/qc/dataimport/import").permitAll()
  64. .antMatchers("/qc/dataimport/test").permitAll()
  65. .antMatchers("/qc/behospitalInfo/exportExcel").permitAll()
  66. .antMatchers("/qc/behospitalInfo/exportQcresult").permitAll()
  67. .antMatchers("/qc/behospitalInfo/exportQcresultByDept").permitAll()
  68. .antMatchers("/qc/behospitalInfo/exportQcresultByGroup").permitAll()
  69. .antMatchers("/qc/abnormal/getQcAnnormalMode").permitAll()
  70. .antMatchers("/qc/dataimport/import").permitAll()
  71. .antMatchers("/qc/dataimport/dataimportPrepare").permitAll()
  72. .antMatchers("/qc/dataimport/test").permitAll()
  73. .antMatchers("/sys/user/pageset/getPageSet").permitAll()
  74. .antMatchers("/sys/user/pageset/savePageSet").permitAll()
  75. .antMatchers("/sys/user/pageset/getDefultPageSet").permitAll()
  76. .antMatchers("/consoleByDept/getDept").permitAll()
  77. .antMatchers("/console/entryRejectPercent").permitAll()
  78. .antMatchers("/console/qcResultLevelPercent").permitAll()
  79. .antMatchers("/console/averageStatistics").permitAll()
  80. .antMatchers("/console/entryByDept").permitAll()
  81. .antMatchers("/console/entryCountGroupByCase").permitAll()
  82. .antMatchers("/console/entryCountGroupByCasePage").permitAll()
  83. .antMatchers("/console/entryCountGroupByEntry").permitAll()
  84. .antMatchers("/console/entryCountGroupByEntryPage").permitAll()
  85. .antMatchers("/console/entryCountGroupXYByEntryPage").permitAll()
  86. .antMatchers("/console/entryGroupByEntryInnerPage").permitAll()
  87. .antMatchers("/console/getAverageDayNum").permitAll()
  88. .antMatchers("/console/getAverageDayNumPage").permitAll()
  89. .antMatchers("/console/getAverageFee").permitAll()
  90. .antMatchers("/console/getAverageFeePage").permitAll()
  91. .antMatchers("/console/getAverageScore").permitAll()
  92. .antMatchers("/console/getAverageScoreByDeptClass").permitAll()
  93. .antMatchers("/console/getAverageScoreByDeptPage").permitAll()
  94. .antMatchers("/console/getLevelResultDept").permitAll()
  95. .antMatchers("/console/homePageLevelLimit").permitAll()
  96. .antMatchers("/console/homePageLevelStatistics").permitAll()
  97. .antMatchers("/console/homePageLevelStatisticsXY").permitAll()
  98. .antMatchers("/console/export/homePageLevelXYExport").permitAll()
  99. .antMatchers("/consoleByDept/homePageLevelStatisticsXYByDept").permitAll()
  100. .antMatchers("/print/export/homePageLevelXYExportByDept").permitAll()
  101. .antMatchers("/consoleByDept/entryCountGroupXYByEntryPageDept").permitAll()
  102. .antMatchers("/print/export/entryCountGroupXYByExportDept").permitAll()
  103. .antMatchers("/consoleByDept/qcResultShortXYPageByDept").permitAll()
  104. .antMatchers("/print/export/qcResultShortXYPageExportDept").permitAll()
  105. .antMatchers("/consoleByDept/badLevelXYPageByDept").permitAll()
  106. .antMatchers("/print/export/badLevelPageXYExportByDept").permitAll()
  107. .antMatchers("/console/leaveHosCount").permitAll()
  108. .antMatchers("/console/medicalRecordIndicator").permitAll()
  109. .antMatchers("/console/codingMonthly").permitAll()
  110. .antMatchers("/console/levelPercentGroupByDeptPage").permitAll()
  111. .antMatchers("/console/levelStatistics").permitAll()
  112. .antMatchers("/console/levelStatisticsByDeptClass").permitAll()
  113. .antMatchers("/console/mrCount").permitAll()
  114. .antMatchers("/console/mrStatistics").permitAll()
  115. .antMatchers("/console/qcResultShortPage").permitAll()
  116. .antMatchers("/console/qcResultShortXYPage").permitAll()
  117. .antMatchers("/console/resultStatistics").permitAll()
  118. .antMatchers("/console/resultStatisticsByDeptPage").permitAll()
  119. .antMatchers("/console/homePageMRCount").permitAll()
  120. .antMatchers("/console/qcCheckStatistics").permitAll()
  121. .antMatchers("/console/unModifyMRStatistics").permitAll()
  122. .antMatchers("/console/unModifyMRPage").permitAll()
  123. .antMatchers("/console/reHos31DaysPage").permitAll()
  124. .antMatchers("/console/beHosCount").permitAll()
  125. .antMatchers("/console/casesEntryStatisticsById").permitAll()
  126. .antMatchers("/console/hmImproveMRPage").permitAll()
  127. .antMatchers("/console/qcCheckMRPage").permitAll()
  128. .antMatchers("/consoleByDept/entryCountGroupByCaseAndDept").permitAll()
  129. .antMatchers("/consoleByDept/entryCountGroupByCaseAndDeptPage").permitAll()
  130. .antMatchers("/consoleByDept/entryCountGroupByEntryAndDept").permitAll()
  131. .antMatchers("/consoleByDept/entryCountGroupByEntryAndDeptPage").permitAll()
  132. .antMatchers("/consoleByDept/entryGroupByEntryAndDeptInnerPage").permitAll()
  133. .antMatchers("/consoleByDept/homePageLevelByDeptLimit").permitAll()
  134. .antMatchers("/consoleByDept/homePageLevelStatisticsByDept").permitAll()
  135. .antMatchers("/consoleByDept/leaveHosCountByDept").permitAll()
  136. .antMatchers("/consoleByDept/levelStatisticsByDept").permitAll()
  137. .antMatchers("/consoleByDept/mrCountByDept").permitAll()
  138. .antMatchers("/consoleByDept/qcResultShortByDeptPage").permitAll()
  139. .antMatchers("/consoleByDept/resultStatisticsByDeptAndDoctorPage").permitAll()
  140. .antMatchers("/console/export/homePageLevelExport").permitAll()
  141. .antMatchers("/console/export/entryGroupByEntryExport").permitAll()
  142. .antMatchers("/console/export/levelExport").permitAll()
  143. .antMatchers("/console/entryStatistics").permitAll()
  144. .antMatchers("/console/export/levelExport_TZ").permitAll()
  145. .antMatchers("/console/export/getAverageDayNumExport").permitAll()
  146. .antMatchers("/console/export/getAverageFeeExport").permitAll()
  147. .antMatchers("/console/export/levelPercentGroupByDeptExport").permitAll()
  148. .antMatchers("/console/export/entryCountGroupByEntryExport").permitAll()
  149. .antMatchers("/console/export/entryCountGroupXYByEntryExport").permitAll()
  150. .antMatchers("/console/export/entryCountGroupByCaseExport").permitAll()
  151. .antMatchers("/console/export/entryStatisticsExport").permitAll()
  152. .antMatchers("/console/export/qcResultShortPageExport").permitAll()
  153. .antMatchers("/console/export/qcResultShortXYPageExport").permitAll()
  154. .antMatchers("/console/export/leaveHosMrPageExport").permitAll()
  155. .antMatchers("/console/export/qcCheckStatisticsExport").permitAll()
  156. .antMatchers("/console/export/unModifyMRPageExport").permitAll()
  157. .antMatchers("/console/export/unModifyMRStatisticsExport").permitAll()
  158. .antMatchers("/console/export/reHos31DaysPageExport").permitAll()
  159. .antMatchers("/console/export/hmImproveMRPageExport").permitAll()
  160. .antMatchers("/console/export/qcCheckMRPageExport").permitAll()
  161. .antMatchers("/qc/data/sendDoctorInfos").permitAll()
  162. .antMatchers("/qc/data/sendDeptInfos").permitAll()
  163. .antMatchers("/qc/data/sendRecordTypes").permitAll()
  164. .antMatchers("/qc/data/sendMrRecordIng").permitAll()
  165. .antMatchers("/qc/data/sendMrContent").permitAll()
  166. .antMatchers("/qc/data/sendMrRecord").permitAll()
  167. .antMatchers("/qc/data/sendPatientInfo").permitAll()
  168. .antMatchers("/qc/data/sendDoctorAdvice").permitAll()
  169. .antMatchers("/qc/data/sendHomePageIng").permitAll()
  170. .antMatchers("/qc/data/sendHomePage").permitAll()
  171. .antMatchers("/qc/data/sendHomeDiagnose").permitAll()
  172. .antMatchers("/qc/data/sendHomeOperation").permitAll()
  173. .antMatchers("/qc/data/sendCrisis").permitAll()
  174. .antMatchers("/qc/data/deleteFlag").permitAll()
  175. .antMatchers("/qc/data/placeFile").permitAll()
  176. .antMatchers("/qc/data/sendLisResults").permitAll()
  177. .antMatchers("/qc/data/sendPacsResults").permitAll()
  178. .antMatchers("/qc/data/getColumnZhAndCh").permitAll()
  179. .antMatchers("/qc/data/analyseRec").permitAll()
  180. .antMatchers("/qc/data/hisDataDeal").permitAll()
  181. .antMatchers("/qc/data_str/sendAdmissionNote").permitAll()
  182. .antMatchers("/qc/data_str/sendBloodResult").permitAll()
  183. .antMatchers("/qc/data_str/sendBloodTransfusion").permitAll()
  184. .antMatchers("/qc/data_str/sendConsultationApply").permitAll()
  185. .antMatchers("/qc/data_str/sendConsultationNote").permitAll()
  186. .antMatchers("/qc/data_str/sendConsultationRecord").permitAll()
  187. .antMatchers("/qc/data_str/sendConsultationResult").permitAll()
  188. .antMatchers("/qc/data_str/sendCrisisNote").permitAll()
  189. .antMatchers("/qc/data_str/sendDeathDiscussion").permitAll()
  190. .antMatchers("/qc/data_str/sendDeathNote").permitAll()
  191. .antMatchers("/qc/data_str/sendDifficultCase").permitAll()
  192. .antMatchers("/qc/data_str/sendFirstRecord").permitAll()
  193. .antMatchers("/qc/data_str/sendIllCritically").permitAll()
  194. .antMatchers("/qc/data_str/sendIllSeriousl").permitAll()
  195. .antMatchers("/qc/data_str/sendLeaveHospital").permitAll()
  196. .antMatchers("/qc/data_str/sendOperativeFirstRecord").permitAll()
  197. .antMatchers("/qc/data_str/sendOperativeNote").permitAll()
  198. .antMatchers("/qc/data_str/sendWardRecord").permitAll()
  199. .antMatchers("/qc/data_str/sendTransferOutNote").permitAll()
  200. .antMatchers("/qc/data_str/sendTransferInNote").permitAll()
  201. .antMatchers("/qc/data_str/sendRescueNote").permitAll()
  202. .antMatchers("/qc/data_str/sendPeriodConclusion").permitAll()
  203. .antMatchers("/qc/data_str/sendPreoperativeDiscussion").permitAll()
  204. .antMatchers("/qc/data_str/sendTalkInform").permitAll()
  205. .antMatchers("/qc/data_str/sendInformedConsent").permitAll()
  206. .antMatchers("/qc/data_str/sendContent").permitAll()
  207. .antMatchers("/qc/doctoradvice/getPage").permitAll()
  208. .antMatchers("/qc/medPacsInfo/getCheckPage").permitAll()
  209. .antMatchers("/qc/medLisInfo/getExaminePage").permitAll()
  210. .antMatchers("/qc/medLisInfo/getExamineSonPage").permitAll()
  211. .antMatchers("/console/medicalCheckForm").permitAll()
  212. .antMatchers("/qc/behospitalInfo/analyzeCds").permitAll()
  213. .antMatchers("/console/medicalCheckTitle").permitAll()
  214. .antMatchers("/console/export/medicalCheckExport").permitAll()
  215. .antMatchers("/console/export/medicalCheckInnerExport").permitAll()
  216. .antMatchers("/console/badLevelPage").permitAll()
  217. .antMatchers("/console/badLevelXYPage").permitAll()
  218. .antMatchers("/console/export/badLevelPagePageExport").permitAll()
  219. .antMatchers("/console/export/badLevelPageXYExport").permitAll()
  220. .antMatchers("/qc/medNurse/getMedNursePage").permitAll()
  221. .antMatchers("/qc/behospitalInfo/exportQcresultByPerson").permitAll()
  222. .antMatchers("/consoleByDept/beHosCountByDept").permitAll()
  223. .antMatchers("/consoleByDept/casesEntryStatisticsByDept").permitAll()
  224. .antMatchers("/bas/doctor/getList").permitAll()
  225. .antMatchers("/consoleByDept/homePageOrGoodLevelByDept").permitAll()
  226. .antMatchers("/print/export/homePageLevelExportByDept").permitAll()
  227. .antMatchers("/print/export/homePageOrLevelExportByDept").permitAll()
  228. .antMatchers("/print/export/entryGroupExportByDeptPage").permitAll()
  229. .antMatchers("/print/export/entryGroupExportByDeptCase").permitAll()
  230. .antMatchers("/print/export/entryGroupExportByDeptEntry").permitAll()
  231. .antMatchers("/print/export/qcResultShortExportByDeptPage").permitAll()
  232. .antMatchers("/print/export/levelExportByDept").permitAll()
  233. .antMatchers("/consoleByDept/entryStatisticsByDept").permitAll()
  234. .antMatchers("/print/export/entryStatisticsExportByDept").permitAll()
  235. .antMatchers("/consoleByDept/leaveHosMRPageByDept").permitAll()
  236. .antMatchers("/print/export/leaveHosMrPageExportByDept").permitAll()
  237. .antMatchers("/consoleByDept/qcCheckStatisticsByDept").permitAll()
  238. .antMatchers("/print/export/qcCheckStaExportByDept").permitAll()
  239. .antMatchers("/consoleByDept/qcCheckMRPageByDept").permitAll()
  240. .antMatchers("/print/export/qcCheckMRPageExportByDept").permitAll()
  241. .antMatchers("/consoleByDept/hmImproveMRPageByDept").permitAll()
  242. .antMatchers("/print/export/improveMRExportByDept").permitAll()
  243. .antMatchers("/consoleByDept/reHos31DaysPageByDept").permitAll()
  244. .antMatchers("/print/export/reHos31DaysPageExportByDept").permitAll()
  245. .antMatchers("/consoleByDept/unModifyMRSByDept").permitAll()
  246. .antMatchers("/print/export/unModifyMRSExportByDept").permitAll()
  247. .antMatchers("/consoleByDept/unModifyMRPageByDept").permitAll()
  248. .antMatchers("/print/export/unModifyMRPageExportByDept").permitAll()
  249. .antMatchers("/consoleByDept/medicalCheckFormKs").permitAll()
  250. .antMatchers("/print/export/medicalCheckExportByDept").permitAll()
  251. .antMatchers("/consoleByDept/medicalCheckTitleKs").permitAll()
  252. .antMatchers("/console/qualityControl").permitAll()
  253. .antMatchers("/console/export/qualityControlExport").permitAll()
  254. .antMatchers("/consoleByDept/qualityControlByDept").permitAll()
  255. .antMatchers("/print/export/qualityControlExportByDept").permitAll()
  256. .antMatchers("/qc/behospitalInfo/getMedQualityCoList").permitAll()
  257. .antMatchers("/console/saveMedicaIndicator").permitAll()
  258. .antMatchers("/qc/medCheckInfo/createMedBeHospitalInfoType").permitAll()
  259. .antMatchers("/qc/medCheckInfo/addMedCheckInfo").permitAll()
  260. .antMatchers("/qc/medCheckInfo/getDataEdit").permitAll()
  261. .antMatchers("/qc/medCheckInfo/saveDataEdit").permitAll()
  262. .antMatchers("/qc/analysis/addMedClickInfo").permitAll()
  263. .antMatchers("/qc/analysis/getQcClick").permitAll()
  264. .antMatchers("/qc/analysis/getQcClickByExport").permitAll()
  265. .antMatchers("/qc/analysis/getQcClickInnerPage").permitAll()
  266. .antMatchers("/qc/analysis/getQcClickInnerPageByExport").permitAll()
  267. .antMatchers("/qc/analysis/getEntryDefectImprove").permitAll()
  268. .antMatchers("/qc/analysis/getEntryDefectImproveByExport").permitAll()
  269. .antMatchers("/**").authenticated();
  270. // .antMatchers("/**").permitAll();
  271. }
  272. @Override
  273. public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
  274. log.info("Configuring ResourceServerSecurityConfigurer");
  275. resources.resourceId("user-service").tokenStore(new JwtTokenStore(jwtTokenEnhancerClient()));
  276. }
  277. @Autowired
  278. private CustomAccessTokenConverter customAccessTokenConverter;
  279. @Bean("jwtTokenEnhancerClient")
  280. protected JwtAccessTokenConverter jwtTokenEnhancerClient() {
  281. JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
  282. Resource resource = new ClassPathResource("public.cert");
  283. String publicKey;
  284. try {
  285. publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
  286. } catch (IOException e) {
  287. throw new RuntimeException(e);
  288. }
  289. converter.setVerifierKey(publicKey);
  290. //不设置这个会出现 Cannot convert access token to JSON
  291. converter.setVerifier(new RsaVerifier(publicKey));
  292. converter.setAccessTokenConverter(customAccessTokenConverter);
  293. log.info("Created jwtTokenEnhancerClient success");
  294. return converter;
  295. }
  296. }