浏览代码

配置权限修改

weiwenhai 7 年之前
父节点
当前提交
33e3e55bcf

+ 1 - 1
examcloud-core-questions-service/src/main/java/cn/com/qmth/examcloud/core/questions/service/ImportPaperService.java

@@ -346,7 +346,7 @@ public class ImportPaperService {
             }else{
             	String errorMsg = pText.length()>10?pText.substring(0, 10):pText;
             	if(pText.startsWith(ImportPaperMsg.left_bracket)){
-            		throw new PaperException(errorMsg + ",标签格式不正确!正确标签格式:[套题]、[套题数]、[小题分数]、[答案]、[难度]、[一级属性]、[二级属性]、[公开度]、[小题型]");
+            		throw new PaperException(errorMsg + ",标签格式不正确!正确标签格式:[套题]、[套题数]、[小题分数]、[答案]、[难度]、[一级属性]、[二级属性]、[公开度]、[小题型]");
             	}
                 throw new PaperException(importPaperCheck.getQuesName()+":“"+ errorMsg +"”"+ImportPaperMsg.errMsg_12);
             }

+ 1 - 0
examcloud-core-questions-starter/pom.xml

@@ -43,6 +43,7 @@
 					<excludes>
 						<exclude>*.properties</exclude>
 						<exclude>*.xml </exclude>
+						<exclude>*.conf </exclude>
 					</excludes>
 				</configuration>
 			</plugin>

+ 27 - 122
examcloud-core-questions-starter/src/main/java/cn/com/qmth/examcloud/core/questions/starter/config/DefaultWebMvcConfigurerAdapter.java

@@ -1,20 +1,22 @@
 package cn.com.qmth.examcloud.core.questions.starter.config;
 
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
 import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
 
+import cn.com.qmth.examcloud.commons.base.util.PathUtil;
+import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
 import cn.com.qmth.examcloud.commons.web.interceptor.FirstInterceptor;
 import cn.com.qmth.examcloud.commons.web.redis.RedisClient;
 import cn.com.qmth.examcloud.commons.web.security.RequestPermissionInterceptor;
 import cn.com.qmth.examcloud.commons.web.security.bean.Role;
