Clover coverage report - Acegi Security System for Spring - 1.0.0-RC1
Coverage timestamp: Mon Dec 5 2005 09:05:15 EST
file stats: LOC: 75   Methods: 1
NCLOC: 24   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
JaasNameCallbackHandler.java 75% 87.5% 100% 84.6%
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.providers.jaas;
 17   
 18    import org.acegisecurity.Authentication;
 19    import org.acegisecurity.userdetails.UserDetails;
 20   
 21    import java.io.IOException;
 22   
 23    import javax.security.auth.callback.Callback;
 24    import javax.security.auth.callback.NameCallback;
 25    import javax.security.auth.callback.UnsupportedCallbackException;
 26   
 27   
 28    /**
 29    * The most basic Callbacks to be handled when using a LoginContext from JAAS,
 30    * are the NameCallback and PasswordCallback. The acegi security framework
 31    * provides the JaasNameCallbackHandler specifically tailored to handling the
 32    * NameCallback. <br>
 33    *
 34    * @author Ray Krueger
 35    * @version $Id: JaasNameCallbackHandler.java,v 1.6 2005/11/29 13:10:08 benalex Exp $
 36    *
 37    * @see <a
 38    * href="http://java.sun.com/j2se/1.4.2/docs/api/javax/security/auth/callback/Callback.html">Callback</a>
 39    * @see <a
 40    * href="http://java.sun.com/j2se/1.4.2/docs/api/javax/security/auth/callback/NameCallback.html">NameCallback</a>
 41    */
 42    public class JaasNameCallbackHandler
 43    implements JaasAuthenticationCallbackHandler {
 44    //~ Methods ================================================================
 45   
 46    /**
 47    * If the callback passed to the 'handle' method is an instance of
 48    * NameCallback, the JaasNameCallbackHandler will call,
 49    * callback.setName(authentication.getPrincipal().toString()).
 50    *
 51    * @param callback
 52    * @param authentication
 53    *
 54    * @throws IOException
 55    * @throws UnsupportedCallbackException
 56    */
 57  18 public void handle(Callback callback, Authentication authentication)
 58    throws IOException, UnsupportedCallbackException {
 59   
 60  18 if (callback instanceof NameCallback) {
 61   
 62  6 NameCallback ncb = (NameCallback) callback;
 63  6 String username = "";
 64   
 65  6 Object principal = authentication.getPrincipal();
 66  6 if (principal instanceof UserDetails) {
 67  0 username = ((UserDetails) principal).getUsername();
 68    } else {
 69  6 username = principal.toString();
 70    }
 71   
 72  6 ncb.setName(username);
 73    }
 74    }
 75    }