Shiro的注解授权不起作用
这是我的controller
package com.ivo.controller;
import javax.annotation.Resource;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ivo.model.User;
import com.ivo.service.UserService;
@Controller
@RequestMapping(value="/user")
public class LoginController {
@Resource(name="userService")
private UserService userService;
@RequestMapping(value="/check")
public String findUser(User user){
Subject subject = SecurityUtils.getSubject();
System.out.println("权限:"+subject.isPermitted("Q8"));
// Session session = subject.getSession();
UsernamePasswordToken token = new UsernamePasswordToken(user.getUserid(),user.getPassword());
token.setRememberMe(true);
try {
subject.login(token);//跳到realm
// session.setTimeout(100);
return "main";
}catch (AuthenticationException e) {
token.clear();
return "register";
}
}
@RequestMapping(value="/register")
public String register(){
return "register";
}
@RequiresPermissions("Q8")
@RequestMapping(value="/master") //注解授权在这里
public String master(){
return "master";
}
@RequestMapping(value="/logout")
public String exit(){
Subject subject = SecurityUtils.getSubject();
System.out.println("SessionID:"+subject.getSession().getId());
if(subject.getSession()==null){
System.out.println("没有Session");
}else{
System.out.println("有Session");
}
SecurityUtils.getSubject().logout();
return "register";
}
}
下面是我的applicationContent.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd ">
classpath:com/ivo/model/
org.hibernate.dialect.MySQL5Dialect
true
update
当我运行项目的时候没有报错,原本的意思是只有Q8权限的subject可以打开,但是实际情况是没有这个权限的subject也可以打开,相当困惑,这是什么原因导致的呢?希望大家能帮忙给看看,先在这里谢过了~
相关阅读:
web.py文件上传
关于PHP提交数据库事务模式的设计
bower init 初始化 报错
Number()函数传入Object时的情况
scrapy有模拟登录网站的相关方法吗?
Laycher ps -aux中的time 的意思
需要一个java的开源视频处理工具
在即时聊天服务中, 服务端只开一个监听端口,如果一个客户端连接过来了,服务端要不要开启一个临时端口和客户端进行通信啊?
oc范型能用于适配iOS7 的代码吗?
IE9下不能在iframe中click()
面向对象问题,方法体中不能将对象设置为空吗?
thinkphp查询结果view中如何多列显示?
删除文章是真从数据库里面删了吗?
程序运行中止,求原因
JS 的循环引用, 原因是什么?
DOM解析XML文件时抛出空指针异常
php网站开发,关于‘文章列表页显示’的疑问?
看看我这个函数为啥没反应?
mysql如何优化数据量极大的sql语句,并且要查询两张表
node中的process.nextTick 与 js定时器调用的原理区别问题?