Clover coverage report - Acegi Security System for Spring - CAS adapter - 1.0.0-RC1
Coverage timestamp: Mon Dec 5 2005 09:07:29 EST
file stats: LOC: 116   Methods: 4
NCLOC: 52   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
CasPasswordHandler.java 80% 88.9% 100% 87.5%
coverage coverage
 1    /* Copyright 2004 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.adapters.cas;
 17   
 18    import org.acegisecurity.Authentication;
 19    import org.acegisecurity.AuthenticationException;
 20    import org.acegisecurity.AuthenticationManager;
 21    import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
 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 javax.servlet.ServletRequest;
 29   
 30   
 31    /**
 32    * Provides actual CAS authentication by delegation to an
 33    * <code>AuthenticationManager</code>.
 34    *
 35    * <P>
 36    * Do not use this class directly. Instead configure CAS to use the {@link
 37    * CasPasswordHandlerProxy}.
 38    * </p>
 39    *
 40    * @author Ben Alex
 41    * @version $Id: CasPasswordHandler.java,v 1.2 2005/11/17 00:56:28 benalex Exp $
 42    */
 43    public final class CasPasswordHandler implements InitializingBean {
 44    //~ Static fields/initializers =============================================
 45   
 46    private static final Log logger = LogFactory.getLog(CasPasswordHandler.class);
 47   
 48    //~ Instance fields ========================================================
 49   
 50    private AuthenticationManager authenticationManager;
 51   
 52    //~ Methods ================================================================
 53   
 54  6 public void setAuthenticationManager(
 55    AuthenticationManager authenticationManager) {
 56  6 this.authenticationManager = authenticationManager;
 57    }
 58   
 59  1 public AuthenticationManager getAuthenticationManager() {
 60  1 return authenticationManager;
 61    }
 62   
 63  6 public void afterPropertiesSet() throws Exception {
 64  6 if (this.authenticationManager == null) {
 65  1 throw new IllegalArgumentException(
 66    "An AuthenticationManager is required");
 67    }
 68    }
 69   
 70    /**
 71    * Called by <code>CasPasswordHandlerProxy</code> for individual
 72    * authentication requests.
 73    *
 74    * <P>
 75    * Delegates to the configured <code>AuthenticationManager</code>.
 76    * </p>
 77    *
 78    * @param servletRequest as provided by CAS
 79    * @param username provided to CAS
 80    * @param password provided to CAS
 81    *
 82    * @return whether authentication was successful or not
 83    */
 84  9 public boolean authenticate(ServletRequest servletRequest, String username,
 85    String password) {
 86  9 if ((username == null) || "".equals(username)) {
 87  2 return false;
 88    }
 89   
 90  7 if (password == null) {
 91  1 password = "";
 92    }
 93   
 94  7 Authentication request = new UsernamePasswordAuthenticationToken(username
 95    .toString(), password.toString());
 96  7 Authentication response = null;
 97   
 98  7 try {
 99  7 response = authenticationManager.authenticate(request);
 100    } catch (AuthenticationException failed) {
 101  3 if (logger.isDebugEnabled()) {
 102  0 logger.debug("Authentication request for user: " + username
 103    + " failed: " + failed.toString());
 104    }
 105   
 106  3 return false;
 107    }
 108   
 109  4 if (logger.isDebugEnabled()) {
 110  0 logger.debug("Authentication request for user: " + username
 111    + " successful");
 112    }
 113   
 114  4 return true;
 115    }
 116    }