123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- package com.diagbot.config;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.ComponentScan;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.core.io.ClassPathResource;
- import org.springframework.core.io.Resource;
- import org.springframework.security.config.annotation.web.builders.HttpSecurity;
- import org.springframework.security.jwt.crypto.sign.RsaVerifier;
- import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
- import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
- import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
- import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
- import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;
- import org.springframework.util.FileCopyUtils;
- import java.io.IOException;
- /**
- * @Description: 权限资源配置类
- * @author: gaodm
- * @time: 2018/8/2 14:21
- */
- @Configuration
- @EnableResourceServer
- @ComponentScan({ "com.diagbot.config" })
- public class ResourceServerConfigurer extends ResourceServerConfigurerAdapter {
- Logger log = LoggerFactory.getLogger(ResourceServerConfigurer.class);
- @Override
- public void configure(HttpSecurity http) throws Exception {
- http.cors()
- .and()
- .csrf().disable()
- .authorizeRequests()
- .regexMatchers(".*swagger.*", ".*v2.*", ".*webjars.*", "/druid.*", "/actuator.*", "/hystrix.*").permitAll()
- .antMatchers("/sys/user/getJwt").permitAll()
- .antMatchers("/sys/user/refreshJwt").permitAll()
- .antMatchers("/sys/user/checkToken").permitAll()
- //.antMatchers("/sys/user/getUserOrgMenu").permitAll()
- .antMatchers("/oauth/token").permitAll()
- .antMatchers("/oauth/check_token").permitAll()
- //.antMatchers("/tran/lisConfig/isExistRecord").permitAll()
- //.antMatchers("/tran/lisConfig/saveOrUpdateRecord").permitAll()
- //.antMatchers("/tran/lisConfig/saveOrUpdateRecords").permitAll()
- //.antMatchers("/tran/lisConfig/deleteRecord").permitAll()
- //.antMatchers("/tran/lisConfig/deleteRecords").permitAll()
- .antMatchers("/tran/lisConfig/getPage").permitAll()
- //.antMatchers("/tran/lisConfig/importExcel").permitAll()
- //.antMatchers("/tran/lisConfig/exportExcel").permitAll()
- .antMatchers("/tran/lisConfig/exportExcelModule").permitAll()
- //.antMatchers("/tran/pacsConfig/isExistRecord").permitAll()
- //.antMatchers("/tran/pacsConfig/saveOrUpdateRecord").permitAll()
- //.antMatchers("/tran/pacsConfig/saveOrUpdateRecords").permitAll()
- //.antMatchers("/tran/pacsConfig/deleteRecord").permitAll()
- //.antMatchers("/tran/pacsConfig/deleteRecords").permitAll()
- .antMatchers("/tran/pacsConfig/getPage").permitAll()
- //.antMatchers("/tran/pacsConfig/importExcel").permitAll()
- //.antMatchers("/tran/pacsConfig/exportExcel").permitAll()
- .antMatchers("/tran/pacsConfig/exportExcelModule").permitAll()
- //.antMatchers("/tran/diseaseConfig/isExistRecord").permitAll()
- //.antMatchers("/tran/diseaseConfig/saveOrUpdateRecord").permitAll()
- //.antMatchers("/tran/diseaseConfig/saveOrUpdateRecords").permitAll()
- //.antMatchers("/tran/diseaseConfig/deleteRecord").permitAll()
- //.antMatchers("/tran/diseaseConfig/deleteRecords").permitAll()
- .antMatchers("/tran/diseaseConfig/getPage").permitAll()
- //.antMatchers("/tran/diseaseConfig/importExcel").permitAll()
- //.antMatchers("/tran/diseaseConfig/exportExcel").permitAll()
- .antMatchers("/tran/diseaseConfig/exportExcelModule").permitAll()
- //.antMatchers("/tran/drugConfig/isExistRecord").permitAll()
- //.antMatchers("/tran/drugConfig/saveOrUpdateRecord").permitAll()
- //.antMatchers("/tran/drugConfig/saveOrUpdateRecords").permitAll()
- //.antMatchers("/tran/drugConfig/deleteRecord").permitAll()
- // .antMatchers("/tran/drugConfig/deleteRecords").permitAll()
- .antMatchers("/tran/drugConfig/getPage").permitAll()
- //.antMatchers("/tran/drugConfig/importExcel").permitAll()
- // .antMatchers("/tran/drugConfig/exportExcel").permitAll()
- .antMatchers("/tran/drugConfig/exportExcelModule").permitAll()
- //.antMatchers("/tran/operationConfig/isExistRecord").permitAll()
- //.antMatchers("/tran/operationConfig/saveOrUpdateRecord").permitAll()
- //.antMatchers("/tran/operationConfig/saveOrUpdateRecords").permitAll()
- //.antMatchers("/tran/operationConfig/deleteRecord").permitAll()
- //.antMatchers("/tran/operationConfig/deleteRecords").permitAll()
- .antMatchers("/tran/operationConfig/getPage").permitAll()
- //.antMatchers("/tran/operationConfig/importExcel").permitAll()
- //.antMatchers("/tran/operationConfig/exportExcel").permitAll()
- .antMatchers("/tran/operationConfig/exportExcelModule").permitAll()
- //.antMatchers("/tran/deptConfig/isExistRecord").permitAll()
- //.antMatchers("/tran/deptConfig/saveOrUpdateRecord").permitAll()
- //.antMatchers("/tran/deptConfig/saveOrUpdateRecords").permitAll()
- //.antMatchers("/tran/deptConfig/deleteRecord").permitAll()
- //.antMatchers("/tran/deptConfig/deleteRecords").permitAll()
- .antMatchers("/tran/deptConfig/getPage").permitAll()
- //.antMatchers("/tran/deptConfig/importExcel").permitAll()
- //.antMatchers("/tran/deptConfig/exportExcel").permitAll()
- .antMatchers("/tran/deptConfig/exportExcelModule").permitAll()
- //.antMatchers("/tran/transfusionConfig/isExistRecord").permitAll()
- //.antMatchers("/tran/transfusionConfig/saveOrUpdateRecord").permitAll()
- //.antMatchers("/tran/transfusionConfig/saveOrUpdateRecords").permitAll()
- //.antMatchers("/tran/transfusionConfig/deleteRecord").permitAll()
- //.antMatchers("/tran/transfusionConfig/deleteRecords").permitAll()
- .antMatchers("/tran/transfusionConfig/getPage").permitAll()
- //.antMatchers("/tran/transfusionConfig/importExcel").permitAll()
- //.antMatchers("/tran/transfusionConfig/exportExcel").permitAll()
- .antMatchers("/tran/transfusionConfig/exportExcelModule").permitAll()
- //.antMatchers("/tran/hospitalInfo/saveRecord").permitAll()
- .antMatchers("/tran/hospitalInfo/getHospitalInfo").permitAll()
- .antMatchers("/tran/hospitalInfo/getHospitalInfoById").permitAll()
- .antMatchers("/sys/versionInfo/getVersionInfoAlls").permitAll()
- .antMatchers("/sys/disclaimerInfo/getDisclaimerInfo").permitAll()
- .antMatchers("/sys/mr/createMr").permitAll()
- .antMatchers("/sys/mr/getMr").permitAll()
- .antMatchers("/sys/plan/getSysPlanInfoDatas").permitAll()
- .antMatchers("/sys/mrqc/analyze_run").permitAll()
- .antMatchers("/sys/tokenPermission/delPermission").permitAll()
- .antMatchers("/sys/tokenPermission/getPermission").permitAll()
- .antMatchers("/sys/push/push").permitAll()
- .antMatchers("/sys/push/pushApi").permitAll()
- .antMatchers("/sys/push/indicationPush").permitAll()
- .antMatchers("/sys/push/pushPlan").permitAll()
- .antMatchers("/demo/templateInfo/updateByIdUsNames").permitAll()
- .antMatchers("/demo/templateInfo/saveTemplateInfo").permitAll()
- .antMatchers("/demo/templateInfo/cancelTemplateInfos").permitAll()
- .antMatchers("/demo/templateInfo/getTemplatePageAlls").permitAll()
- .antMatchers("/demo/templateInfo/getTemplatebyId").permitAll()
- .antMatchers("/sys/tokenPermission/getPermission").permitAll()
- //.antMatchers("/sys/plan/getPlanInfoPages").permitAll()
- //.antMatchers("/sys/plan/savePlanInfoDatas").permitAll()
- //.antMatchers("/sys/plan/getSysPlanInfoDatas").permitAll()
- //.antMatchers("/sys/plan/cancelPlanDatas").permitAll()
- //.antMatchers("/sys/plan/revStopPlans").permitAll()
- .antMatchers("/sys/tokenHospital/getTokenHospital").permitAll()
- .antMatchers("/demo/retrieval/index").permitAll()
- .antMatchers("/graph/conceptInfo/staticKnowledgeIndex").permitAll()
- .antMatchers("/graph/conceptInfo/staticKnowledgeIndexWithoutInfo").permitAll()
- .antMatchers("/graph/conceptInfo/getStaticKnowledge").permitAll()
- .antMatchers("/graph/conceptInfo/getStaticKnowledgeForHIS").permitAll()
- .antMatchers("/graph/conceptInfo/getPage").permitAll()
- //.antMatchers("/graph/conceptInfo/saveOrUpdateRecord").permitAll()
- //.antMatchers("/graph/conceptInfo/changeStatus").permitAll()
- .antMatchers("/graph/conceptInfo/isExist").permitAll()
- .antMatchers("/graph/conceptInfo/getRecordById").permitAll()
- .antMatchers("/sys/planDetail/getPlanDetailDatas").permitAll()
- //.antMatchers("/sys/planDetail/savePlanDetails").permitAll()
- //.antMatchers("/sys/planDetail/cancelPlanDetails").permitAll()
- //.antMatchers("/sys/planDetail/revStopPlanDetails").permitAll()
- //.antMatchers("/sys/plan/getDefaultPlans").permitAll()
- .antMatchers("/sys/dictionaryInfo/getList").permitAll()
- .antMatchers("/sys/dictionaryInfo/getListBack").permitAll()
- .antMatchers("/sys/plan/getPlanInfoIds").permitAll()
- .antMatchers("/sys/file/uploadImage").permitAll()
- .antMatchers("/sys/file/deleteRemoteFile").permitAll()
- .antMatchers("/sys/mrqc/caseWritingPrompt").permitAll()
- .antMatchers("/**").authenticated();
- // .antMatchers("/**").permitAll();
- }
- @Override
- public void configure(ResourceServerSecurityConfigurer resources) throws Exception {
- log.info("Configuring ResourceServerSecurityConfigurer");
- resources.resourceId("user-service").tokenStore(new JwtTokenStore(jwtTokenEnhancerClient()));
- }
- @Autowired
- private CustomAccessTokenConverter customAccessTokenConverter;
- @Bean("jwtTokenEnhancerClient")
- protected JwtAccessTokenConverter jwtTokenEnhancerClient() {
- JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
- Resource resource = new ClassPathResource("public.cert");
- String publicKey;
- try {
- publicKey = new String(FileCopyUtils.copyToByteArray(resource.getInputStream()));
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- converter.setVerifierKey(publicKey);
- //不设置这个会出现 Cannot convert access token to JSON
- converter.setVerifier(new RsaVerifier(publicKey));
- converter.setAccessTokenConverter(customAccessTokenConverter);
- log.info("Created jwtTokenEnhancerClient success");
- return converter;
- }
- }
|