Coverage Report - org.acegisecurity.providers.jaas.JaasPasswordCallbackHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
JaasPasswordCallbackHandler
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.providers.jaas;
 17  
 
 18  
 import org.acegisecurity.Authentication;
 19  
 
 20  
 import java.io.IOException;
 21  
 
 22  
 import javax.security.auth.callback.Callback;
 23  
 import javax.security.auth.callback.PasswordCallback;
 24  
 import javax.security.auth.callback.UnsupportedCallbackException;
 25  
 
 26  
 
 27  
 /**
 28  
  * The most basic Callbacks to be handled when using a LoginContext from JAAS, are the NameCallback and
 29  
  * PasswordCallback. The acegi security framework provides the JaasPasswordCallbackHandler specifically tailored to
 30  
  * handling the PasswordCallback. <br>
 31  
  *
 32  
  * @author Ray Krueger
 33  
  * @version $Id: JaasPasswordCallbackHandler.java 1784 2007-02-24 21:00:24Z luke_t $
 34  
  *
 35  
  * @see <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/security/auth/callback/Callback.html">Callback</a>
 36  
  * @see <a href="http://java.sun.com/j2se/1.4.2/docs/api/javax/security/auth/callback/PasswordCallback.html">
 37  
  *         PasswordCallback</a>
 38  
  */
 39  12
 public class JaasPasswordCallbackHandler implements JaasAuthenticationCallbackHandler {
 40  
     //~ Methods ========================================================================================================
 41  
 
 42  
     /**
 43  
      * If the callback passed to the 'handle' method is an instance of PasswordCallback, the
 44  
      * JaasPasswordCallbackHandler will call, callback.setPassword(authentication.getCredentials().toString()).
 45  
      *
 46  
      * @param callback
 47  
      * @param auth
 48  
      *
 49  
      * @throws IOException
 50  
      * @throws UnsupportedCallbackException
 51  
      */
 52  
     public void handle(Callback callback, Authentication auth)
 53  
         throws IOException, UnsupportedCallbackException {
 54  18
         if (callback instanceof PasswordCallback) {
 55  6
             PasswordCallback pc = (PasswordCallback) callback;
 56  6
             pc.setPassword(auth.getCredentials().toString().toCharArray());
 57  
         }
 58  18
     }
 59  
 }