Wraps disassembles cookies into a SavedCookie that is serializable
This commit is contained in:
Ray Krueger 2006-06-03 13:36:51 +00:00
parent f7020755be
commit 1a9629b197
2 changed files with 149 additions and 0 deletions

View File

@ -0,0 +1,86 @@
package org.acegisecurity.ui.savedrequest;
import javax.servlet.http.Cookie;
import java.io.Serializable;
/**
* Stores off the values of a cookie in a serializable holder
*
* @author Ray Krueger
*/
public class SavedCookie implements Serializable {
private java.lang.String name;
private java.lang.String value;
private java.lang.String comment;
private java.lang.String domain;
private int maxAge;
private java.lang.String path;
private boolean secure;
private int version;
public SavedCookie(String name, String value, String comment, String domain, int maxAge, String path, boolean secure, int version) {
this.name = name;
this.value = value;
this.comment = comment;
this.domain = domain;
this.maxAge = maxAge;
this.path = path;
this.secure = secure;
this.version = version;
}
public SavedCookie(Cookie cookie) {
this(cookie.getName(), cookie.getValue(), cookie.getComment(),
cookie.getDomain(), cookie.getMaxAge(), cookie.getPath(), cookie.getSecure(), cookie.getVersion());
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
public String getComment() {
return comment;
}
public String getDomain() {
return domain;
}
public int getMaxAge() {
return maxAge;
}
public String getPath() {
return path;
}
public boolean isSecure() {
return secure;
}
public int getVersion() {
return version;
}
public Cookie getCookie() {
Cookie c = new Cookie(getName(), getValue());
if (getComment() != null)
c.setComment(getComment());
if (getDomain() != null)
c.setDomain(getDomain());
if (getPath() != null)
c.setPath(getPath());
c.setVersion(getVersion());
c.setMaxAge(getMaxAge());
c.setSecure(isSecure());
return c;
}
}

View File

@ -0,0 +1,63 @@
package org.acegisecurity.ui.savedrequest;
import junit.framework.TestCase;
import javax.servlet.http.Cookie;
public class SavedCookieTest extends TestCase {
Cookie cookie;
SavedCookie savedCookie;
protected void setUp() throws Exception {
cookie = new Cookie("name", "value");
cookie.setComment("comment");
cookie.setDomain("domain");
cookie.setMaxAge(100);
cookie.setPath("path");
cookie.setSecure(true);
cookie.setVersion(11);
savedCookie = new SavedCookie(cookie);
}
public void testGetName() throws Exception {
assertEquals(cookie.getName(), savedCookie.getName());
}
public void testGetValue() throws Exception {
assertEquals(cookie.getValue(), savedCookie.getValue());
}
public void testGetComment() throws Exception {
assertEquals(cookie.getComment(), savedCookie.getComment());
}
public void testGetDomain() throws Exception {
assertEquals(cookie.getDomain(), savedCookie.getDomain());
}
public void testGetMaxAge() throws Exception {
assertEquals(cookie.getMaxAge(), savedCookie.getMaxAge());
}
public void testGetPath() throws Exception {
assertEquals(cookie.getPath(), savedCookie.getPath());
}
public void testGetVersion() throws Exception {
assertEquals(cookie.getVersion(), savedCookie.getVersion());
}
public void testGetCookie() throws Exception {
Cookie other = savedCookie.getCookie();
assertEquals(cookie.getComment(), other.getComment());
assertEquals(cookie.getDomain(), other.getDomain());
assertEquals(cookie.getMaxAge(), other.getMaxAge());
assertEquals(cookie.getName(), other.getName());
assertEquals(cookie.getPath(), other.getPath());
assertEquals(cookie.getSecure(), other.getSecure());
assertEquals(cookie.getValue(), other.getValue());
assertEquals(cookie.getVersion(), other.getVersion());
}
}