[Statelessfilter-commits] SF.net SVN: statelessfilter:[116] trunk
Status: Beta
Brought to you by:
nricheton
From: <nri...@us...> - 2013-10-24 09:02:52
|
Revision: 116 http://sourceforge.net/p/statelessfilter/code/116 Author: nricheton Date: 2013-10-24 09:02:49 +0000 (Thu, 24 Oct 2013) Log Message: ----------- Cleanup Modified Paths: -------------- trunk/pom.xml trunk/stateless-cookie-aes/pom.xml trunk/stateless-cookie-aes/src/main/java/net/sourceforge/statelessfilter/backend/aescookie/AESCookieBackend.java trunk/stateless-core/src/main/java/net/sourceforge/statelessfilter/backend/support/CookieBackendSupport.java Added Paths: ----------- trunk/stateless-cookie-aes/src/test/java/net/ trunk/stateless-cookie-aes/src/test/java/net/sourceforge/ trunk/stateless-cookie-aes/src/test/java/net/sourceforge/statelessfilter/ trunk/stateless-cookie-aes/src/test/java/net/sourceforge/statelessfilter/backend/ trunk/stateless-cookie-aes/src/test/java/net/sourceforge/statelessfilter/backend/aescookie/ trunk/stateless-cookie-aes/src/test/java/net/sourceforge/statelessfilter/backend/aescookie/AESCookieBackendTest.java Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2013-10-24 08:33:06 UTC (rev 115) +++ trunk/pom.xml 2013-10-24 09:02:49 UTC (rev 116) @@ -159,4 +159,34 @@ <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> + <dependencyManagement> + <dependencies> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>2.5</version> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.11</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <version>1.7.5</version> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <version>2.6</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <version>1.7.5</version> + <scope>test</scope> + </dependency> + </dependencies> + </dependencyManagement> </project> \ No newline at end of file Modified: trunk/stateless-cookie-aes/pom.xml =================================================================== --- trunk/stateless-cookie-aes/pom.xml 2013-10-24 08:33:06 UTC (rev 115) +++ trunk/stateless-cookie-aes/pom.xml 2013-10-24 09:02:49 UTC (rev 116) @@ -1,39 +1,47 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> - <parent> - <artifactId>stateless-parent</artifactId> - <groupId>net.sourceforge.statelessfilter</groupId> - <version>0.8.2-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - <artifactId>stateless-cookie-aes</artifactId> - <name>Store: AES cookie</name> - - <dependencies> - <dependency> - <groupId>net.sourceforge.statelessfilter</groupId> - <artifactId>stateless-core</artifactId> - <version>0.8.2-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>javax.servlet</groupId> - <artifactId>servlet-api</artifactId> - <version>2.5</version> - <type>jar</type> - <scope>provided</scope> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - <version>1.5.8</version> - <type>jar</type> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.4</version> - <type>jar</type> - <scope>compile</scope> - </dependency> - </dependencies> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <parent> + <artifactId>stateless-parent</artifactId> + <groupId>net.sourceforge.statelessfilter</groupId> + <version>0.8.2-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>stateless-cookie-aes</artifactId> + <name>Store: AES cookie</name> + + <dependencies> + <dependency> + <groupId>net.sourceforge.statelessfilter</groupId> + <artifactId>stateless-core</artifactId> + <version>0.8.2-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <type>jar</type> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + <type>jar</type> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>commons-lang</groupId> + <artifactId>commons-lang</artifactId> + <type>jar</type> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-simple</artifactId> + <scope>test</scope> + </dependency> + </dependencies> </project> \ No newline at end of file Modified: trunk/stateless-cookie-aes/src/main/java/net/sourceforge/statelessfilter/backend/aescookie/AESCookieBackend.java =================================================================== --- trunk/stateless-cookie-aes/src/main/java/net/sourceforge/statelessfilter/backend/aescookie/AESCookieBackend.java 2013-10-24 08:33:06 UTC (rev 115) +++ trunk/stateless-cookie-aes/src/main/java/net/sourceforge/statelessfilter/backend/aescookie/AESCookieBackend.java 2013-10-24 09:02:49 UTC (rev 116) @@ -1,20 +1,23 @@ /* * Copyright 2009-2010 Capgemini - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * */ package net.sourceforge.statelessfilter.backend.aescookie; +import static org.apache.commons.lang.StringUtils.defaultIfEmpty; +import static org.apache.commons.lang.StringUtils.isEmpty; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -41,7 +44,6 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang.ArrayUtils; -import org.apache.commons.lang.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,15 +69,17 @@ private static final String ENCRYPTION = "AES"; //$NON-NLS-1$ private static final String ENCRYPTION_WITH_PARAM = "AES/CBC/PKCS5Padding"; //$NON-NLS-1$ private static final String ID = "aescookie"; //$NON-NLS-1$ - private static final String PARAM_COMPRESS = "compress"; //$NON-NLS-1$ - private static final String PARAM_IV = "iv"; //$NON-NLS-1$ - private static final String PARAM_KEY = "key"; //$NON-NLS-1$ + private static Logger logger = LoggerFactory.getLogger(AESCookieBackend.class); + public static final String PARAM_COMPRESS = "compress"; //$NON-NLS-1$ + public static final String PARAM_IV = "iv"; //$NON-NLS-1$ + public static final String PARAM_KEY = "key"; //$NON-NLS-1$ + public static final String PARAM_SESSION_MAX_TIME = "sessionMaxTime"; + public static final String PARAM_SIGN_SECRET = "secret"; private static final String SEPARATOR = "B"; //$NON-NLS-1$ - private static final Object PARAM_SIGN_SECRET = "secret"; private boolean compress = true; private IvParameterSpec iv = null; - Logger logger = LoggerFactory.getLogger(AESCookieBackend.class); private SecretKeySpec secretKey = null; + private Integer sessionMaxTime; // seconds private String signSecret; public AESCookieBackend() { @@ -90,6 +94,10 @@ // Nothing to do } + public boolean getCompress() { + return compress; + } + private byte[] getEncryptionBytes(String data, int length) { byte[] keyRaw = new byte[length]; for (int i = 0; i < length; i++) { @@ -110,6 +118,14 @@ return ID; } + public Integer getSessionMaxTime() { + return sessionMaxTime; + } + + public String getSignSecret() { + return signSecret; + } + /** * Loads key and iv for encryption and performs normal init. * @@ -119,19 +135,21 @@ @Override public void init(Map<String, String> config) throws Exception { super.init(config); - this.compress = Boolean.parseBoolean(StringUtils.defaultIfEmpty(config.get(PARAM_COMPRESS), "true")); - this.signSecret = StringUtils.defaultIfEmpty(config.get(PARAM_SIGN_SECRET), UUID.randomUUID().toString()); + this.compress = Boolean.parseBoolean(defaultIfEmpty(config.get(PARAM_COMPRESS), "true")); + this.signSecret = defaultIfEmpty(config.get(PARAM_SIGN_SECRET), UUID.randomUUID().toString()); + this.sessionMaxTime = isEmpty(config.get(PARAM_SESSION_MAX_TIME)) ? null : Integer.parseInt(config + .get(PARAM_SESSION_MAX_TIME)); if (logger.isInfoEnabled()) { - logger.info("Cookie name: '" + cookieName + "', compression: '" //$NON-NLS-1$//$NON-NLS-2$ - + this.compress + "'"); //$NON-NLS-1$ + logger.info( + "Cookie name: '{}', compression: '{}', session max time: '{}'", new Object[] { this.cookieName, this.compress, this.sessionMaxTime }); //$NON-NLS-1$ } // AES configuration String key = config.get(PARAM_KEY); String iv = config.get(PARAM_IV); - if (StringUtils.isEmpty(key) || StringUtils.isEmpty(iv)) { - throw new Exception(ID + if (isEmpty(key) || isEmpty(iv)) { + throw new IllegalArgumentException(ID + "." + PARAM_KEY + " or " + ID + "." + PARAM_IV + " parameter missing in /stateless.properties."); //$NON-NLS-1$ } Added: trunk/stateless-cookie-aes/src/test/java/net/sourceforge/statelessfilter/backend/aescookie/AESCookieBackendTest.java =================================================================== --- trunk/stateless-cookie-aes/src/test/java/net/sourceforge/statelessfilter/backend/aescookie/AESCookieBackendTest.java (rev 0) +++ trunk/stateless-cookie-aes/src/test/java/net/sourceforge/statelessfilter/backend/aescookie/AESCookieBackendTest.java 2013-10-24 09:02:49 UTC (rev 116) @@ -0,0 +1,37 @@ +package net.sourceforge.statelessfilter.backend.aescookie; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +public class AESCookieBackendTest { + + @Test + public void testInitConfiguration() throws Exception { + AESCookieBackend backend = new AESCookieBackend(); + Map<String, String> config = new HashMap<String, String>(); + config.put(AESCookieBackend.PARAM_SESSION_MAX_TIME, "3600"); + config.put(AESCookieBackend.PARAM_COOKIENAME, "test"); + config.put(AESCookieBackend.PARAM_KEY, "0123456789ABCDEF"); + config.put(AESCookieBackend.PARAM_IV, "FEDCBA9876543210"); + config.put(AESCookieBackend.PARAM_SIGN_SECRET, "secret"); + backend.init(config); + + assertEquals(3600, backend.getSessionMaxTime().intValue()); + assertEquals(3600, backend.getSessionMaxTime().intValue()); + assertEquals("secret", backend.getSignSecret()); + } + + @Test(expected = IllegalArgumentException.class) + public void testInitWithoutAESConfiguration() throws Exception { + AESCookieBackend backend = new AESCookieBackend(); + Map<String, String> config = new HashMap<String, String>(); + config.put(AESCookieBackend.PARAM_SESSION_MAX_TIME, "3600"); + config.put(AESCookieBackend.PARAM_COOKIENAME, "test"); + backend.init(config); + } + +} Modified: trunk/stateless-core/src/main/java/net/sourceforge/statelessfilter/backend/support/CookieBackendSupport.java =================================================================== --- trunk/stateless-core/src/main/java/net/sourceforge/statelessfilter/backend/support/CookieBackendSupport.java 2013-10-24 08:33:06 UTC (rev 115) +++ trunk/stateless-core/src/main/java/net/sourceforge/statelessfilter/backend/support/CookieBackendSupport.java 2013-10-24 09:02:49 UTC (rev 116) @@ -67,10 +67,10 @@ private static Logger logger = LoggerFactory.getLogger(CookieBackendSupport.class); /* Constants used in properties */ - private static final String PARAM_COOKIEDOMAIN = "cookiedomain"; //$NON-NLS-1$ - private static final String PARAM_COOKIEMAXAGE = "cookiemaxage"; //$NON-NLS-1$ - private static final String PARAM_COOKIENAME = "cookiename"; //$NON-NLS-1$ - private static final String PARAM_COOKIEPATH = "cookiepath"; //$NON-NLS-1$ + public static final String PARAM_COOKIEDOMAIN = "cookiedomain"; //$NON-NLS-1$ + public static final String PARAM_COOKIEMAXAGE = "cookiemaxage"; //$NON-NLS-1$ + public static final String PARAM_COOKIENAME = "cookiename"; //$NON-NLS-1$ + public static final String PARAM_COOKIEPATH = "cookiepath"; //$NON-NLS-1$ /** * Constant used to store the number of cookie segment within a single This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |