mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-01 09:42:13 +00:00
work on unit test, still some functionality to cover later
This commit is contained in:
parent
2a46a975a5
commit
20025da7c7
@ -49,16 +49,16 @@ public class AuthenticationProcessingFilterEntryPoint
|
|||||||
*/
|
*/
|
||||||
private String loginFormUrl;
|
private String loginFormUrl;
|
||||||
|
|
||||||
private boolean forceSsl = false;
|
private boolean forceHttps = false;
|
||||||
|
|
||||||
private HashMap sslPortMapping;
|
private HashMap httpsPortMapping;
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
public AuthenticationProcessingFilterEntryPoint() {
|
public AuthenticationProcessingFilterEntryPoint() {
|
||||||
sslPortMapping = new HashMap();
|
httpsPortMapping = new HashMap();
|
||||||
sslPortMapping.put(new Integer(80), new Integer(443));
|
httpsPortMapping.put(new Integer(80), new Integer(443));
|
||||||
sslPortMapping.put(new Integer(8080), new Integer(8443));
|
httpsPortMapping.put(new Integer(8080), new Integer(8443));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoginFormUrl(String loginFormUrl) {
|
public void setLoginFormUrl(String loginFormUrl) {
|
||||||
@ -83,9 +83,9 @@ public class AuthenticationProcessingFilterEntryPoint
|
|||||||
|
|
||||||
String redirectUrl = contextPath + loginFormUrl;
|
String redirectUrl = contextPath + loginFormUrl;
|
||||||
|
|
||||||
if (forceSsl && req.getScheme().equals("http")) {
|
if (forceHttps && req.getScheme().equals("http")) {
|
||||||
Integer httpPort = new Integer(req.getServerPort());
|
Integer httpPort = new Integer(req.getServerPort());
|
||||||
Integer httpsPort = (Integer) sslPortMapping.get(httpPort);
|
Integer httpsPort = (Integer) httpsPortMapping.get(httpPort);
|
||||||
if (httpsPort != null ) {
|
if (httpsPort != null ) {
|
||||||
String serverName = req.getServerName();
|
String serverName = req.getServerName();
|
||||||
redirectUrl = "https://" + serverName + ":" + httpsPort + contextPath
|
redirectUrl = "https://" + serverName + ":" + httpsPort + contextPath
|
||||||
@ -96,35 +96,40 @@ public class AuthenticationProcessingFilterEntryPoint
|
|||||||
((HttpServletResponse) response).sendRedirect(redirectUrl);
|
((HttpServletResponse) response).sendRedirect(redirectUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setForceSsl(boolean forceSsl) {
|
public void setForceHttps(boolean forceSsl) {
|
||||||
this.forceSsl = forceSsl;
|
this.forceHttps = forceSsl;
|
||||||
}
|
}
|
||||||
public boolean isForceSsl() {
|
public boolean getForceHttps() {
|
||||||
return forceSsl;
|
return forceHttps;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws IllegalArgumentException if input map does not consist of String keys
|
* @throws IllegalArgumentException if input map does not consist of String keys
|
||||||
* and values, each representing an integer port number for one mapping.
|
* and values, each representing an integer port number for one mapping.
|
||||||
*/
|
*/
|
||||||
public void setSslPortMapping(HashMap sslPortMapping) {
|
public void setHttpsPortMapping(HashMap newMappings) {
|
||||||
this.sslPortMapping.clear();
|
httpsPortMapping.clear();
|
||||||
Iterator it = sslPortMapping.entrySet().iterator();
|
Iterator it = newMappings.entrySet().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Map.Entry entry = (Map.Entry) it.next();
|
Map.Entry entry = (Map.Entry) it.next();
|
||||||
Integer httpPort = new Integer((String)entry.getKey());
|
Integer httpPort = new Integer((String)entry.getKey());
|
||||||
Integer httpsPort = new Integer((String)entry.getKey());
|
Integer httpsPort = new Integer((String)entry.getValue());
|
||||||
if (httpPort.intValue() < 1 || httpPort.intValue() > 65535 ||
|
if (httpPort.intValue() < 1 || httpPort.intValue() > 65535 ||
|
||||||
httpsPort.intValue() < 1 || httpsPort.intValue() > 65535)
|
httpsPort.intValue() < 1 || httpsPort.intValue() > 65535)
|
||||||
throw new IllegalArgumentException("one or both ports out of legal range: "
|
throw new IllegalArgumentException("one or both ports out of legal range: "
|
||||||
+ httpPort + ", " + httpsPort);
|
+ httpPort + ", " + httpsPort);
|
||||||
sslPortMapping.put(httpPort, httpsPort);
|
httpsPortMapping.put(httpPort, httpsPort);
|
||||||
if (sslPortMapping.size() < 1)
|
if (httpsPortMapping.size() < 1)
|
||||||
throw new IllegalArgumentException("Must map at least one port");
|
throw new IllegalArgumentException("must map at least one port");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public HashMap getSslPortMapping() {
|
|
||||||
return sslPortMapping;
|
/**
|
||||||
|
* Returns the translated (Integer -> Integer) version of the original port
|
||||||
|
* mapping specified via setHttpsPortMapping()
|
||||||
|
*/
|
||||||
|
protected HashMap getTranslatedHttpsPortMapping() {
|
||||||
|
return httpsPortMapping;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
package net.sf.acegisecurity.ui.webapp;
|
package net.sf.acegisecurity.ui.webapp;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import net.sf.acegisecurity.MockHttpServletRequest;
|
import net.sf.acegisecurity.MockHttpServletRequest;
|
||||||
@ -28,15 +30,6 @@ import net.sf.acegisecurity.MockHttpServletResponse;
|
|||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class AuthenticationProcessingFilterEntryPointTests extends TestCase {
|
public class AuthenticationProcessingFilterEntryPointTests extends TestCase {
|
||||||
//~ Constructors ===========================================================
|
|
||||||
|
|
||||||
public AuthenticationProcessingFilterEntryPointTests() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public AuthenticationProcessingFilterEntryPointTests(String arg0) {
|
|
||||||
super(arg0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//~ Methods ================================================================
|
//~ Methods ================================================================
|
||||||
|
|
||||||
@ -64,6 +57,38 @@ public class AuthenticationProcessingFilterEntryPointTests extends TestCase {
|
|||||||
ep.setLoginFormUrl("/hello");
|
ep.setLoginFormUrl("/hello");
|
||||||
assertEquals("/hello", ep.getLoginFormUrl());
|
assertEquals("/hello", ep.getLoginFormUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSetSslPortMapping() {
|
||||||
|
AuthenticationProcessingFilterEntryPoint ep = new AuthenticationProcessingFilterEntryPoint();
|
||||||
|
HashMap map = new HashMap();
|
||||||
|
try {
|
||||||
|
ep.setHttpsPortMapping(map);
|
||||||
|
} catch (IllegalArgumentException expected) {
|
||||||
|
assertEquals("must map at least one port", expected.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
map.put(new Integer(0).toString(), new Integer(443).toString());
|
||||||
|
try {
|
||||||
|
ep.setHttpsPortMapping(map);
|
||||||
|
} catch (IllegalArgumentException expected) {
|
||||||
|
assertTrue(expected.getMessage().startsWith("one or both ports out of legal range"));
|
||||||
|
}
|
||||||
|
|
||||||
|
map.clear();
|
||||||
|
map.put(new Integer(80).toString(), new Integer(100000).toString());
|
||||||
|
try {
|
||||||
|
ep.setHttpsPortMapping(map);
|
||||||
|
} catch (IllegalArgumentException expected) {
|
||||||
|
assertTrue(expected.getMessage().startsWith("one or both ports out of legal range"));
|
||||||
|
}
|
||||||
|
|
||||||
|
map.clear();
|
||||||
|
map.put(new Integer(80).toString(), new Integer(443).toString());
|
||||||
|
ep.setHttpsPortMapping(map);
|
||||||
|
map = ep.getTranslatedHttpsPortMapping();
|
||||||
|
assertTrue(map.size() == 1);
|
||||||
|
assertTrue(((Integer)map.get(new Integer(80))).equals(new Integer(443)));
|
||||||
|
}
|
||||||
|
|
||||||
public void testNormalOperation() throws Exception {
|
public void testNormalOperation() throws Exception {
|
||||||
AuthenticationProcessingFilterEntryPoint ep = new AuthenticationProcessingFilterEntryPoint();
|
AuthenticationProcessingFilterEntryPoint ep = new AuthenticationProcessingFilterEntryPoint();
|
||||||
@ -79,4 +104,11 @@ public class AuthenticationProcessingFilterEntryPointTests extends TestCase {
|
|||||||
ep.commence(request, response);
|
ep.commence(request, response);
|
||||||
assertEquals("/bigWebApp/hello", response.getRedirect());
|
assertEquals("/bigWebApp/hello", response.getRedirect());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testHttpsOperation() throws Exception {
|
||||||
|
AuthenticationProcessingFilterEntryPoint ep = new AuthenticationProcessingFilterEntryPoint();
|
||||||
|
|
||||||
|
//TODO: finish later today
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user