|
22 | 22 | import com.liferay.portal.kernel.portlet.PortletPreferencesFactoryUtil; |
23 | 23 |
|
24 | 24 | import java.util.ConcurrentModificationException; |
| 25 | +import java.util.Enumeration; |
25 | 26 |
|
26 | 27 | import javax.servlet.http.HttpServletRequest; |
27 | 28 | import javax.servlet.http.HttpSession; |
@@ -143,10 +144,46 @@ public static void put(HttpSession httpSession, String key, String value) { |
143 | 144 | public static void put( |
144 | 145 | HttpSession httpSession, String namespace, String key, String value) { |
145 | 146 |
|
146 | | - String sessionKey = StringBundler.concat( |
147 | | - namespace, StringPool.COLON, key); |
| 147 | + if ((key.length() > _SESSION_CLICKS_MAX_SIZE_TERMS) || |
| 148 | + (value.length() > _SESSION_CLICKS_MAX_SIZE_TERMS)) { |
| 149 | + |
| 150 | + if (_log.isWarnEnabled()) { |
| 151 | + _log.warn( |
| 152 | + StringBundler.concat( |
| 153 | + "Session clicks has attempted to exceed the maximum ", |
| 154 | + "size allowed for keys or values with {key=", key, |
| 155 | + ", value=", value, "}")); |
| 156 | + } |
| 157 | + |
| 158 | + return; |
| 159 | + } |
| 160 | + |
| 161 | + Enumeration<String> enumeration = httpSession.getAttributeNames(); |
| 162 | + |
| 163 | + int size = 0; |
| 164 | + |
| 165 | + while (enumeration.hasMoreElements()) { |
| 166 | + enumeration.nextElement(); |
| 167 | + |
| 168 | + size++; |
| 169 | + } |
148 | 170 |
|
149 | | - httpSession.setAttribute(sessionKey, value); |
| 171 | + if (size < _SESSION_CLICKS_MAX_ALLOWED_VALUES) { |
| 172 | + String sessionKey = StringBundler.concat( |
| 173 | + namespace, StringPool.COLON, key); |
| 174 | + |
| 175 | + httpSession.setAttribute(sessionKey, value); |
| 176 | + |
| 177 | + return; |
| 178 | + } |
| 179 | + |
| 180 | + if (_log.isWarnEnabled()) { |
| 181 | + _log.warn( |
| 182 | + StringBundler.concat( |
| 183 | + "Session clicks has attempted to exceed the maximum ", |
| 184 | + "number of allowed values with {key=", key, ", value=", |
| 185 | + value, "}")); |
| 186 | + } |
150 | 187 | } |
151 | 188 |
|
152 | 189 | private static final String _DEFAULT_NAMESPACE = |
|
0 commit comments