ResourceServerConfigurer.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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/refreshJwt").permitAll()
  38. .antMatchers("/sys/user/checkToken").permitAll()
  39. //.antMatchers("/sys/user/getUserOrgMenu").permitAll()
  40. .antMatchers("/oauth/token").permitAll()
  41. .antMatchers("/oauth/check_token").permitAll()
  42. //.antMatchers("/tran/lisConfig/isExistRecord").permitAll()
  43. //.antMatchers("/tran/lisConfig/saveOrUpdateRecord").permitAll()
  44. //.antMatchers("/tran/lisConfig/saveOrUpdateRecords").permitAll()
  45. //.antMatchers("/tran/lisConfig/deleteRecord").permitAll()
  46. //.antMatchers("/tran/lisConfig/deleteRecords").permitAll()
  47. .antMatchers("/tran/lisConfig/getPage").permitAll()
  48. //.antMatchers("/tran/lisConfig/importExcel").permitAll()
  49. //.antMatchers("/tran/lisConfig/exportExcel").permitAll()
  50. .antMatchers("/tran/lisConfig/exportExcelModule").permitAll()
  51. //.antMatchers("/tran/pacsConfig/isExistRecord").permitAll()
  52. //.antMatchers("/tran/pacsConfig/saveOrUpdateRecord").permitAll()
  53. //.antMatchers("/tran/pacsConfig/saveOrUpdateRecords").permitAll()
  54. //.antMatchers("/tran/pacsConfig/deleteRecord").permitAll()
  55. //.antMatchers("/tran/pacsConfig/deleteRecords").permitAll()
  56. .antMatchers("/tran/pacsConfig/getPage").permitAll()
  57. //.antMatchers("/tran/pacsConfig/importExcel").permitAll()
  58. //.antMatchers("/tran/pacsConfig/exportExcel").permitAll()
  59. .antMatchers("/tran/pacsConfig/exportExcelModule").permitAll()
  60. //.antMatchers("/tran/diseaseConfig/isExistRecord").permitAll()
  61. //.antMatchers("/tran/diseaseConfig/saveOrUpdateRecord").permitAll()
  62. //.antMatchers("/tran/diseaseConfig/saveOrUpdateRecords").permitAll()
  63. //.antMatchers("/tran/diseaseConfig/deleteRecord").permitAll()
  64. //.antMatchers("/tran/diseaseConfig/deleteRecords").permitAll()
  65. .antMatchers("/tran/diseaseConfig/getPage").permitAll()
  66. //.antMatchers("/tran/diseaseConfig/importExcel").permitAll()
  67. //.antMatchers("/tran/diseaseConfig/exportExcel").permitAll()
  68. .antMatchers("/tran/diseaseConfig/exportExcelModule").permitAll()
  69. //.antMatchers("/tran/drugConfig/isExistRecord").permitAll()
  70. //.antMatchers("/tran/drugConfig/saveOrUpdateRecord").permitAll()
  71. //.antMatchers("/tran/drugConfig/saveOrUpdateRecords").permitAll()
  72. //.antMatchers("/tran/drugConfig/deleteRecord").permitAll()
  73. // .antMatchers("/tran/drugConfig/deleteRecords").permitAll()
  74. .antMatchers("/tran/drugConfig/getPage").permitAll()
  75. //.antMatchers("/tran/drugConfig/importExcel").permitAll()
  76. // .antMatchers("/tran/drugConfig/exportExcel").permitAll()
  77. .antMatchers("/tran/drugConfig/exportExcelModule").permitAll()
  78. //.antMatchers("/tran/operationConfig/isExistRecord").permitAll()
  79. //.antMatchers("/tran/operationConfig/saveOrUpdateRecord").permitAll()
  80. //.antMatchers("/tran/operationConfig/saveOrUpdateRecords").permitAll()
  81. //.antMatchers("/tran/operationConfig/deleteRecord").permitAll()
  82. //.antMatchers("/tran/operationConfig/deleteRecords").permitAll()
  83. .antMatchers("/tran/operationConfig/getPage").permitAll()
  84. //.antMatchers("/tran/operationConfig/importExcel").permitAll()
  85. //.antMatchers("/tran/operationConfig/exportExcel").permitAll()
  86. .antMatchers("/tran/operationConfig/exportExcelModule").permitAll()
  87. //.antMatchers("/tran/deptConfig/isExistRecord").permitAll()
  88. //.antMatchers("/tran/deptConfig/saveOrUpdateRecord").permitAll()
  89. //.antMatchers("/tran/deptConfig/saveOrUpdateRecords").permitAll()
  90. //.antMatchers("/tran/deptConfig/deleteRecord").permitAll()
  91. //.antMatchers("/tran/deptConfig/deleteRecords").permitAll()
  92. .antMatchers("/tran/deptConfig/getPage").permitAll()
  93. //.antMatchers("/tran/deptConfig/importExcel").permitAll()
  94. //.antMatchers("/tran/deptConfig/exportExcel").permitAll()
  95. .antMatchers("/tran/deptConfig/exportExcelModule").permitAll()
  96. //.antMatchers("/tran/transfusionConfig/isExistRecord").permitAll()
  97. //.antMatchers("/tran/transfusionConfig/saveOrUpdateRecord").permitAll()
  98. //.antMatchers("/tran/transfusionConfig/saveOrUpdateRecords").permitAll()
  99. //.antMatchers("/tran/transfusionConfig/deleteRecord").permitAll()
  100. //.antMatchers("/tran/transfusionConfig/deleteRecords").permitAll()
  101. .antMatchers("/tran/transfusionConfig/getPage").permitAll()
  102. //.antMatchers("/tran/transfusionConfig/importExcel").permitAll()
  103. //.antMatchers("/tran/transfusionConfig/exportExcel").permitAll()
  104. .antMatchers("/tran/transfusionConfig/exportExcelModule").permitAll()
  105. //.antMatchers("/tran/hospitalInfo/saveRecord").permitAll()
  106. .antMatchers("/tran/hospitalInfo/getHospitalInfo").permitAll()
  107. .antMatchers("/tran/hospitalInfo/getHospitalInfoById").permitAll()
  108. .antMatchers("/sys/versionInfo/getVersionInfoAlls").permitAll()
  109. .antMatchers("/sys/disclaimerInfo/getDisclaimerInfo").permitAll()
  110. .antMatchers("/sys/mr/createMr").permitAll()
  111. .antMatchers("/sys/mr/getMr").permitAll()
  112. .antMatchers("/sys/plan/getSysPlanInfoDatas").permitAll()
  113. .antMatchers("/sys/mrqc/analyze_run").permitAll()
  114. .antMatchers("/sys/tokenPermission/delPermission").permitAll()
  115. .antMatchers("/sys/tokenPermission/getPermission").permitAll()
  116. .antMatchers("/sys/push/push").permitAll()
  117. .antMatchers("/sys/push/pushApi").permitAll()
  118. .antMatchers("/sys/push/indicationPush").permitAll()
  119. .antMatchers("/sys/push/pushPlan").permitAll()
  120. .antMatchers("/demo/templateInfo/updateByIdUsNames").permitAll()
  121. .antMatchers("/demo/templateInfo/saveTemplateInfo").permitAll()
  122. .antMatchers("/demo/templateInfo/cancelTemplateInfos").permitAll()
  123. .antMatchers("/demo/templateInfo/getTemplatePageAlls").permitAll()
  124. .antMatchers("/demo/templateInfo/getTemplatebyId").permitAll()
  125. .antMatchers("/sys/tokenPermission/getPermission").permitAll()
  126. //.antMatchers("/sys/plan/getPlanInfoPages").permitAll()
  127. //.antMatchers("/sys/plan/savePlanInfoDatas").permitAll()
  128. //.antMatchers("/sys/plan/getSysPlanInfoDatas").permitAll()
  129. //.antMatchers("/sys/plan/cancelPlanDatas").permitAll()
  130. //.antMatchers("/sys/plan/revStopPlans").permitAll()
  131. .antMatchers("/sys/tokenHospital/getTokenHospital").permitAll()
  132. .antMatchers("/demo/retrieval/index").permitAll()
  133. .antMatchers("/graph/conceptInfo/staticKnowledgeIndex").permitAll()
  134. .antMatchers("/graph/conceptInfo/staticKnowledgeIndexWithoutInfo").permitAll()
  135. .antMatchers("/graph/conceptInfo/getStaticKnowledge").permitAll()
  136. .antMatchers("/graph/conceptInfo/getStaticKnowledgeForHIS").permitAll()
  137. .antMatchers("/graph/conceptInfo/getPage").permitAll()
  138. //.antMatchers("/graph/conceptInfo/saveOrUpdateRecord").permitAll()
  139. //.antMatchers("/graph/conceptInfo/changeStatus").permitAll()
  140. .antMatchers("/graph/conceptInfo/isExist").permitAll()
  141. .antMatchers("/graph/conceptInfo/getRecordById").permitAll()
  142. .antMatchers("/sys/planDetail/getPlanDetailDatas").permitAll()
  143. //.antMatchers("/sys/planDetail/savePlanDetails").permitAll()
  144. //.antMatchers("/sys/planDetail/cancelPlanDetails").permitAll()
  145. //.antMatchers("/sys/planDetail/revStopPlanDetails").permitAll()
  146. //.antMatchers("/sys/plan/getDefaultPlans").permitAll()
  147. .antMatchers("/sys/dictionaryInfo/getList").permitAll()
  148. .antMatchers("/sys/dictionaryInfo/getListBack").permitAll()
  149. .antMatchers("/sys/plan/getPlanInfoIds").permitAll()
  150. .antMatchers("/sys/file/uploadImage").permitAll()
  151. .antMatchers("/sys/file/deleteRemoteFile").permitAll()
  152. .antMatchers("/sys/mrqc/caseWritingPrompt").permitAll()
  153. .antMatchers("/**").authenticated();
  154. // .antMatchers("/**").permitAll();
  155. }
  156. @Override
  157. public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
  158. log.info("Configuring ResourceServerSecurityConfigurer");
  159. resources.resourceId("user-service").tokenStore(new JwtTokenStore(jwtTokenEnhancerClient()));
  160. }
  161. @Autowired
  162. private CustomAccessTokenConverter customAccessTokenConverter;
  163. @Bean("jwtTokenEnhancerClient")
  164. protected JwtAccessTokenConverter jwtTokenEnhancerClient() {
  165. JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
  166. Resource resource = new ClassPathResource("public.cert");
  167. String publicKey;
  168. try {
  169. publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
  170. } catch (IOException e) {
  171. throw new RuntimeException(e);
  172. }
  173. converter.setVerifierKey(publicKey);
  174. //不设置这个会出现 Cannot convert access token to JSON
  175. converter.setVerifier(new RsaVerifier(publicKey));
  176. converter.setAccessTokenConverter(customAccessTokenConverter);
  177. log.info("Created jwtTokenEnhancerClient success");
  178. return converter;
  179. }
  180. }