shiro技术_shiro渗透工具

文章导航:

Shiro的 rememberMe 功能使用指导为什么rememberMe设置了没作用

1、打开IE选工具/Internet选项/内容/自动完成/自动完成功能应用于下面有四个选项,如果没有勾选,请勾选,按确定应用即可。

2、如果故障依旧,运行输入gpedit.msc回车打开组策略,在左侧选用户配置/管理模板/Windows组件/Internet Explorer/在右侧选“禁用表单的自动完成功能”和“禁止自动完成功能保存密码”双击它,在打开的对话框中选择“未配置”然后按应用确定,重启电脑即可。

3、也可以,修改注册表启动“自动完成”功能

开始/运行输入regedit回车打开注册表编辑器,依次单击展开[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer]子健,在其下新建一个名为“Autocomplete”的子健,然后在右窗口新建一个名为的“Append Completion”的“字符串值”键值项,将其数值设置为“YES”即可(注:上面新建的键值如果已存在就不需要重建,按照上述方法进行修改就是了)。

怎么获取shiro中的session对象

1、Shiro默认的Session处理方式

!-- 定义 Shiro 主要业务对象 --

bean id="securityManager" class="f5c9-6f1b-1bca-94e2 org.apache.shiro.web.mgt.DefaultWebSecurityManager"

!-- property name="sessionManager" ref="sessionManager" / --

property name="realm" ref="systemAuthorizingRealm" /

property name="cacheManager" ref="shiroCacheManager" /

/bean

这里从DefaultWebSecurityManager这里看起,这个代码是定义的Shiro安全管理对象,看下面的构造方法(代码 1-1)

(代码 1-1)

public DefaultWebSecurityManager() {

super();

((DefaultSubjectDAO) this.subjectDAO).setSessionStorageEvaluator(new DefaultWebSessionStorageEvaluator());

this.sessionMode = HTTP_SESSION_MODE;

setSubjectFactory(new DefaultWebSubjectFactory());

setRememberMeManager(new CookieRememberMeManager());

setSessionManager(new ServletContainerSessionManager());

}

从 构造方法里面可以看出,这里面有 publicvoid setRememberMeManager(RememberMeManager rememberMeManager) 和 publicvoid setSessionManager(SessionManager sessionManager)两个方法。这两个分别是对Shiro的remembereMe功能和Session功能的管理。其中在构造方法里面可以看到,其实一开是就设置了SessionManager,就是默认的:ServletContainerSessionManager().接下来看看默认的ServletContainerSessionManager()是怎么玩转Session的.看下图。这个图显示了这个类的这些个方法

这个类通过getSession(SessionKey)获得Sesison,下面看看这个方法干了些什么(代码1-2)

(代码1-2)

publicSession getSession(SessionKey key) throws SessionException {

if (!WebUtils.isHttp(key)) { //判断是不是http的key,否则抛异常

String msg = "SessionKey must be an HTTP compatible implementation.";

throw new IllegalArgumentException(msg);

}

HttpServletRequest request = WebUtils.getHttpRequest(key); //通过工具类获得HttpServletRequest 这类是javax.servlet.http.HttpServletRequest;

Session session = null;

HttpSession httpSession = request.getSession(false);//先从request里获得本来存在的

if (httpSession != null) {

session = createSession(httpSession, request.getRemoteHost());//如果不为空,就创建一个封装了的,为空就不管它

}

return session;

}

可以看看注释,注释上都写好了,这里的意思是,首先判断封装好的Key是不是Http的key,如果是就继续,不是就抛异常.key这个是带了ServletRequest和ServletResponse的WebSessinKey,具体怎么new出来的,看DefaultWebSecurityManager的这方法代码就知道了(代码1-3),这里里,将Request和Response还有sessionId传递进去

(代码1-3)

@Override

protected SessionKey getSessionKey(SubjectContext context) {

if (WebUtils.isWeb(context)) {

Serializable sessionId = context.getSessionId();

ServletRequest request = WebUtils.getRequest(context);

ServletResponse response = WebUtils.getResponse(context);

return new WebSessionKey(sessionId, request, response);

} else {

return super.getSessionKey(context);

}

}

因为继承了 org.apache.shiro.session.mgt.DefaultSessionKey ,这个类是实现了SessionKey这个接口。

看看createSession这个方法,这个方法就是将传入的HttpSession和host传进去,封装成Shiro的HttpServletSession (代码 1-4)

(代码1-4)

protectedSession createSession(HttpSession httpSession, String host) {

return new HttpServletSession(httpSession, host);

}

关于默认的Session管理器,最后还看一下HttpServletSession这个类,就看一下的几个方法,还有些方法是没有放出来的,可以明显的看出,Shiro使用了一个叫Session的接口,但这个接口是和HttpSession的接口一模一样,就是通过HttpSession这个接口获得Session的功能(代码1-5)

(代码1-5)

public class HttpServletSession implements Session {

private HttpSession httpSession = null;

public HttpServletSession(HttpSession httpSession, String host) {

if (httpSession == null) {

String msg = "HttpSession constructor argument cannot be null.";

throw new IllegalArgumentException(msg);

}

if (httpSession instanceof ShiroHttpSession) {

String msg = "HttpSession constructor argument cannot be an instance of ShiroHttpSession. This " +

"is enforced to prevent circular dependencies and infinite loops.";

throw new IllegalArgumentException(msg);

}

this.httpSession = httpSession;

if (StringUtils.hasText(host)) {

setHost(host);

}

}

……………………

……………………

………………

public Object getAttribute(Object key) throws InvalidSessionException {

try {

return httpSession.getAttribute(assertString(key));

} catch (Exception e) {

throw new InvalidSessionException(e);

}

}

public void setAttribute(Object key, Object value) throws InvalidSessionException {

try {

httpSession.setAttribute(assertString(key), value);

} catch (Exception e) {

throw new InvalidSessionException(e);

}

}

………………

………………

}

默认的模式就描述到这里

shiro记住我cookie无法添加 按照网上的说法 把配置文件中所有的配置都写了 javabea

ie11下查看cookie:1:IE11=》F12打开开发人员工具2:开发人员工具=》网络F5启用网络流量捕获3:IE11=》输入和访问相关网址4:开发人员工具=》网络=》详细信息=》Cookie如果你只在java后台写的cookie,前端浏览器当然看不到

原文链接:,转发请注明来源!
「shiro技术_shiro渗透工具」评论列表
仿站
仿站
发布于 2022-07-13 11:49:07  回复
ecurityManager这里看起,这个代码是定义的Shiro安全管理对象,看下面的构造方法(代码 1-1)(代码 1-1)public DefaultWebSecurityManager() { super(); ((DefaultSubjectD
仿站
仿站
发布于 2022-07-13 21:41:47  回复
下面的构造方法(代码 1-1)(代码 1-1)public DefaultWebSecurityManager() { super(); ((DefaultSubjectDAO
仿站
仿站
发布于 2022-07-13 13:54:22  回复
return new WebSessionKey(sessionId, request, response); } else { return super.getSessionKey(context);
仿站
仿站
发布于 2022-07-13 14:37:18  回复
r" !-- property name="sessionManager" ref="sessionManager" / -- propert

发表评论