1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License. You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied. See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.ws.security.common;
21  
22  import org.apache.ws.security.WSSecurityEngineResult;
23  import org.apache.ws.security.handler.WSHandler;
24  import org.apache.ws.security.handler.RequestData;
25  import org.w3c.dom.Document;
26  
27  import java.util.HashMap;
28  import java.util.List;
29  import java.util.Map;
30  
31  
32  /**
33   * A trivial extension of the WSHandler type for use in unit-testing.
34   */
35  public class CustomHandler extends WSHandler {
36      
37      private Map<String, Object> optionsMap = new HashMap<String, Object>();
38  
39      public Object 
40      getOption(String key) {
41          return optionsMap.get(key);
42      }
43      
44      public void
45      setOption(String key, Object option) {
46          optionsMap.put(key, option);
47      }
48  
49      @SuppressWarnings("unchecked")
50      public void 
51      setProperty(
52          Object ctx, 
53          String key, 
54          Object value
55      ) {
56          ((Map<String, Object>)ctx).put(key, value);
57      }
58  
59      public Object 
60      getProperty(Object ctx, String key) {
61          if (ctx instanceof Map<?,?>) {
62              return ((Map<?,?>)ctx).get(key);
63          }
64          return null;
65      }
66  
67      public void 
68      setPassword(Object msgContext, String password) {
69      }
70  
71      public String 
72      getPassword(Object msgContext) {
73          if (msgContext instanceof Map<?,?>) {
74              return (String)((Map<?,?>)msgContext).get("password");
75          }
76          return null;
77      }
78  
79      public void send(
80          int action, 
81          Document doc,
82          RequestData reqData, 
83          List<Integer> actions,
84          boolean request
85      ) throws org.apache.ws.security.WSSecurityException {
86          doSenderAction(
87              action, 
88              doc, 
89              reqData, 
90              actions,
91              request
92          );
93      }
94      
95      public void receive(
96          int action, 
97          RequestData reqData
98      ) throws org.apache.ws.security.WSSecurityException {
99          doReceiverAction(
100             action, 
101             reqData
102         );
103     }
104 
105     public void signatureConfirmation(
106         RequestData requestData,
107         List<WSSecurityEngineResult> results
108     ) throws org.apache.ws.security.WSSecurityException {
109         checkSignatureConfirmation(requestData, results);
110     }
111     
112     public boolean checkResults(
113         List<WSSecurityEngineResult> results,
114         List<Integer> actions
115     ) throws org.apache.ws.security.WSSecurityException {
116         return checkReceiverResults(results, actions);
117     }
118 
119     public boolean checkResultsAnyOrder(
120         List<WSSecurityEngineResult> results,
121         List<Integer> actions
122     ) throws org.apache.ws.security.WSSecurityException {
123         return checkReceiverResultsAnyOrder(results, actions);
124     }
125     
126     
127 }