View Javadoc
1   /*
2    * Copyright 2012 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.openehealth.ipf.platform.camel.ihe.xds;
17  
18  import org.apache.wss4j.common.ext.WSPasswordCallback;
19  
20  import javax.security.auth.callback.Callback;
21  import javax.security.auth.callback.CallbackHandler;
22  import javax.security.auth.callback.UnsupportedCallbackException;
23  import java.io.IOException;
24  
25  public class CommonCallbackHandler implements CallbackHandler {
26  
27      public void handle(Callback[] callbacks) throws IOException,
28              UnsupportedCallbackException {
29          for (Callback callback : callbacks) {
30              if (callback instanceof WSPasswordCallback) { // CXF
31                  WSPasswordCallback pc = (WSPasswordCallback) callback;
32                  if ("myclientkey".equals(pc.getIdentifier())) {
33                      pc.setPassword("ckpass");
34                      break;
35                  } else if ("myservicekey".equals(pc.getIdentifier())) {
36                      pc.setPassword("skpass");
37                      break;
38                  } else if ("alice".equals(pc.getIdentifier())) {
39                      pc.setPassword("clarinet");
40                      break;
41                  } else if ("bob".equals(pc.getIdentifier())) {
42                      pc.setPassword("trombone");
43                      break;
44                  } else if ("eve".equals(pc.getIdentifier())) {
45                      pc.setPassword("evekpass");
46                      break;
47                  } else if ("mystskey".equals(pc.getIdentifier())) {
48                      pc.setPassword("stskpass");
49                      break;
50                  }
51              }
52          }
53      }
54  }