首页>代码>ssm开发生产管理ERP系统>/src/main/java/com/megagao/production/ssm/controller/AuthorityJudgeController.java
package com.megagao.production.ssm.controller; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import com.megagao.production.ssm.domain.customize.ActiveUser; import com.megagao.production.ssm.util.CollectionsFactory; import org.apache.shiro.SecurityUtils; import org.apache.shiro.subject.Subject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import static com.megagao.production.ssm.common.Constants.NO_PERMISSION; /** * * 权限判断controller * */ @RestController public class AuthorityJudgeController { private static final Logger logger = LoggerFactory.getLogger(AuthorityJudgeController.class); @RequestMapping("*/*_judge") public Map<String,Object> authorityJudge(HttpServletRequest request) throws Exception{ Subject subject = SecurityUtils.getSubject(); ActiveUser activeUser = (ActiveUser) subject.getPrincipal(); //根据uri,使用shiro判断相应权限 String uri = request.getRequestURI(); String[] names = uri.split("/"); String featureName = names[2]; String operateName = names[3].split("_")[0]; Map<String,Object> map = CollectionsFactory.newHashMap(); if(!activeUser.getUserStatus().equals("1")){ if (logger.isDebugEnabled()) { logger.debug(NO_PERMISSION, "账户已被锁定!"); } map.put("msg", "您的账户已被锁定,请切换账户登录!"); }else if(!activeUser.getRoleStatus().equals("1")){ if (logger.isDebugEnabled()) { logger.debug(NO_PERMISSION, "角色已被锁定!"); } map.put("msg", "当前角色已被锁定,请切换账户登录!"); }else{ if (logger.isDebugEnabled()) { logger.debug(NO_PERMISSION, "没有权限!"); } if(!subject.isPermitted(featureName+":"+operateName)){ map.put("msg", "您没有权限,请切换用户登录!"); } } return map; } }
最近下载更多
weilaizhisheng LV21
昨天
pureshyness LV6
2月14日
403401 LV2
2023年12月17日
guanrenan LV10
2023年11月28日
daguocai001 LV3
2023年11月4日
ytiian_hm LV6
2023年9月12日
baozhenghua LV2
2023年8月29日
wuying8208 LV15
2023年7月27日
自丶渡 LV3
2023年6月16日
哇塞塞哈哈哈 LV8
2023年5月5日
最近浏览更多
weilaizhisheng LV21
昨天
qinxixing LV4
3月2日
test6758 LV2
2月23日
mypogo
2月20日
暂无贡献等级
pureshyness LV6
2月14日
midyn203 LV2
2月5日
admin_z LV22
1月28日
PSSDZH LV3
1月25日
Camellia-while LV1
1月2日
wwewww LV4
2023年12月18日