| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.acegisecurity.securechannel; |
| 17 |
|
|
| 18 |
|
import org.acegisecurity.util.PortMapper; |
| 19 |
|
import org.acegisecurity.util.PortMapperImpl; |
| 20 |
|
import org.acegisecurity.util.PortResolver; |
| 21 |
|
import org.acegisecurity.util.PortResolverImpl; |
| 22 |
|
|
| 23 |
|
import org.apache.commons.logging.Log; |
| 24 |
|
import org.apache.commons.logging.LogFactory; |
| 25 |
|
|
| 26 |
|
import org.springframework.beans.factory.InitializingBean; |
| 27 |
|
|
| 28 |
|
import org.springframework.util.Assert; |
| 29 |
|
|
| 30 |
|
import java.io.IOException; |
| 31 |
|
|
| 32 |
|
import javax.servlet.ServletException; |
| 33 |
|
import javax.servlet.ServletRequest; |
| 34 |
|
import javax.servlet.ServletResponse; |
| 35 |
|
import javax.servlet.http.HttpServletRequest; |
| 36 |
|
import javax.servlet.http.HttpServletResponse; |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
|
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
14 |
public class RetryWithHttpEntryPoint implements InitializingBean, ChannelEntryPoint { |
| 48 |
|
|
| 49 |
|
|
| 50 |
2 |
private static final Log logger = LogFactory.getLog(RetryWithHttpEntryPoint.class); |
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
14 |
private PortMapper portMapper = new PortMapperImpl(); |
| 55 |
14 |
private PortResolver portResolver = new PortResolverImpl(); |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
public void afterPropertiesSet() throws Exception { |
| 60 |
6 |
Assert.notNull(portMapper, "portMapper is required"); |
| 61 |
5 |
Assert.notNull(portResolver, "portResolver is required"); |
| 62 |
4 |
} |
| 63 |
|
|
| 64 |
|
public void commence(ServletRequest request, ServletResponse response) |
| 65 |
|
throws IOException, ServletException { |
| 66 |
5 |
HttpServletRequest req = (HttpServletRequest) request; |
| 67 |
|
|
| 68 |
5 |
String pathInfo = req.getPathInfo(); |
| 69 |
5 |
String queryString = req.getQueryString(); |
| 70 |
5 |
String contextPath = req.getContextPath(); |
| 71 |
5 |
String destination = req.getServletPath() + ((pathInfo == null) ? "" : pathInfo) |
| 72 |
|
+ ((queryString == null) ? "" : ("?" + queryString)); |
| 73 |
|
|
| 74 |
5 |
String redirectUrl = contextPath; |
| 75 |
|
|
| 76 |
5 |
Integer httpsPort = new Integer(portResolver.getServerPort(req)); |
| 77 |
5 |
Integer httpPort = portMapper.lookupHttpPort(httpsPort); |
| 78 |
|
|
| 79 |
5 |
if (httpPort != null) { |
| 80 |
4 |
boolean includePort = true; |
| 81 |
|
|
| 82 |
4 |
if (httpPort.intValue() == 80) { |
| 83 |
2 |
includePort = false; |
| 84 |
|
} |
| 85 |
|
|
| 86 |
4 |
redirectUrl = "http://" + req.getServerName() + ((includePort) ? (":" + httpPort) : "") + contextPath |
| 87 |
|
+ destination; |
| 88 |
|
} |
| 89 |
|
|
| 90 |
5 |
if (logger.isDebugEnabled()) { |
| 91 |
0 |
logger.debug("Redirecting to: " + redirectUrl); |
| 92 |
|
} |
| 93 |
|
|
| 94 |
5 |
((HttpServletResponse) response).sendRedirect(((HttpServletResponse) response).encodeRedirectURL(redirectUrl)); |
| 95 |
5 |
} |
| 96 |
|
|
| 97 |
|
public PortMapper getPortMapper() { |
| 98 |
1 |
return portMapper; |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
public PortResolver getPortResolver() { |
| 102 |
1 |
return portResolver; |
| 103 |
|
} |
| 104 |
|
|
| 105 |
|
public void setPortMapper(PortMapper portMapper) { |
| 106 |
6 |
this.portMapper = portMapper; |
| 107 |
6 |
} |
| 108 |
|
|
| 109 |
|
public void setPortResolver(PortResolver portResolver) { |
| 110 |
6 |
this.portResolver = portResolver; |
| 111 |
6 |
} |
| 112 |
|
} |