简单的cas单点登录+加密 SSM
来源:互联网 发布:网络运营管理岗 面试 编辑:程序博客网 时间:2024/06/05 09:51
楼主新萌一枚,写了一些小的demo 拿出来分析一下,如果有那些问题 欢迎大家前来指点,废话不多说啦,下面是代码
~~~~~~~~~~~~~~~~~~~~华丽的分割线~~~~~~~~~~~~~~~~~~~
/*楼主redis 的xml配置一直失败,然后就放弃了,改成了编码形式
第一次发帖,害羞胆怯
登陆方法
*/
@Override
public Customer loginSelect(String username, String password, HttpServletResponse response) throws Exception {Customer customer = loginDao.loginSelect(username, Md5Utils.encryptPassword(password, "加盐"));
有数据的话 ,就保存在session中
if (null != customer) {
更新最后登陆时间
loginDao.updateLdate(format.format(new Date()), customer.getC_id());
将对象装换为JSON
String str = JSON.json(new Cust(customer.getC_id(), customer.getC_nickname()));
String token = UUID.randomUUID().toString().replaceAll(-, );
生成token 放入redis中
Jedis jedis = RedisPoll.getJedis();
jedis.set(token, str);
设置15分钟
jedis.expire(token, 60 15);
RedisPoll.returnResource(jedis);
放入cookie
Cookie cookie = new Cookie(token, token);
cookie.setPath();
cookie.setMaxAge(60 15);
response.addCookie(cookie);
return customer;
}
return null;
}
/**
* 单点登陆认证中心
* @param request
* @param response
* @return
* @throws Exception
*/
@RequestMapping(value = "/getCookie.action")
@ResponseBody
public String dandian(HttpServletRequest request, HttpServletResponse response) throws Exception {
// 获得到客户端的cookies
Cookie[] cookies = request.getCookies();
if (null != cookies && cookies.length > 0) {
for (Cookie cookie : cookies) {
// 拿到token
if (cookie.getName().equals("token")) {
// 有
Jedis jedis = RedisPoll.getJedis();
// 得到token的value
String value = cookie.getValue();
String customer = jedis.get(value);
// 判断redis中是否有这个字
if (!"null".equals(customer)) {
// 更新在redis中的有效时间
jedis.expire(value, 60 * 15);
// 更新cookie有效时间
cookie.setMaxAge(60 * 15);
response.addCookie(cookie);
// 关闭redis
RedisPoll.returnResource(jedis);
return customer;
}
// 关闭redis
RedisPoll.returnResource(jedis);
}
}
}
return "null";
}
/**
* 退出登陆
*
* @param request
* @param model
* @return
* @throws IOException
*/
@RequestMapping("/outlogin.action")
@ResponseBody
public String outLoign(HttpServletRequest request) throws IOException {
// 获得到cookies
Cookie[] cookies = request.getCookies();
if (null != cookies && cookies.length > 0) {
for (Cookie cookie : cookies) {
// 得到token
if (cookie.getName().equals("token")) {
// 有
Jedis jedis = RedisPoll.getJedis();
// 得到token的value
String value = cookie.getValue();
String customer = jedis.get(value);
// 判断redis中是否有这个字
if (!"null".equals(customer)) {
// 删除这个redis
jedis.del(value);
// 关闭redis
RedisPoll.returnResource(jedis);
return "null";
}
// 关闭redis
RedisPoll.returnResource(jedis);
}
}
}
return "null";
}
阅读全文
0 0
- 简单的cas单点登录+加密 SSM
- cas单点登录的简单例子
- SSO的CAS单点登录简单例子
- Cas单点登录的简单了解
- 一个yale-cas实现单点登录的简单例子实现
- java单点登录系统CAS的简单使用
- java单点登录系统CAS的简单使用
- java单点登录系统CAS的简单使用
- Java 单点登录系统 CAS 的简单使用
- 单点登录cas的使用
- CAS的单点登录原理
- CAS 实现的单点登录
- CAS 实现的单点登录
- 单点登录之CAS简单介绍
- Mvc4单点登录之一Cas简单介绍
- cas单点登录(sso)简单Demo
- CAS单点登录服务器的配置
- 完整的CAS单点登录教程
- oracle数据库索引相关知识
- Deep Learning of Binary Hash Codes for Fast Image Retrieval_CVPR2015
- 数字三角形POJ1163 program7.1.4.cpp
- 《大话数据结构》——学习笔记(栈&串&树)
- union和union-all的区别
- 简单的cas单点登录+加密 SSM
- extjs的alias和xtype比较
- form提交表单 踩坑
- vue + ElementUI 关闭对话框清空验证,清除form表单
- 每天一个linux命令(9):touch 命令
- 基于TCP协议的Socket通信实例(JAVA)
- <?xml version="1.0" encoding="UTF-8" standalone="no"?>
- python爬虫系列(一)百度首页爬取
- 不安装Oracle使用PlSqlDeveloper