View Javadoc
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.wss4j.dom.common;
21  
22  import org.apache.wss4j.common.ext.WSSecurityException;
23  import org.apache.wss4j.dom.engine.WSSecurityEngineResult;
24  import org.apache.wss4j.dom.handler.HandlerAction;
25  import org.apache.wss4j.dom.handler.WSHandler;
26  import org.apache.wss4j.dom.handler.RequestData;
27  import org.apache.wss4j.dom.handler.WSHandlerResult;
28  import org.w3c.dom.Document;
29  
30  import java.util.HashMap;
31  import java.util.List;
32  import java.util.Map;
33  
34  
35  /**
36   * A trivial extension of the WSHandler type for use in unit-testing.
37   */
38  public class CustomHandler extends WSHandler {
39  
40      private Map<String, Object> optionsMap = new HashMap<>();
41  
42      public Object
43      getOption(String key) {
44          return optionsMap.get(key);
45      }
46  
47      public void
48      setOption(String key, Object option) {
49          optionsMap.put(key, option);
50      }
51  
52      @SuppressWarnings("unchecked")
53      public void
54      setProperty(
55          Object ctx,
56          String key,
57          Object value
58      ) {
59          ((Map<String, Object>)ctx).put(key, value);
60      }
61  
62      public Object
63      getProperty(Object ctx, String key) {
64          if (ctx instanceof Map<?,?>) {
65              return ((Map<?,?>)ctx).get(key);
66          }
67          return null;
68      }
69  
70      public void
71      setPassword(Object msgContext, String password) {
72      }
73  
74      public String
75      getPassword(Object msgContext) {
76          if (msgContext instanceof Map<?,?>) {
77              return (String)((Map<?,?>)msgContext).get("password");
78          }
79          return null;
80      }
81  
82      public void send(
83          Document doc,
84          RequestData reqData,
85          List<HandlerAction> actions,
86          boolean request
87      ) throws WSSecurityException {
88          doSenderAction(
89              doc,
90              reqData,
91              actions,
92              request
93          );
94      }
95  
96      public void receive(
97          List<Integer> actions,
98          RequestData reqData
99      ) throws WSSecurityException {
100         doReceiverAction(
101             actions,
102             reqData
103         );
104     }
105 
106     public void signatureConfirmation(
107         RequestData requestData,
108         WSHandlerResult handlerResults
109     ) throws WSSecurityException {
110         checkSignatureConfirmation(requestData, handlerResults);
111     }
112 
113     public boolean checkResults(
114         List<WSSecurityEngineResult> results,
115         List<Integer> actions
116     ) throws WSSecurityException {
117         return checkReceiverResults(results, actions);
118     }
119 
120     public boolean checkResultsAnyOrder(
121         List<WSSecurityEngineResult> results,
122         List<Integer> actions
123     ) throws WSSecurityException {
124         return checkReceiverResultsAnyOrder(results, actions);
125     }
126 
127 
128 }