View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.cxf.wssec;
8   
9   import java.io.IOException;
10  
11  import javax.security.auth.callback.Callback;
12  import javax.security.auth.callback.CallbackHandler;
13  import javax.security.auth.callback.UnsupportedCallbackException;
14  
15  import org.apache.ws.security.WSPasswordCallback;
16  
17  /**
18   * This callback simply supplies the password so that it's not stored in our config file.
19   * You will need to call 
20   *   ClientPasswordCallback.setPassword("password"); 
21   * from your code before invoking the secure service.
22   */
23  public class ClientPasswordCallback implements CallbackHandler
24  {
25      private static String password;
26      
27      public static void setPassword(String password)
28      {
29          ClientPasswordCallback.password = password;
30      }
31  
32      public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException 
33      {
34          WSPasswordCallback pc = (WSPasswordCallback) callbacks[0];
35  
36          // set the password for our message.
37          pc.setPassword(password);
38      }
39  }
40  
41