Coverage Report - org.acegisecurity.ui.cas.CasProcessingFilterEntryPoint
 
Classes in this File Line Coverage Branch Coverage Complexity
CasProcessingFilterEntryPoint
100% 
100% 
1
 
 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.ui.cas;
 17  
 
 18  
 import java.io.IOException;
 19  
 import java.net.URLEncoder;
 20  
 
 21  
 import javax.servlet.ServletException;
 22  
 import javax.servlet.ServletRequest;
 23  
 import javax.servlet.ServletResponse;
 24  
 import javax.servlet.http.HttpServletRequest;
 25  
 import javax.servlet.http.HttpServletResponse;
 26  
 
 27  
 import org.acegisecurity.AuthenticationException;
 28  
 import org.acegisecurity.ui.AuthenticationEntryPoint;
 29  
 import org.springframework.beans.factory.InitializingBean;
 30  
 import org.springframework.util.Assert;
 31  
 
 32  
 
 33  
 /**
 34  
  * Used by the <code>SecurityEnforcementFilter</code> to commence authentication via the JA-SIG Central
 35  
  * Authentication Service (CAS).<P>The user's browser will be redirected to the JA-SIG CAS enterprise-wide login
 36  
  * page. This page is specified by the <code>loginUrl</code> property. Once login is complete, the CAS login page will
 37  
  * redirect to the page indicated by the <code>service</code> property. The <code>service</code> is a HTTP URL
 38  
  * belonging to the current application. The <code>service</code> URL is monitored by the {@link CasProcessingFilter},
 39  
  * which will validate the CAS login was successful.</p>
 40  
  *
 41  
  * @author Ben Alex
 42  
  * @version $Id: CasProcessingFilterEntryPoint.java 1948 2007-08-25 00:15:30Z benalex $
 43  
  */
 44  5
 public class CasProcessingFilterEntryPoint implements AuthenticationEntryPoint, InitializingBean {
 45  
     //~ Instance fields ================================================================================================
 46  
 
 47  
     private ServiceProperties serviceProperties;
 48  
     private String loginUrl;
 49  
 
 50  
     //~ Methods ========================================================================================================
 51  
 
 52  
         public void afterPropertiesSet() throws Exception {
 53  4
         Assert.hasLength(this.loginUrl, "loginUrl must be specified");
 54  3
         Assert.notNull(this.serviceProperties, "serviceProperties must be specified");
 55  2
     }
 56  
 
 57  
     public void commence(final ServletRequest servletRequest, final ServletResponse servletResponse,
 58  
         final AuthenticationException authenticationException)
 59  
         throws IOException, ServletException {
 60  2
         final HttpServletRequest request = (HttpServletRequest) servletRequest;
 61  2
         final HttpServletResponse response = (HttpServletResponse) servletResponse;
 62  2
         final String urlEncodedService = response.encodeURL(this.serviceProperties.getService());
 63  
 
 64  2
         final StringBuffer buffer = new StringBuffer(255);
 65  
 
 66  2
         synchronized (buffer) {
 67  2
             buffer.append(this.loginUrl);
 68  2
             buffer.append("?service=");
 69  2
             buffer.append(URLEncoder.encode(urlEncodedService, "UTF-8"));
 70  2
             buffer.append(this.serviceProperties.isSendRenew() ? "&renew=true" : "");
 71  2
         }
 72  
 
 73  2
         response.sendRedirect(buffer.toString());
 74  2
     }
 75  
 
 76  
     /**
 77  
      * The enterprise-wide CAS login URL. Usually something like
 78  
      * <code>https://www.mycompany.com/cas/login</code>.
 79  
      *
 80  
      * @return the enterprise-wide CAS login URL
 81  
      */
 82  
     public String getLoginUrl() {
 83  1
         return this.loginUrl;
 84  
     }
 85  
 
 86  
     public ServiceProperties getServiceProperties() {
 87  1
         return this.serviceProperties;
 88  
     }
 89  
 
 90  
     public void setLoginUrl(final String loginUrl) {
 91  4
         this.loginUrl = loginUrl;
 92  4
     }
 93  
 
 94  
     public void setServiceProperties(final ServiceProperties serviceProperties) {
 95  4
         this.serviceProperties = serviceProperties;
 96  4
     }
 97  
 }