Coverage Report - org.acegisecurity.util.PortResolverImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PortResolverImpl
100% 
100% 
2
 
 1  
 /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
 2  
  *
 3  
  * Licensed under the Apache License, Version 2.0 (the "License");
 4  
  * you may not use this file except in compliance with the License.
 5  
  * You may obtain a copy of the License at
 6  
  *
 7  
  *     http://www.apache.org/licenses/LICENSE-2.0
 8  
  *
 9  
  * Unless required by applicable law or agreed to in writing, software
 10  
  * distributed under the License is distributed on an "AS IS" BASIS,
 11  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
  * See the License for the specific language governing permissions and
 13  
  * limitations under the License.
 14  
  */
 15  
 
 16  
 package org.acegisecurity.util;
 17  
 
 18  
 import org.springframework.beans.factory.InitializingBean;
 19  
 
 20  
 import org.springframework.util.Assert;
 21  
 
 22  
 import javax.servlet.ServletRequest;
 23  
 
 24  
 
 25  
 /**
 26  
  * Concrete implementation of {@link PortResolver} that obtains the port from
 27  
  * <code>ServletRequest.getServerPort()</code>.<P>This class is capable of handling the IE bug which results in an
 28  
  * incorrect URL being presented in the header subsequent to a redirect to a different scheme and port where the port
 29  
  * is not a well-known number (ie 80 or 443). Handling involves detecting an incorrect response from
 30  
  * <code>ServletRequest.getServerPort()</code> for the scheme (eg a HTTP request on 8443) and then determining the
 31  
  * real server port (eg HTTP request is really on 8080). The map of valid ports is obtained from the configured {@link
 32  
  * PortMapper}.</p>
 33  
  *
 34  
  * @author Ben Alex
 35  
  * @version $Id: PortResolverImpl.java 1496 2006-05-23 13:38:33Z benalex $
 36  
  */
 37  75
 public class PortResolverImpl implements InitializingBean, PortResolver {
 38  
     //~ Instance fields ================================================================================================
 39  
 
 40  75
     private PortMapper portMapper = new PortMapperImpl();
 41  
 
 42  
     //~ Methods ========================================================================================================
 43  
 
 44  
     public void afterPropertiesSet() throws Exception {
 45  4
         Assert.notNull(portMapper, "portMapper required");
 46  3
     }
 47  
 
 48  
     public PortMapper getPortMapper() {
 49  2
         return portMapper;
 50  
     }
 51  
 
 52  
     public int getServerPort(ServletRequest request) {
 53  8
         int result = request.getServerPort();
 54  
 
 55  8
         if ("http".equals(request.getScheme().toLowerCase())) {
 56  6
             Integer http = portMapper.lookupHttpPort(new Integer(result));
 57  
 
 58  6
             if (http != null) {
 59  
                 // IE 6 bug
 60  1
                 result = http.intValue();
 61  
             }
 62  
         }
 63  
 
 64  8
         if ("https".equals(request.getScheme().toLowerCase())) {
 65  2
             Integer https = portMapper.lookupHttpsPort(new Integer(result));
 66  
 
 67  2
             if (https != null) {
 68  
                 // IE 6 bug
 69  1
                 result = https.intValue();
 70  
             }
 71  
         }
 72  
 
 73  8
         return result;
 74  
     }
 75  
 
 76  
     public void setPortMapper(PortMapper portMapper) {
 77  2
         this.portMapper = portMapper;
 78  2
     }
 79  
 }