- 浏览: 2552532 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Session Fixation Security Issue(3)Local Cache Improvement
Just learn from others, try to implement this local cache in my demo project.
Just copy the codes from the openfire repository, but I only want to use the local cache. So I remove some codes about CacheFactory.java from DefaultCache class and rename it to LocalCache.
The test case for it is as follow:
package com.sillycat.easywebflow.core.localcache;
import org.junit.Test;
import org.springframework.util.Assert;
public class LocalCacheTest {
@Test
public void dummy() {
Assert.isTrue(true);
}
@Test
public void lifetime() throws InterruptedException {
LocalCache<string string> localCache = new LocalCache<string string>(
"test_name", 1024 * 1024 * 100, 5000);
for (int i = 0; i &gt; sessionLocalCache = new LocalCache<string map object>&gt;(
"localSession", 1024 * 1024 * 100, 10000);
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest servletRequest,
ServletResponse serlvetResponse, FilterChain chain)
throws IOException, ServletException {
Thread currentThread = Thread.currentThread();
String threadName = currentThread.getName();
if (!(servletRequest instanceof HttpServletRequest)) {
log.error("Can only process HttpServletRequest");
throw new ServletException("Can only process HttpServletRequest");
}
if (!(serlvetResponse instanceof HttpServletResponse)) {
log.error("Can only process HttpServletResponse");
throw new ServletException("Can only process HttpServletResponse");
}
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) serlvetResponse;
// read cookie
Cookie[] cookies_array = request.getCookies();
String sessionId_fromCookie = "";
if (cookies_array != null &amp;&amp; cookies_array.length &gt; 0) {
for (int i = 0; i attributesToMigrate = null;
// get session
HttpSession session = request.getSession(false);
if (session == null &amp;&amp; request.isRequestedSessionIdValid() == false) {
log.debug(threadName
+ " how did this happen, there is no session!!!!!!!!!!!! + sessionId_fromCookie="
+ sessionId_fromCookie);
}
String originalSessionId = "";
if (session != null &amp;&amp; request.isRequestedSessionIdValid() != false) {
originalSessionId = session.getId();
// save the attributes in map
if (migrateSessionAttributes) {
attributesToMigrate = new HashMap<string object>();
Enumeration&gt; enumer = session.getAttributeNames();
while (enumer.hasMoreElements()) {
try {
String key = (String) enumer.nextElement();
if (session != null
&amp;&amp; request.isRequestedSessionIdValid() != false) {
attributesToMigrate.put(key,
session.getAttribute(key));
}
} catch (Exception e) {
log.error(threadName + " error message " + e
+ " sessionId=" + originalSessionId);
}
}
sessionLocalCache.put(originalSessionId, attributesToMigrate);
}
} else {
originalSessionId = sessionId_fromCookie;
}
// kill the old session
if (session != null &amp;&amp; request.isRequestedSessionIdValid() != false) {
if (log.isDebugEnabled()) {
log.debug(threadName + " Invalidating session with Id "
+ originalSessionId + " start!");
}
session.invalidate();
if (log.isDebugEnabled()) {
log.debug(threadName + "Invalidating session with Id "
+ originalSessionId + " end!");
}
// session.setMaxInactiveInterval(10);
}
session = request.getSession(true); // we now have a new session
if (log.isDebugEnabled()) {
log.debug(threadName + "Started new session: " + session.getId());
}
if (sessionLocalCache.containsKey(originalSessionId)) {
log.debug(threadName + "getting session value from map: "
+ originalSessionId);
attributesToMigrate = (HashMap<string object>) sessionLocalCache
.get(originalSessionId);
}
// migrate the attribute to new session
if (attributesToMigrate != null) {
Iterator&gt; iter = attributesToMigrate.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry, ?&gt; entry = (Entry, ?&gt;) iter.next();
try {
session.setAttribute((String) entry.getKey(),
entry.getValue());
} catch (Exception e) {
log.error(threadName + " error message " + e
+ " new SessionId=" + session.getId());
}
}
log.debug(threadName + " merge the data into new session ="
+ session.getId());
}
CookieRequestWrapper wrapperRequest = new CookieRequestWrapper(request);
wrapperRequest.setResponse(response);
chain.doFilter(wrapperRequest, response);
}
public void destroy() {
}
public boolean isMigrateSessionAttributes() {
return migrateSessionAttributes;
}
public void setMigrateSessionAttributes(boolean migrateSessionAttributes) {
this.migrateSessionAttributes = migrateSessionAttributes;
}
}
It is weird to manage session like this. It is not recommended way.
references:
http://hi.baidu.com/iburu/item/61b4e5144ff792f8ddeecacd
http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/cache/DefaultCache.java
http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/LinkedList.java
http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/LinkedListNode.java
http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/cache/Cache.java
http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/cache/CacheSizes.java
http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/cache/Cacheable.java
http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/cache/CannotCalculateSizeException.java
</string></string></string></string></string>
Just learn from others, try to implement this local cache in my demo project.
Just copy the codes from the openfire repository, but I only want to use the local cache. So I remove some codes about CacheFactory.java from DefaultCache class and rename it to LocalCache.
The test case for it is as follow:
package com.sillycat.easywebflow.core.localcache;
import org.junit.Test;
import org.springframework.util.Assert;
public class LocalCacheTest {
@Test
public void dummy() {
Assert.isTrue(true);
}
@Test
public void lifetime() throws InterruptedException {
LocalCache<string string> localCache = new LocalCache<string string>(
"test_name", 1024 * 1024 * 100, 5000);
for (int i = 0; i &gt; sessionLocalCache = new LocalCache<string map object>&gt;(
"localSession", 1024 * 1024 * 100, 10000);
public void init(FilterConfig filterConfig) throws ServletException {
}
public void doFilter(ServletRequest servletRequest,
ServletResponse serlvetResponse, FilterChain chain)
throws IOException, ServletException {
Thread currentThread = Thread.currentThread();
String threadName = currentThread.getName();
if (!(servletRequest instanceof HttpServletRequest)) {
log.error("Can only process HttpServletRequest");
throw new ServletException("Can only process HttpServletRequest");
}
if (!(serlvetResponse instanceof HttpServletResponse)) {
log.error("Can only process HttpServletResponse");
throw new ServletException("Can only process HttpServletResponse");
}
HttpServletRequest request = (HttpServletRequest) servletRequest;
HttpServletResponse response = (HttpServletResponse) serlvetResponse;
// read cookie
Cookie[] cookies_array = request.getCookies();
String sessionId_fromCookie = "";
if (cookies_array != null &amp;&amp; cookies_array.length &gt; 0) {
for (int i = 0; i attributesToMigrate = null;
// get session
HttpSession session = request.getSession(false);
if (session == null &amp;&amp; request.isRequestedSessionIdValid() == false) {
log.debug(threadName
+ " how did this happen, there is no session!!!!!!!!!!!! + sessionId_fromCookie="
+ sessionId_fromCookie);
}
String originalSessionId = "";
if (session != null &amp;&amp; request.isRequestedSessionIdValid() != false) {
originalSessionId = session.getId();
// save the attributes in map
if (migrateSessionAttributes) {
attributesToMigrate = new HashMap<string object>();
Enumeration&gt; enumer = session.getAttributeNames();
while (enumer.hasMoreElements()) {
try {
String key = (String) enumer.nextElement();
if (session != null
&amp;&amp; request.isRequestedSessionIdValid() != false) {
attributesToMigrate.put(key,
session.getAttribute(key));
}
} catch (Exception e) {
log.error(threadName + " error message " + e
+ " sessionId=" + originalSessionId);
}
}
sessionLocalCache.put(originalSessionId, attributesToMigrate);
}
} else {
originalSessionId = sessionId_fromCookie;
}
// kill the old session
if (session != null &amp;&amp; request.isRequestedSessionIdValid() != false) {
if (log.isDebugEnabled()) {
log.debug(threadName + " Invalidating session with Id "
+ originalSessionId + " start!");
}
session.invalidate();
if (log.isDebugEnabled()) {
log.debug(threadName + "Invalidating session with Id "
+ originalSessionId + " end!");
}
// session.setMaxInactiveInterval(10);
}
session = request.getSession(true); // we now have a new session
if (log.isDebugEnabled()) {
log.debug(threadName + "Started new session: " + session.getId());
}
if (sessionLocalCache.containsKey(originalSessionId)) {
log.debug(threadName + "getting session value from map: "
+ originalSessionId);
attributesToMigrate = (HashMap<string object>) sessionLocalCache
.get(originalSessionId);
}
// migrate the attribute to new session
if (attributesToMigrate != null) {
Iterator&gt; iter = attributesToMigrate.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry, ?&gt; entry = (Entry, ?&gt;) iter.next();
try {
session.setAttribute((String) entry.getKey(),
entry.getValue());
} catch (Exception e) {
log.error(threadName + " error message " + e
+ " new SessionId=" + session.getId());
}
}
log.debug(threadName + " merge the data into new session ="
+ session.getId());
}
CookieRequestWrapper wrapperRequest = new CookieRequestWrapper(request);
wrapperRequest.setResponse(response);
chain.doFilter(wrapperRequest, response);
}
public void destroy() {
}
public boolean isMigrateSessionAttributes() {
return migrateSessionAttributes;
}
public void setMigrateSessionAttributes(boolean migrateSessionAttributes) {
this.migrateSessionAttributes = migrateSessionAttributes;
}
}
It is weird to manage session like this. It is not recommended way.
references:
http://hi.baidu.com/iburu/item/61b4e5144ff792f8ddeecacd
http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/cache/DefaultCache.java
http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/LinkedList.java
http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/LinkedListNode.java
http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/cache/Cache.java
http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/cache/CacheSizes.java
http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/cache/Cacheable.java
http://svn.igniterealtime.org/svn/repos/openfire/trunk/src/java/org/jivesoftware/util/cache/CannotCalculateSizeException.java
</string></string></string></string></string>
发表评论
-
Update Site will come soon
2021-06-02 04:10 1679I am still keep notes my tech n ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 431Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 436Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 374Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 456VPN Server 2020(2)Docker on Cen ... -
Nginx Deal with OPTIONS in HTTP Protocol
2020-02-15 01:33 356Nginx Deal with OPTIONS in HTTP ... -
PDF to HTML 2020(1)pdftohtml Linux tool or PDFBox
2020-01-29 07:37 405PDF to HTML 2020(1)pdftohtml Li ... -
Elasticsearch Cluster 2019(2)Kibana Issue or Upgrade
2020-01-12 03:25 720Elasticsearch Cluster 2019(2)Ki ... -
Spark Streaming 2020(1)Investigation
2020-01-08 07:19 295Spark Streaming 2020(1)Investig ... -
Hadoop Docker 2019 Version 3.2.1
2019-12-10 07:39 295Hadoop Docker 2019 Version 3.2. ... -
MongoDB 2019(3)Security and Auth
2019-11-16 06:48 241MongoDB 2019(3)Security and Aut ... -
MongoDB 2019(1)Install 4.2.1 Single and Cluster
2019-11-11 05:07 294MongoDB 2019(1) Follow this ht ... -
Monitor Tool 2019(1)Monit Installation and Usage
2019-10-17 08:22 325Monitor Tool 2019(1)Monit Insta ... -
Ansible 2019(1)Introduction and Installation on Ubuntu and CentOS
2019-10-12 06:15 312Ansible 2019(1)Introduction and ... -
Timezone and Time on All Servers and Docker Containers
2019-10-10 11:18 332Timezone and Time on All Server ... -
Kafka Cluster 2019(6) 3 Nodes Cluster on CentOS7
2019-10-05 23:28 283Kafka Cluster 2019(6) 3 Nodes C ... -
K8S Helm(1)Understand YAML and Kubectl Pod and Deployment
2019-10-01 01:21 326K8S Helm(1)Understand YAML and ... -
Rancher and k8s 2019(5)Private Registry
2019-09-27 03:25 362Rancher and k8s 2019(5)Private ... -
Jenkins 2019 Cluster(1)Version 2.194
2019-09-12 02:53 444Jenkins 2019 Cluster(1)Version ... -
Redis Cluster 2019(3)Redis Cluster on CentOS
2019-08-17 04:07 373Redis Cluster 2019(3)Redis Clus ...
相关推荐
**会话固定攻击(Session Fixation)** 会话固定攻击是一种网络安全性问题,攻击者通过在用户登录前预先设定一个已知的会话ID(Session ID),然后在用户登录后继续使用这个固定的会话ID,从而能够控制或劫持用户的...
在Spring Security中,会话管理主要涉及到会话固定防护(Session Fixation Protection)和会话超时(Session Timeout)。 2. **会话固定防护** - 会话固定攻击是一种常见的安全威胁,攻击者通过获取用户的会话ID来...
7. **会话管理**:Spring Security提供了会话管理功能,包括会话固定攻击防护(Session Fixation Protection)、会话超时(Session Timeout)和并发会话控制(Concurrent Session Control)。 8. **记住我功能**:...
3. **获取Session值**:为了读取已存储的Session数据,类可能包含一个`get_session_data`方法,通过传入键名来返回对应的Session值。 4. **删除Session值**:如果需要移除某个Session数据,类中可能会有一个`unset_...
5. **会话管理**:Spring Security提供了会话管理功能,如会话固定保护(Session Fixation Protection)和会话超时控制。源码分析可以帮助理解如何自定义这些策略。 6. **Remember Me服务**:这个特性允许用户在...
Spring Security 可以帮助管理用户会话,防止会话固定攻击(session fixation)和会话超时。它提供了一套完整的会话管理策略,如强制使用 HTTPS、会话时间限制等。 五、集成其他框架 Spring Security 能很好地与 ...
5. **会话管理**:配置会话管理策略,防止会话固定攻击(session fixation)和其他会话相关的安全问题。 6. **测试和调试**:在Eclipse中运行应用,测试不同用户和角色能否正确访问相应资源,确保安全策略生效。 ...
5. **Session Management**: Spring Security提供了会话管理功能,包括会话固定防护(Session Fixation Protection)和会话超时检测,防止会话劫持和会话超时后仍能访问应用的情况。 6. **CSRF Protection**: 为了...
此外,SpringSecurity还提供了会话管理功能,包括会话固定保护(Session Fixation Protection)和会话超时(Session Timeout)等,以防止会话劫持和会话固定攻击。它还集成了Remember Me服务,允许用户在一定时间内...
4. **会话管理(Session Management)**:Spring Security提供了会话管理功能,如会话固定保护(Session Fixation Protection)、会话超时和并发会话控制,以防止会话劫持和会话固定攻击。 5. **CSRF防护(Cross-...
此外,Spring Security还提供了会话管理功能,包括会话固定保护(Session Fixation Protection)和会话超时管理。会话固定保护能防止会话劫持攻击,而会话超时则有助于防止未授权的长时间访问。 Spring Security3也...
3. 会话管理:Spring Security可以管理和监控用户会话,防止会话固定攻击(Session Fixation)和会话劫持(Session Hijacking),同时支持会话超时和跨站请求伪造(CSRF)防护。 三、Spring Security 3.1特性 1. ...
### J2EE的13种核心技术详解 #### 引言 Java从最初的浏览器脚本语言逐渐进化成为服务器端开发的主流技术,其中J2EE(Java 2 Platform, Enterprise Edition)平台扮演了至关重要的角色。J2EE由一系列服务、APIs和...
在Web开发中,Session是一种非常...在实际开发中,还需要考虑到Session的过期策略、安全性(防止Session Hijacking和Session Fixation攻击)以及性能优化(如Session的持久化存储和集群环境下的Session共享)等问题。
4. **会话管理**:Spring Security提供了会话管理功能,可以防止会话固定攻击(Session Fixation)、实现会话超时以及单点登录(Single Sign-On, SSO)。 5. **异常处理**:当安全规则不满足时,Spring Security会...
2. **防止Session Fixation**:在用户成功登录后,重新生成session ID,避免攻击者利用预先知道的session ID进行攻击。 3. **定期刷新session**:设置合理的session超时时间,并在用户活动时更新session的最后活跃...
5. **会话管理**:Spring Security 提供了会话管理功能,可以防止会话固定攻击(Session Fixation)、会话超时控制,以及会话并发控制,确保只有一个用户在同一时间使用同一会话。 6. **CSRF保护**:Spring ...
- **防止Session Fixation攻击**:通过在用户登录后重新生成Session ID来防止此类攻击,确保即使Session被恶意复制,攻击者也无法继续使用。 ### 方法安全控制 Spring Security不仅限于Web层的安全控制,还提供了...
5. **会话管理(Session Management)**:SpringSecurity可以控制会话的创建、生命周期和并发控制,防止会话固定攻击(Session Fixation)和会话劫持(Session Hijacking)。 6. **CSRF防护(Cross-Site Request ...
10. **Session Management**:Spring Security提供了丰富的会话管理策略,可以防止会话固定攻击(session fixation)、超时管理以及会话并发控制。 在实际开发中,我们可以通过XML或Java配置来集成Spring Security...