|
@@ -1,6 +1,9 @@
|
|
|
package cn.com.qmth.examcloud.core.basic.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("/**");
|
|
@@ -35,12 +40,28 @@ public class DefaultWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
|
|
|
|
|
|
@Bean
|
|
|
public RequestPermissionInterceptor getRequestPermissionInterceptor() {
|
|
|
- String[] exclusions = new String[]{".*"};
|
|
|
+ String[] exclusions = new String[]{};
|
|
|
return new RequestPermissionInterceptor(redisClient, exclusions) {
|
|
|
|
|
|
@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;
|
|
|
}
|
|
|
|
|
|
};
|