diff --git a/pom.xml b/pom.xml
index 818fda0df12afd66869e6c440d905ddb4e592e5a..e5f4eb9ca0aece80a8a3fd1d50986a31b68cfe61 100644
--- a/pom.xml
+++ b/pom.xml
@@ -32,6 +32,12 @@
springfox-swagger-ui
2.9.2
+
+
+ io.swagger
+ swagger-models
+ 1.5.21
+
@@ -159,65 +165,65 @@
spring-boot-maven-plugin
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/java/com/stu/stusystem/config/MyShiroConfig.java b/src/main/java/com/stu/stusystem/config/MyShiroConfig.java
index 135431146362ad186dbcf2a3e2d16651569831ef..0cc5a919d86fe7b7a9615f03bf0b82f7bfb9bd5c 100644
--- a/src/main/java/com/stu/stusystem/config/MyShiroConfig.java
+++ b/src/main/java/com/stu/stusystem/config/MyShiroConfig.java
@@ -34,11 +34,11 @@ public class MyShiroConfig {
public ShiroFilterFactoryBean getShiroFilterFactoryBean(@Qualifier("defaultWebSecurity") DefaultWebSecurityManager defaultWebSecurityManager) {
ShiroFilterFactoryBean shiroFilterFactoryBean = new ShiroFilterFactoryBean();
- // 设置安全管理器
+ // Shiro的核心安全接口,这个属性是必须的
shiroFilterFactoryBean.setSecurityManager(defaultWebSecurityManager);
- // 未登录时候跳转链接
- // shiroFilterFactoryBean.setLoginUrl("/index");
+ // 未登录时候跳转链接,还可以通过类继承AuthenticationFilter方式配置
+ shiroFilterFactoryBean.setLoginUrl("/notLogin");
// 登录成功后要跳转的链接
// shiroFilterFactoryBean.setSuccessUrl("/index");
@@ -46,11 +46,6 @@ public class MyShiroConfig {
// 未授权界面
// shiroFilterFactoryBean.setUnauthorizedUrl("/403");
- // 设置shiro内置过滤器
- Map filters = new HashMap<>();
- ShiroAuthenticationFilter authenticationFilter = new ShiroAuthenticationFilter();
- filters.put("authc", authenticationFilter);
- shiroFilterFactoryBean.setFilters(filters);
// 拦截器
Map filterChainDefinitionMap = new LinkedHashMap();
filterChainDefinitionMap.put("/static/**", "anon");
diff --git a/src/main/java/com/stu/stusystem/config/MyShiroRealm.java b/src/main/java/com/stu/stusystem/config/MyShiroRealm.java
index 3706d5a29e38cd4fc97e2cdeca96b0faaf9fae5d..fe660a3dbd685c0c14287deb5c50a038daabfe59 100644
--- a/src/main/java/com/stu/stusystem/config/MyShiroRealm.java
+++ b/src/main/java/com/stu/stusystem/config/MyShiroRealm.java
@@ -1,6 +1,7 @@
package com.stu.stusystem.config;
import com.stu.stusystem.mapper.system.StuMapper;
+import com.stu.stusystem.model.em.Jurisdiction;
import com.stu.stusystem.model.system.StuUser;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.AuthenticationException;
@@ -13,12 +14,16 @@ import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
+import java.util.HashSet;
+import java.util.Set;
+
/**
* @author cxt
* @date 2020/9/10
*/
@Slf4j
public class MyShiroRealm extends AuthorizingRealm {
+
private StuMapper stuMapper;
/**
@@ -29,9 +34,22 @@ public class MyShiroRealm extends AuthorizingRealm {
SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
StuUser user = (StuUser) principals.getPrimaryPrincipal();
log.info("登陆授权,user={}", user);
-// Set roles = new HashSet<>();
-// roles.add(user.getPassword());
-// info.setRoles(roles);
+ // 角色列表
+ Set roles = new HashSet<>();
+ // 功能列表
+ Set menus = new HashSet<>();
+ if (user.getJurisdiction() == Jurisdiction.ADMIN) {
+ info.addRole("admin");
+ info.addStringPermission("*:*:*");
+ } else {
+// roles = roleService.selectRoleKeys(user.getUserId()); // 查询角色表
+// menus = menuService.selectPermsByUserId(user.getUserId()); // 查询数据库(角色表和菜单表),角色id对应菜单权限id
+
+ // 角色加入AuthorizationInfo认证对象
+ info.setRoles(roles);
+ // 权限加入AuthorizationInfo认证对象
+ info.setStringPermissions(menus);
+ }
return info;
}
diff --git a/src/main/java/com/stu/stusystem/config/ShiroAuthenticationFilter.java b/src/main/java/com/stu/stusystem/config/ShiroAuthenticationFilter.java
deleted file mode 100644
index 0f7849420db62f1828434fe306cc2bf98d78b9cf..0000000000000000000000000000000000000000
--- a/src/main/java/com/stu/stusystem/config/ShiroAuthenticationFilter.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package com.stu.stusystem.config;
-
-import com.alibaba.fastjson.JSONObject;
-import com.stu.stusystem.common.ApiResult;
-import org.apache.shiro.web.filter.authc.AuthenticationFilter;
-
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-
-/**
- * @author: cxt
- * @time: 2021/3/11
- */
-public class ShiroAuthenticationFilter extends AuthenticationFilter {
- @Override
- protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws IOException {
- HttpServletResponse httpServletResponse = (HttpServletResponse) response;
- httpServletResponse.setCharacterEncoding("UTF-8");
- httpServletResponse.setContentType("application/json");
- // 在用户未登录时候请求地址,返回json数据
- ApiResult