|
@@ -1,81 +0,0 @@
|
|
-/*
|
|
|
|
- * *************************************************
|
|
|
|
- * Copyright (c) 2018 QMTH. All Rights Reserved.
|
|
|
|
- * Created by Deason on 2018-10-17 16:34:17.
|
|
|
|
- * *************************************************
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
-package cn.com.qmth.examcloud.core.print.config;
|
|
|
|
-
|
|
|
|
-import cn.com.qmth.examcloud.api.commons.security.bean.Role;
|
|
|
|
-import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
|
-import cn.com.qmth.examcloud.commons.util.PathUtil;
|
|
|
|
-import cn.com.qmth.examcloud.commons.util.PropertiesUtil;
|
|
|
|
-import cn.com.qmth.examcloud.web.interceptor.FirstInterceptor;
|
|
|
|
-import cn.com.qmth.examcloud.web.redis.RedisClient;
|
|
|
|
-import cn.com.qmth.examcloud.web.security.RequestPermissionInterceptor;
|
|
|
|
-import cn.com.qmth.examcloud.web.security.SpringCloudInterceptor;
|
|
|
|
-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 java.util.List;
|
|
|
|
-
|
|
|
|
-/**
|
|
|
|
- * @author: fengdesheng
|
|
|
|
- * @since: 2018/10/17
|
|
|
|
- */
|
|
|
|
-@Configuration
|
|
|
|
-public class InterceptorConfig extends WebMvcConfigurerAdapter {
|
|
|
|
- @Autowired
|
|
|
|
- private RedisClient redisClient;
|
|
|
|
-
|
|
|
|
- static {
|
|
|
|
- PropertiesUtil.configure(PathUtil.getResoucePath("security-mapping.properties"));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public void addInterceptors(InterceptorRegistry registry) {
|
|
|
|
- registry.addInterceptor(new FirstInterceptor()).addPathPatterns("/**");
|
|
|
|
- SpringCloudInterceptor springCloudInterceptor = new SpringCloudInterceptor();
|
|
|
|
- registry.addInterceptor(springCloudInterceptor).addPathPatterns("/**");
|
|
|
|
- //springCloudInterceptor.setRedisClient(redisClient);todo
|
|
|
|
-
|
|
|
|
- RequestPermissionInterceptor requestPermissionInterceptor = getRequestPermissionInterceptor();
|
|
|
|
- requestPermissionInterceptor.configure("security-exclusions.conf");
|
|
|
|
- registry.addInterceptor(requestPermissionInterceptor).addPathPatterns("/**");
|
|
|
|
- super.addInterceptors(registry);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Bean
|
|
|
|
- public RequestPermissionInterceptor getRequestPermissionInterceptor() {
|
|
|
|
- return new RequestPermissionInterceptor(redisClient) {
|
|
|
|
- @Override
|
|
|
|
- public boolean hasPermission(String mappingPath, User user) {
|
|
|
|
- List<Role> roleList = user.getRoleList();
|
|
|
|
- if (CollectionUtils.isEmpty(roleList)) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- String roles = PropertiesUtil.getString(mappingPath);
|
|
|
|
- if (StringUtils.isBlank(roles)) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- roles = "," + roles + ",";
|
|
|
|
-
|
|
|
|
- for (Role role : roleList) {
|
|
|
|
- if (roles.contains("," + role.getRoleCode() + ",")) {
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-}
|
|
|