package com.shiro.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.shiro.Utils.EncryptUtils;
import com.shiro.model.User;
@Controller
@RequestMapping(value = "login")
public class LoginController {
/*
* @Autowired User user;
*/
/**
* 用户登录
*
* @param user
* 登录用户
* @return
*/
@RequestMapping(params = "main")
public ModelAndView login(User user,HttpSession session, HttpServletRequest request) {
ModelAndView modelView = new ModelAndView();
Subject currentUser = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(
user.getUsercode(), EncryptUtils.encryptMD5(user.getPassword()));
token.setRememberMe(true);
try {
currentUser.login(token);
} catch (AuthenticationException e) {
modelView.addObject("message", "login errors");
modelView.setViewName("/login");
e.printStackTrace();
}
if(currentUser.isAuthenticated()){
user.setUserName("张三");
session.setAttribute("userinfo", user);
modelView.setViewName("/main");
}else{
modelView.addObject("message", "login errors");
modelView.setViewName("/login");
}
return modelView;
}
/**
* 退出登录
*
* @return
*/
@RequestMapping(params = "logout")
public String logout() {
Subject currentUser = SecurityUtils.getSubject();
try {
currentUser.logout();
} catch (AuthenticationException e) {
e.printStackTrace();
}
return "/login";
}
@RequestMapping(params = "myjsp")
public ModelAndView login2() {
System.out.println("sss");
ModelAndView modelView = new ModelAndView();
modelView.addObject("message", "登录成功!");
modelView.setViewName("/my");
return modelView;
}
@RequestMapping(params = "test")
public ModelAndView login3() {
System.out.println("sss");
ModelAndView modelView = new ModelAndView();
modelView.addObject("message", "登录成功!");
modelView.setViewName("/test");
return modelView;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
shiro demo一个结合spring的实例
共57个文件
jar:23个
xml:7个
jsp:6个
5星 · 超过95%的资源 需积分: 44 2.8k 下载量 122 浏览量
2012-10-27
14:58:48
上传
评论 20
收藏 6.67MB RAR 举报
温馨提示
网上很多都是不全的,我看了都没太大用,最后还是自己写个demo,给初学者参考吧,用myeclipse8.6开发的,直接导入项目可用,稍配一下jdk,包括谁和授权,虽然没有跟后台交互,但是是模拟了一下数据库。还有一篇文档,我也会上传,大家可以去我的资源找一下,主要是对这个demo的解释,以及如何跟数据库交互。
资源推荐
资源详情
资源评论
收起资源包目录
shirodemo.rar (57个子文件)
shirodemo
.project 1KB
.mymetadata 300B
src
spring-shiro.xml 2KB
applicationContext.xml 670B
com
shiro
service
MonitorRealm.java 2KB
Utils
EncryptUtils.java 280B
model
User.java 541B
controller
UserController.java 841B
LoginController.java 2KB
spring-mvc.xml 2KB
WebRoot
WEB-INF
classes
spring-shiro.xml 2KB
applicationContext.xml 670B
com
shiro
service
MonitorRealm.class 3KB
Utils
EncryptUtils.class 649B
model
User.class 919B
controller
UserController.class 1KB
LoginController.class 3KB
spring-mvc.xml 2KB
lib
servlet-api.jar 173KB
log4j-1.2.16.jar 470KB
org.springframework.web.servlet-3.1.1.RELEASE.jar 560KB
org.springframework.web-3.1.1.RELEASE.jar 532KB
dom4j-1.6.1.jar 307KB
org.springframework.beans-3.1.1.RELEASE.jar 576KB
shiro-all-1.2.1.jar 521KB
org.springframework.expression-3.1.1.RELEASE.jar 172KB
jackson-all-1.8.5.jar 989KB
commons-logging-1.1.1.jar 59KB
org.springframework.context.support-3.1.1.RELEASE.jar 105KB
org.springframework.asm-3.1.1.RELEASE.jar 52KB
commons-io-2.0.1.jar 156KB
antlr-2.7.7.jar 435KB
org.springframework.aspects-3.1.1.RELEASE.jar 49KB
org.springframework.context-3.1.1.RELEASE.jar 812KB
aopalliance-1.0.jar 4KB
org.springframework.aop-3.1.1.RELEASE.jar 324KB
slf4j-api-1.5.2.jar 17KB
slf4j-log4j12-1.5.2.jar 9KB
commons-collections-3.2.1.jar 562KB
org.springframework.core-3.1.1.RELEASE.jar 439KB
jtds-1.2.5.jar 295KB
web.xml 2KB
my.jsp 494B
index.jsp 834B
images
blank.gif 43B
sflogo.png 9KB
top_bg.gif 519B
Thumbs.db 19KB
SyProLogo.png 10KB
login-logo.jpg 35KB
notmyjsp.jsp 479B
main.jsp 661B
META-INF
MANIFEST.MF 36B
login.jsp 3KB
error
noperms.jsp 648B
.myeclipse
.settings
org.eclipse.core.resources.prefs 244B
.classpath 2KB
共 57 条
- 1
牛一样的程序员
- 粉丝: 27
- 资源: 41
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页