Coverage Report - org.mule.extras.wssecurity.callbackhandlers.MuleWsSecurityCallbackHandler
 
Classes in this File Line Coverage Branch Coverage Complexity
MuleWsSecurityCallbackHandler
0%
0/13
0%
0/2
3
 
 1  
 /*
 2  
  * $Id: MuleWsSecurityCallbackHandler.java 7976 2007-08-21 14:26:13Z dirk.olmes $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.com
 5  
  *
 6  
  * The software in this package is published under the terms of the CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.extras.wssecurity.callbackhandlers;
 12  
 
 13  
 import org.mule.MuleException;
 14  
 import org.mule.MuleManager;
 15  
 import org.mule.config.i18n.CoreMessages;
 16  
 import org.mule.umo.manager.ObjectNotFoundException;
 17  
 
 18  
 import java.io.IOException;
 19  
 import java.util.Properties;
 20  
 
 21  
 import javax.security.auth.callback.Callback;
 22  
 import javax.security.auth.callback.CallbackHandler;
 23  
 import javax.security.auth.callback.UnsupportedCallbackException;
 24  
 
 25  
 import org.apache.ws.security.WSPasswordCallback;
 26  
 
 27  
 public class MuleWsSecurityCallbackHandler implements CallbackHandler
 28  
 {
 29  
     private Properties passwords;
 30  
 
 31  
     /**
 32  
      * This is the standard Mule callback handler that gets a set of passwords from
 33  
      * the configuration file.
 34  
      * 
 35  
      * @throws MuleException in case of any error
 36  
      */
 37  
     public MuleWsSecurityCallbackHandler() throws MuleException
 38  0
     {
 39  
         PasswordContainer pass;
 40  
         try
 41  
         {
 42  0
             pass = (PasswordContainer)MuleManager.getInstance().getContainerContext().getComponent(
 43  
                 "passwords");
 44  0
             passwords = pass.getPasswords();
 45  
         }
 46  0
         catch (ObjectNotFoundException e)
 47  
         {
 48  0
             throw new MuleException(CoreMessages.authNoCredentials(), e);
 49  0
         }
 50  0
     }
 51  
 
 52  
     /**
 53  
      * This method handles the callback, i.e. it checks whether the required password
 54  
      * is available
 55  
      */
 56  
     public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException
 57  
     {
 58  0
         for (int i = 0; i < callbacks.length; i++)
 59  
         {
 60  0
             WSPasswordCallback pc = (WSPasswordCallback)callbacks[i];
 61  
 
 62  0
             String pass = (String)passwords.get(pc.getIdentifer());
 63  0
             if (pass != null)
 64  
             {
 65  0
                 pc.setPassword(pass);
 66  
             }
 67  
         }
 68  0
     }
 69  
 }