瀏覽代碼

Merge branch 'master' of http://git.qmth.com.cn/ExamCloud-2/examcloud-core-examwork.git

wangwei 7 年之前
父節點
當前提交
e521e4fd3a

+ 22 - 1
examcloud-core-examwork-starter/src/main/java/cn/com/qmth/examcloud/core/examwork/starter/config/DefaultWebMvcConfigurerAdapter.java

@@ -1,6 +1,9 @@
 package cn.com.qmth.examcloud.core.examwork.starter.config;
 
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Bean;
@@ -26,6 +29,8 @@ public class DefaultWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
 	@Autowired
 	RedisClient redisClient;
 
+	private static Map<String, String[]> rolePathMap = new HashMap<String, String[]>();
+
 	@Override
 	public void addInterceptors(InterceptorRegistry registry) {
 		registry.addInterceptor(new FirstInterceptor()).addPathPatterns("/**");
@@ -40,7 +45,23 @@ public class DefaultWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
 
 			@Override
 			public boolean hasPermission(String mappingPath, List<Role> roleList) {
-				return true;
+				String[] roles = rolePathMap.get(mappingPath);
+				if (roles == null) {
+					return true;
+				}
+				if (roleList == null) {
+					return false;
+				}
+				List<String> roleCodes = new ArrayList<String>();
+				for (Role role : roleList) {
+					roleCodes.add(role.getRoleCode());
+				}
+				for (String role : roles) {
+					if (roleCodes.contains(role)) {
+						return true;
+					}
+				}
+				return false;
 			}
 
 		};