1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.util;
17
18 import org.springframework.beans.factory.InitializingBean;
19 import org.springframework.util.Assert;
20
21 import javax.servlet.ServletRequest;
22
23
24 /***
25 * Concrete implementation of {@link PortResolver} that obtains the port from
26 * <code>ServletRequest.getServerPort()</code>.
27 *
28 * <P>
29 * This class is capable of handling the IE bug which results in an incorrect
30 * URL being presented in the header subsequent to a redirect to a different
31 * scheme and port where the port is not a well-known number (ie 80 or 443).
32 * Handling involves detecting an incorrect response from
33 * <code>ServletRequest.getServerPort()</code> for the scheme (eg a HTTP
34 * request on 8443) and then determining the real server port (eg HTTP request
35 * is really on 8080). The map of valid ports is obtained from the configured
36 * {@link PortMapper}.
37 * </p>
38 *
39 * @author Ben Alex
40 * @version $Id: PortResolverImpl.java,v 1.4 2005/11/17 00:56:09 benalex Exp $
41 */
42 public class PortResolverImpl implements InitializingBean, PortResolver {
43
44
45 private PortMapper portMapper = new PortMapperImpl();
46
47
48
49 public void setPortMapper(PortMapper portMapper) {
50 this.portMapper = portMapper;
51 }
52
53 public PortMapper getPortMapper() {
54 return portMapper;
55 }
56
57 public int getServerPort(ServletRequest request) {
58 int result = request.getServerPort();
59
60 if ("http".equals(request.getScheme().toLowerCase())) {
61 Integer http = portMapper.lookupHttpPort(new Integer(result));
62
63 if (http != null) {
64
65 result = http.intValue();
66 }
67 }
68
69 if ("https".equals(request.getScheme().toLowerCase())) {
70 Integer https = portMapper.lookupHttpsPort(new Integer(result));
71
72 if (https != null) {
73
74 result = https.intValue();
75 }
76 }
77
78 return result;
79 }
80
81 public void afterPropertiesSet() throws Exception {
82 Assert.notNull(portMapper, "portMapper required");
83 }
84 }