+import cn.com.qmth.examcloud.commons.web.security.bean.User;
 
 /**
  * 默认WebMvcConfigurer
@@ -28,144 +30,47 @@ public class DefaultWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
 
 	@Autowired
 	RedisClient redisClient;
-	
-	private static final Map<String,String[]> rolePathMap = new HashMap<String, String[]>();
-	
-	static{
-		rolePathMap.put("[api/exam_audit]:[]:[POST]", new String[]{"OE_ADMIN,LC_USER"});
-		//cn.com.qmth.examcloud.service.core.api.CourseController
-		rolePathMap.put("[${api_cqb}/]:[/course/{curPage}/{pageSize}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/course]:[PUT]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/course]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/course/{coruse_id}]:[DELETE]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/course]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/course/{courseNo}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/course/allCourses]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		
-		//cn.com.qmth.examcloud.service.core.api.GenPaperController
-		rolePathMap.put("[${api_cqb}/]:[/genPaper/simple]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/genPaper/normal]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/genPaper/blue]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		
-		//cn.com.qmth.examcloud.service.core.api.GenPaperController.ImportPaperController
-		rolePathMap.put("[${api_cqb}/]:[/importPaper]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/importPaper/saveBlankPaper/{courseNo}/{courseName}/{paperName}]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/clonePaper/{paperId}/{paperName}/{courseNo}]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		
-		//cn.com.qmth.examcloud.service.core.api.PaperController
-		rolePathMap.put("[${api_cqb}/]:[/paper/{paperId}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper]:[PUT]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/importPaper/{curPage}/{pageSize}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/importPaperNotSuccess/{curPage}/{pageSize}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/getImportPaper]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/getGenPaper]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/genPaper/{curPage}/{pageSize}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/genPaper/{ids}/{curPage}/{pageSize}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/{paperIds}]:[DELETE]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/pass]:[PUT]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/pass]:[PUT]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/noPass]:[PUT]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/list/{examId}/{courseCode}/{groupCode}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/join/{examId}/{courseCode}/{groupCode}/{paperId}]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/release/{examId}/{courseCode}/{groupCode}/{paperId}]:[DELETE]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/groupCode/{examId}/{courseCode}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/groupCode/{examId}/{courseCode}/{groupCode}]:[DELETE]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/deleteQuestion/{questionId}]:[DELETE]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/addQuestion/{paperId}/{paperDetailId}]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/{paperId}/reduplicate-questions]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/listNames/{questionId}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/listQuestion/{paperId}/{curPage}/{pageSize}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paper/selectQuestions/{paperId}/{paperDetailId}]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/importPaper/{ids}/{curPage}/{pageSize}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/importPaper/course]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/useBasePaper/{paperIds}]:[PUT]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/uploadRadio/{paperId}]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		
-		//cn.com.qmth.examcloud.service.core.api.PaperDetailController
-		rolePathMap.put("[${api_cqb}/]:[/paperDetail/units/{detail_id}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paperDetail/{detail_id}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/updatePaperDetail/{paperId}]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paperDetail]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paperDetail/{detailId}]:[DELETE]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paperDetail/paper/{paperId}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		
-		//cn.com.qmth.examcloud.service.core.api.PaperDetailUnitController
-		rolePathMap.put("[${api_cqb}/]:[/paperDetailUnit/question/{unit_id}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paperDetailUnit/{unit_id}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paperDetailUnit]:[PUT]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paperDetailUnit]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paperDetailUnit/{unitId}]:[DELETE]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		
-		//cn.com.qmth.examcloud.service.core.api.PaperStructController
-		rolePathMap.put("[${api_cqb}/]:[/paperStruct/{curPage}/{pageSize}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paperStruct]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paperStruct/{id}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paperStruct]:[PUT]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paperStruct]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paperStruct/{ids}]:[DELETE]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/paperStruct/quesNames]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		
-		//cn.com.qmth.examcloud.service.core.api.QuesController
-		rolePathMap.put("[${api_cqb}/]:[/question/{id}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/question/{curPage}/{pageSize}]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/question]:[PUT]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/question]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/question/{id}]:[DELETE]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/question/{id}/{number}]:[PUT]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/question/count]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		
-		//cn.com.qmth.examcloud.service.core.api.SettingController
-		rolePathMap.put("[${api_cqb}/]:[/setting]:[GET]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/setting]:[PUT]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/setting]:[POST]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
-		rolePathMap.put("[${api_cqb}/]:[/setting/{id}]:[DELETE]", new String[]{"QUESTION_ADMIN","SUPER_ADMIN"});
+
+	static {
+		PropertiesUtil.configureAndWatch(PathUtil.getResoucePath("security-mapping.properties"));
 	}
 
 	@Override
 	public void addInterceptors(InterceptorRegistry registry) {
 		registry.addInterceptor(new FirstInterceptor()).addPathPatterns("/**");
-		registry.addInterceptor(getRequestPermissionInterceptor()).addPathPatterns("/**");
+		RequestPermissionInterceptor requestPermissionInterceptor = getRequestPermissionInterceptor();
+		requestPermissionInterceptor.configureAndWatch("security-exclusions.conf");
+		registry.addInterceptor(requestPermissionInterceptor).addPathPatterns("/**");
 		super.addInterceptors(registry);
 	}
 
 	@Bean
 	public RequestPermissionInterceptor getRequestPermissionInterceptor() {
-		
-		String[] exclusions = new String[]{
-				".*/export/.*",
-				".*/exportSingleExamPaperInfo/.*",
-				".*/exportBatchExamPaperInfo/.*",
-//				".*/importPaper/.*",
-//				"^.*/import.*$",/extractQues/
-				".*/ecs_ques/extract/.*",
-				".*/extractQues/.*",
-				".*/ecs_ques/checkObjective/.*",
-//				".*/ecs_ques/uploadRadio/.*",
-				"pdf","ecs_ques/paper",
-				".*/batch_export/.*"
-		};
-		return new RequestPermissionInterceptor(redisClient, exclusions) {
+		return new RequestPermissionInterceptor(redisClient) {
 
 			@Override
-			public boolean hasPermission(String mappingPath, List<Role> roleList) {
-				String[] roles = rolePathMap.get(mappingPath);
-				if(roles == null){
-					return true;
-				}
-				if(roleList==null){
+			public boolean hasPermission(String mappingPath, User user) {
+				List<Role> roleList = user.getRoleList();
+				if (CollectionUtils.isEmpty(roleList)) {
 					return false;
 				}
-				List<String> roleCodes = new ArrayList<String>();
-				for(Role role:roleList){
-					roleCodes.add(role.getRoleCode());
+
+				String roles = PropertiesUtil.getString(mappingPath);
+				if (StringUtils.isBlank(roles)) {
+					return true;
 				}
-				for(String role:roles){
-					if(roleCodes.contains(role)){
+
+				roles = "," + roles + ",";
+
+				for (Role role : roleList) {
+					if (roles.contains("," + role.getRoleCode() + ",")) {
 						return true;
 					}
 				}
+
 				return false;
 			}
+
 		};
 	}
-}
+}