1 /**
2 * Waffle (https://github.com/dblock/waffle)
3 *
4 * Copyright (c) 2010 - 2015 Application Security, Inc.
5 *
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors:
12 * Application Security, Inc.
13 */
14 package waffle.mock.http;
15
16 import java.util.Enumeration;
17 import java.util.HashMap;
18 import java.util.Map;
19
20 import javax.servlet.ServletContext;
21 import javax.servlet.http.HttpSession;
22 import javax.servlet.http.HttpSessionContext;
23
24 /**
25 * Simple Http Session.
26 *
27 * @author dblock[at]dblock[dot]org
28 */
29 @SuppressWarnings("deprecation")
30 public class SimpleHttpSession implements HttpSession {
31
32 /** The attributes. */
33 private final Map<String, Object> attributes = new HashMap<String, Object>();
34
35 /* (non-Javadoc)
36 * @see javax.servlet.http.HttpSession#getAttribute(java.lang.String)
37 */
38 @Override
39 public Object getAttribute(final String attributeName) {
40 return this.attributes.get(attributeName);
41 }
42
43 /* (non-Javadoc)
44 * @see javax.servlet.http.HttpSession#getAttributeNames()
45 */
46 @Override
47 public Enumeration<String> getAttributeNames() {
48 return null;
49 }
50
51 /* (non-Javadoc)
52 * @see javax.servlet.http.HttpSession#getCreationTime()
53 */
54 @Override
55 public long getCreationTime() {
56 return 0;
57 }
58
59 /* (non-Javadoc)
60 * @see javax.servlet.http.HttpSession#getId()
61 */
62 @Override
63 public String getId() {
64 return null;
65 }
66
67 /* (non-Javadoc)
68 * @see javax.servlet.http.HttpSession#getLastAccessedTime()
69 */
70 @Override
71 public long getLastAccessedTime() {
72 return 0;
73 }
74
75 /* (non-Javadoc)
76 * @see javax.servlet.http.HttpSession#getMaxInactiveInterval()
77 */
78 @Override
79 public int getMaxInactiveInterval() {
80 return 0;
81 }
82
83 /* (non-Javadoc)
84 * @see javax.servlet.http.HttpSession#getServletContext()
85 */
86 @Override
87 public ServletContext getServletContext() {
88 return null;
89 }
90
91 /* (non-Javadoc)
92 * @see javax.servlet.http.HttpSession#getSessionContext()
93 */
94 @Deprecated
95 @Override
96 public HttpSessionContext getSessionContext() {
97 return null;
98 }
99
100 /* (non-Javadoc)
101 * @see javax.servlet.http.HttpSession#getValue(java.lang.String)
102 */
103 @Deprecated
104 @Override
105 public Object getValue(final String arg0) {
106 return null;
107 }
108
109 /* (non-Javadoc)
110 * @see javax.servlet.http.HttpSession#getValueNames()
111 */
112 @Deprecated
113 @Override
114 public String[] getValueNames() {
115 return new String[0];
116 }
117
118 /* (non-Javadoc)
119 * @see javax.servlet.http.HttpSession#invalidate()
120 */
121 @Override
122 public void invalidate() {
123 // Do Nothing
124 }
125
126 /* (non-Javadoc)
127 * @see javax.servlet.http.HttpSession#isNew()
128 */
129 @Override
130 public boolean isNew() {
131 return false;
132 }
133
134 /* (non-Javadoc)
135 * @see javax.servlet.http.HttpSession#putValue(java.lang.String, java.lang.Object)
136 */
137 @Deprecated
138 @Override
139 public void putValue(final String arg0, final Object arg1) {
140 // Do Nothing
141 }
142
143 /* (non-Javadoc)
144 * @see javax.servlet.http.HttpSession#removeAttribute(java.lang.String)
145 */
146 @Override
147 public void removeAttribute(final String attributeName) {
148 this.attributes.remove(attributeName);
149 }
150
151 /* (non-Javadoc)
152 * @see javax.servlet.http.HttpSession#removeValue(java.lang.String)
153 */
154 @Deprecated
155 @Override
156 public void removeValue(final String arg0) {
157 // Do Nothing
158 }
159
160 /* (non-Javadoc)
161 * @see javax.servlet.http.HttpSession#setAttribute(java.lang.String, java.lang.Object)
162 */
163 @Override
164 public void setAttribute(final String attributeName, final Object attributeValue) {
165 this.attributes.put(attributeName, attributeValue);
166 }
167
168 /* (non-Javadoc)
169 * @see javax.servlet.http.HttpSession#setMaxInactiveInterval(int)
170 */
171 @Override
172 public void setMaxInactiveInterval(final int arg0) {
173 // Do Nothing
174 }
175 }