View Javadoc

1   /*
2    * Copyright 2006 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  
17  package org.springframework.ws.soap.security.xwss.callback;
18  
19  import java.io.IOException;
20  import javax.security.auth.callback.Callback;
21  import javax.security.auth.callback.UnsupportedCallbackException;
22  
23  import com.sun.xml.wss.impl.callback.CertificateValidationCallback;
24  import com.sun.xml.wss.impl.callback.DecryptionKeyCallback;
25  import com.sun.xml.wss.impl.callback.EncryptionKeyCallback;
26  import com.sun.xml.wss.impl.callback.SignatureKeyCallback;
27  import com.sun.xml.wss.impl.callback.SignatureVerificationKeyCallback;
28  
29  import org.springframework.ws.soap.security.callback.AbstractCallbackHandler;
30  
31  /**
32   * Default callback handler that handles cryptographic callback. This handler determines the exact callback passed, and
33   * calls a template method for it. By default, all template methods throw an <code>UnsupportedCallbackException</code>,
34   * so you only need to override those you need.
35   *
36   * @author Arjen Poutsma
37   * @since 1.0.0
38   */
39  public class CryptographyCallbackHandler extends AbstractCallbackHandler {
40  
41      protected final void handleInternal(Callback callback) throws IOException, UnsupportedCallbackException {
42          if (callback instanceof CertificateValidationCallback) {
43              handleCertificateValidationCallback((CertificateValidationCallback) callback);
44          }
45          else if (callback instanceof DecryptionKeyCallback) {
46              handleDecryptionKeyCallback((DecryptionKeyCallback) callback);
47          }
48          else if (callback instanceof EncryptionKeyCallback) {
49              handleEncryptionKeyCallback((EncryptionKeyCallback) callback);
50          }
51          else if (callback instanceof SignatureKeyCallback) {
52              handleSignatureKeyCallback((SignatureKeyCallback) callback);
53          }
54          else if (callback instanceof SignatureVerificationKeyCallback) {
55              handleSignatureVerificationKeyCallback((SignatureVerificationKeyCallback) callback);
56          }
57          else {
58              throw new UnsupportedCallbackException(callback);
59          }
60  
61      }
62  
63      //
64      // Certificate validation
65      //
66  
67      /**
68       * Template method that handles <code>CertificateValidationCallback</code>s. Called from
69       * <code>handleInternal()</code>. Default implementation throws an <code>UnsupportedCallbackException</code>.
70       */
71      protected void handleCertificateValidationCallback(CertificateValidationCallback callback)
72              throws IOException, UnsupportedCallbackException {
73          throw new UnsupportedCallbackException(callback);
74      }
75  
76      //
77      // Decryption
78      //
79  
80      /**
81       * Method that handles <code>DecryptionKeyCallback</code>s. Called from <code>handleInternal()</code>. Default
82       * implementation delegates to specific handling methods.
83       *
84       * @see #handlePrivateKeyRequest(com.sun.xml.wss.impl.callback.DecryptionKeyCallback,
85       *      com.sun.xml.wss.impl.callback.DecryptionKeyCallback.PrivateKeyRequest)
86       * @see #handleSymmetricKeyRequest(com.sun.xml.wss.impl.callback.DecryptionKeyCallback,
87       *      com.sun.xml.wss.impl.callback.DecryptionKeyCallback.SymmetricKeyRequest)
88       */
89      protected final void handleDecryptionKeyCallback(DecryptionKeyCallback callback)
90              throws IOException, UnsupportedCallbackException {
91          if (callback.getRequest() instanceof DecryptionKeyCallback.PrivateKeyRequest) {
92              handlePrivateKeyRequest(callback, (DecryptionKeyCallback.PrivateKeyRequest) callback.getRequest());
93          }
94          else if (callback.getRequest() instanceof DecryptionKeyCallback.SymmetricKeyRequest) {
95              handleSymmetricKeyRequest(callback, (DecryptionKeyCallback.SymmetricKeyRequest) callback.getRequest());
96          }
97          else {
98              throw new UnsupportedCallbackException(callback);
99          }
100     }
101 
102     /**
103      * Method that handles <code>DecryptionKeyCallback</code>s with <code>PrivateKeyRequest</code> . Called from
104      * <code>handleDecryptionKeyCallback()</code>. Default implementation delegates to specific handling methods.
105      *
106      * @see #handlePublicKeyBasedPrivKeyCertRequest(com.sun.xml.wss.impl.callback.SignatureKeyCallback,
107      *      com.sun.xml.wss.impl.callback.SignatureKeyCallback.PublicKeyBasedPrivKeyCertRequest)
108      * @see #handleX509CertificateBasedRequest(com.sun.xml.wss.impl.callback.DecryptionKeyCallback,
109      *      com.sun.xml.wss.impl.callback.DecryptionKeyCallback.X509CertificateBasedRequest)
110      * @see #handleX509IssuerSerialBasedRequest(com.sun.xml.wss.impl.callback.DecryptionKeyCallback,
111      *      com.sun.xml.wss.impl.callback.DecryptionKeyCallback.X509IssuerSerialBasedRequest)
112      * @see #handleX509SubjectKeyIdentifierBasedRequest(com.sun.xml.wss.impl.callback.DecryptionKeyCallback,
113      *      com.sun.xml.wss.impl.callback.DecryptionKeyCallback.X509SubjectKeyIdentifierBasedRequest)
114      */
115     protected final void handlePrivateKeyRequest(DecryptionKeyCallback callback,
116                                                  DecryptionKeyCallback.PrivateKeyRequest request)
117             throws IOException, UnsupportedCallbackException {
118         if (request instanceof DecryptionKeyCallback.PublicKeyBasedPrivKeyRequest) {
119             handlePublicKeyBasedPrivKeyRequest(callback, (DecryptionKeyCallback.PublicKeyBasedPrivKeyRequest) request);
120         }
121         else if (request instanceof DecryptionKeyCallback.X509CertificateBasedRequest) {
122             handleX509CertificateBasedRequest(callback, (DecryptionKeyCallback.X509CertificateBasedRequest) request);
123         }
124         else if (request instanceof DecryptionKeyCallback.X509IssuerSerialBasedRequest) {
125             handleX509IssuerSerialBasedRequest(callback, (DecryptionKeyCallback.X509IssuerSerialBasedRequest) request);
126         }
127         else if (request instanceof DecryptionKeyCallback.X509SubjectKeyIdentifierBasedRequest) {
128             handleX509SubjectKeyIdentifierBasedRequest(callback,
129                     (DecryptionKeyCallback.X509SubjectKeyIdentifierBasedRequest) request);
130         }
131         else {
132             throw new UnsupportedCallbackException(callback);
133         }
134     }
135 
136     /**
137      * Template method that handles <code>DecryptionKeyCallback</code>s with <code>PublicKeyBasedPrivKeyRequest</code>s.
138      * Called from <code>handlePrivateKeyRequest()</code>. Default implementation throws an
139      * <code>UnsupportedCallbackException</code>.
140      */
141     protected void handlePublicKeyBasedPrivKeyRequest(DecryptionKeyCallback callback,
142                                                       DecryptionKeyCallback.PublicKeyBasedPrivKeyRequest request)
143             throws IOException, UnsupportedCallbackException {
144         throw new UnsupportedCallbackException(callback);
145     }
146 
147     /**
148      * Template method that handles <code>DecryptionKeyCallback</code>s with <code>X509CertificateBasedRequest</code>s.
149      * Called from <code>handlePrivateKeyRequest()</code>. Default implementation throws an
150      * <code>UnsupportedCallbackException</code>.
151      */
152     protected void handleX509CertificateBasedRequest(DecryptionKeyCallback callback,
153                                                      DecryptionKeyCallback.X509CertificateBasedRequest request)
154             throws IOException, UnsupportedCallbackException {
155         throw new UnsupportedCallbackException(callback);
156     }
157 
158     /**
159      * Template method that handles <code>DecryptionKeyCallback</code>s with <code>X509IssuerSerialBasedRequest</code>s.
160      * Called from <code>handlePrivateKeyRequest()</code>. Default implementation throws an
161      * <code>UnsupportedCallbackException</code>.
162      */
163     protected void handleX509IssuerSerialBasedRequest(DecryptionKeyCallback callback,
164                                                       DecryptionKeyCallback.X509IssuerSerialBasedRequest request)
165             throws IOException, UnsupportedCallbackException {
166         throw new UnsupportedCallbackException(callback);
167     }
168 
169     /**
170      * Template method that handles <code>DecryptionKeyCallback</code>s with <code>X509SubjectKeyIdentifierBasedRequest</code>s.
171      * Called from <code>handlePrivateKeyRequest()</code>. Default implementation throws an
172      * <code>UnsupportedCallbackException</code>.
173      */
174     protected void handleX509SubjectKeyIdentifierBasedRequest(DecryptionKeyCallback callback,
175                                                               DecryptionKeyCallback.X509SubjectKeyIdentifierBasedRequest request)
176             throws IOException, UnsupportedCallbackException {
177         throw new UnsupportedCallbackException(callback);
178     }
179 
180     /**
181      * Method that handles <code>DecryptionKeyCallback</code>s with <code>SymmetricKeyRequest</code> . Called from
182      * <code>handleDecryptionKeyCallback()</code>. Default implementation delegates to specific handling methods.
183      *
184      * @see #handleAliasSymmetricKeyRequest(com.sun.xml.wss.impl.callback.DecryptionKeyCallback,
185      *      com.sun.xml.wss.impl.callback.DecryptionKeyCallback.AliasSymmetricKeyRequest)
186      */
187     protected final void handleSymmetricKeyRequest(DecryptionKeyCallback callback,
188                                                    DecryptionKeyCallback.SymmetricKeyRequest request)
189             throws IOException, UnsupportedCallbackException {
190         if (request instanceof DecryptionKeyCallback.AliasSymmetricKeyRequest) {
191             DecryptionKeyCallback.AliasSymmetricKeyRequest aliasSymmetricKeyRequest =
192                     (DecryptionKeyCallback.AliasSymmetricKeyRequest) request;
193             handleAliasSymmetricKeyRequest(callback, aliasSymmetricKeyRequest);
194         }
195         else {
196             throw new UnsupportedCallbackException(callback);
197         }
198     }
199 
200     /**
201      * Template method that handles <code>DecryptionKeyCallback</code>s with <code>AliasSymmetricKeyRequest</code>s.
202      * Called from <code>handleSymmetricKeyRequest()</code>. Default implementation throws an
203      * <code>UnsupportedCallbackException</code>.
204      */
205     protected void handleAliasSymmetricKeyRequest(DecryptionKeyCallback callback,
206                                                   DecryptionKeyCallback.AliasSymmetricKeyRequest request)
207             throws IOException, UnsupportedCallbackException {
208         throw new UnsupportedCallbackException(callback);
209     }
210 
211     //
212     // Encryption
213     //
214 
215     /**
216      * Method that handles <code>EncryptionKeyCallback</code>s. Called from <code>handleInternal()</code>. Default
217      * implementation delegates to specific handling methods.
218      *
219      * @see #handleSymmetricKeyRequest(com.sun.xml.wss.impl.callback.EncryptionKeyCallback,
220      *      com.sun.xml.wss.impl.callback.EncryptionKeyCallback.SymmetricKeyRequest)
221      * @see #handleX509CertificateRequest(com.sun.xml.wss.impl.callback.EncryptionKeyCallback,
222      *      com.sun.xml.wss.impl.callback.EncryptionKeyCallback.X509CertificateRequest)
223      */
224     protected final void handleEncryptionKeyCallback(EncryptionKeyCallback callback)
225             throws IOException, UnsupportedCallbackException {
226         if (callback.getRequest() instanceof EncryptionKeyCallback.SymmetricKeyRequest) {
227             handleSymmetricKeyRequest(callback, (EncryptionKeyCallback.SymmetricKeyRequest) callback.getRequest());
228         }
229         else if (callback.getRequest() instanceof EncryptionKeyCallback.X509CertificateRequest) {
230             handleX509CertificateRequest(callback,
231                     (EncryptionKeyCallback.X509CertificateRequest) callback.getRequest());
232         }
233         else {
234             throw new UnsupportedCallbackException(callback);
235 
236         }
237     }
238 
239     /**
240      * Method that handles <code>EncryptionKeyCallback</code>s with <code>SymmetricKeyRequest</code> . Called from
241      * <code>handleEncryptionKeyCallback()</code>. Default implementation delegates to specific handling methods.
242      *
243      * @see #handleAliasSymmetricKeyRequest(com.sun.xml.wss.impl.callback.EncryptionKeyCallback,
244      *      com.sun.xml.wss.impl.callback.EncryptionKeyCallback.AliasSymmetricKeyRequest)
245      */
246     protected final void handleSymmetricKeyRequest(EncryptionKeyCallback callback,
247                                                    EncryptionKeyCallback.SymmetricKeyRequest request)
248             throws IOException, UnsupportedCallbackException {
249         if (request instanceof EncryptionKeyCallback.AliasSymmetricKeyRequest) {
250             handleAliasSymmetricKeyRequest(callback, (EncryptionKeyCallback.AliasSymmetricKeyRequest) request);
251         }
252     }
253 
254     /**
255      * Template method that handles <code>EncryptionKeyCallback</code>s with <code>AliasSymmetricKeyRequest</code>s.
256      * Called from <code>handleSymmetricKeyRequest()</code>. Default implementation throws an
257      * <code>UnsupportedCallbackException</code>.
258      */
259     protected void handleAliasSymmetricKeyRequest(EncryptionKeyCallback callback,
260                                                   EncryptionKeyCallback.AliasSymmetricKeyRequest request)
261             throws IOException, UnsupportedCallbackException {
262         throw new UnsupportedCallbackException(callback);
263     }
264 
265     /**
266      * Method that handles <code>EncryptionKeyCallback</code>s with <code>X509CertificateRequest</code> . Called from
267      * <code>handleEncryptionKeyCallback()</code>. Default implementation delegates to specific handling methods.
268      *
269      * @see #handleAliasX509CertificateRequest(com.sun.xml.wss.impl.callback.EncryptionKeyCallback,
270      *      com.sun.xml.wss.impl.callback.EncryptionKeyCallback.AliasX509CertificateRequest)
271      * @see #handleDefaultX509CertificateRequest(com.sun.xml.wss.impl.callback.EncryptionKeyCallback,
272      *      com.sun.xml.wss.impl.callback.EncryptionKeyCallback.DefaultX509CertificateRequest)
273      * @see #handlePublicKeyBasedRequest(com.sun.xml.wss.impl.callback.EncryptionKeyCallback,
274      *      com.sun.xml.wss.impl.callback.EncryptionKeyCallback.PublicKeyBasedRequest)
275      */
276     protected final void handleX509CertificateRequest(EncryptionKeyCallback callback,
277                                                       EncryptionKeyCallback.X509CertificateRequest request)
278             throws IOException, UnsupportedCallbackException {
279         if (request instanceof EncryptionKeyCallback.AliasX509CertificateRequest) {
280             handleAliasX509CertificateRequest(callback, (EncryptionKeyCallback.AliasX509CertificateRequest) request);
281         }
282         else if (request instanceof EncryptionKeyCallback.DefaultX509CertificateRequest) {
283             handleDefaultX509CertificateRequest(callback,
284                     (EncryptionKeyCallback.DefaultX509CertificateRequest) request);
285         }
286         else if (request instanceof EncryptionKeyCallback.PublicKeyBasedRequest) {
287             handlePublicKeyBasedRequest(callback, (EncryptionKeyCallback.PublicKeyBasedRequest) request);
288         }
289         else {
290             throw new UnsupportedCallbackException(callback);
291         }
292     }
293 
294     /**
295      * Template method that handles <code>EncryptionKeyCallback</code>s with <code>AliasX509CertificateRequest</code>s.
296      * Called from <code>handleX509CertificateRequest()</code>. Default implementation throws an
297      * <code>UnsupportedCallbackException</code>.
298      */
299     protected void handleAliasX509CertificateRequest(EncryptionKeyCallback callback,
300                                                      EncryptionKeyCallback.AliasX509CertificateRequest request)
301             throws IOException, UnsupportedCallbackException {
302         throw new UnsupportedCallbackException(callback);
303     }
304 
305     /**
306      * Template method that handles <code>EncryptionKeyCallback</code>s with <code>DefaultX509CertificateRequest</code>s.
307      * Called from <code>handleX509CertificateRequest()</code>. Default implementation throws an
308      * <code>UnsupportedCallbackException</code>.
309      */
310     protected void handleDefaultX509CertificateRequest(EncryptionKeyCallback callback,
311                                                        EncryptionKeyCallback.DefaultX509CertificateRequest request)
312             throws IOException, UnsupportedCallbackException {
313         throw new UnsupportedCallbackException(callback);
314     }
315 
316     /**
317      * Template method that handles <code>EncryptionKeyCallback</code>s with <code>PublicKeyBasedRequest</code>s. Called
318      * from <code>handleX509CertificateRequest()</code>. Default implementation throws an
319      * <code>UnsupportedCallbackException</code>.
320      */
321     protected void handlePublicKeyBasedRequest(EncryptionKeyCallback callback,
322                                                EncryptionKeyCallback.PublicKeyBasedRequest request)
323             throws IOException, UnsupportedCallbackException {
324         throw new UnsupportedCallbackException(callback);
325     }
326 
327     //
328     // Signing
329     //
330 
331     /**
332      * Method that handles <code>SignatureKeyCallback</code>s. Called from <code>handleInternal()</code>. Default
333      * implementation delegates to specific handling methods.
334      *
335      * @see #handlePrivKeyCertRequest(com.sun.xml.wss.impl.callback.SignatureKeyCallback,
336      *      com.sun.xml.wss.impl.callback.SignatureKeyCallback.PrivKeyCertRequest)
337      */
338     protected final void handleSignatureKeyCallback(SignatureKeyCallback callback)
339             throws IOException, UnsupportedCallbackException {
340         if (callback.getRequest() instanceof SignatureKeyCallback.PrivKeyCertRequest) {
341             handlePrivKeyCertRequest(callback, (SignatureKeyCallback.PrivKeyCertRequest) callback.getRequest());
342         }
343         else {
344             throw new UnsupportedCallbackException(callback);
345         }
346     }
347 
348     /**
349      * Method that handles <code>SignatureKeyCallback</code>s with <code>PrivKeyCertRequest</code>s. Called from
350      * <code>handleSignatureKeyCallback()</code>. Default implementation delegates to specific handling methods.
351      *
352      * @see #handleDefaultPrivKeyCertRequest(com.sun.xml.wss.impl.callback.SignatureKeyCallback,
353      *      com.sun.xml.wss.impl.callback.SignatureKeyCallback.DefaultPrivKeyCertRequest)
354      * @see #handleAliasPrivKeyCertRequest(com.sun.xml.wss.impl.callback.SignatureKeyCallback,
355      *      com.sun.xml.wss.impl.callback.SignatureKeyCallback.AliasPrivKeyCertRequest)
356      * @see #handlePublicKeyBasedPrivKeyCertRequest(com.sun.xml.wss.impl.callback.SignatureKeyCallback,
357      *      com.sun.xml.wss.impl.callback.SignatureKeyCallback.PublicKeyBasedPrivKeyCertRequest)
358      */
359     protected final void handlePrivKeyCertRequest(SignatureKeyCallback cb,
360                                                   SignatureKeyCallback.PrivKeyCertRequest request)
361             throws IOException, UnsupportedCallbackException {
362         if (request instanceof SignatureKeyCallback.DefaultPrivKeyCertRequest) {
363             handleDefaultPrivKeyCertRequest(cb, (SignatureKeyCallback.DefaultPrivKeyCertRequest) request);
364         }
365         else if (cb.getRequest() instanceof SignatureKeyCallback.AliasPrivKeyCertRequest) {
366             handleAliasPrivKeyCertRequest(cb, (SignatureKeyCallback.AliasPrivKeyCertRequest) request);
367         }
368         else if (cb.getRequest() instanceof SignatureKeyCallback.PublicKeyBasedPrivKeyCertRequest) {
369             handlePublicKeyBasedPrivKeyCertRequest(cb, (SignatureKeyCallback.PublicKeyBasedPrivKeyCertRequest) request);
370         }
371         else {
372             throw new UnsupportedCallbackException(cb);
373         }
374     }
375 
376     /**
377      * Template method that handles <code>SignatureKeyCallback</code>s with <code>DefaultPrivKeyCertRequest</code>s.
378      * Called from <code>handlePrivKeyCertRequest()</code>. Default implementation throws an
379      * <code>UnsupportedCallbackException</code>.
380      */
381     protected void handleDefaultPrivKeyCertRequest(SignatureKeyCallback callback,
382                                                    SignatureKeyCallback.DefaultPrivKeyCertRequest request)
383             throws IOException, UnsupportedCallbackException {
384         throw new UnsupportedCallbackException(callback);
385     }
386 
387     /**
388      * Template method that handles <code>SignatureKeyCallback</code>s with <code>AliasPrivKeyCertRequest</code>s.
389      * Called from <code>handlePrivKeyCertRequest()</code>. Default implementation throws an
390      * <code>UnsupportedCallbackException</code>.
391      */
392     protected void handleAliasPrivKeyCertRequest(SignatureKeyCallback callback,
393                                                  SignatureKeyCallback.AliasPrivKeyCertRequest request)
394             throws IOException, UnsupportedCallbackException {
395         throw new UnsupportedCallbackException(callback);
396     }
397 
398     /**
399      * Template method that handles <code>SignatureKeyCallback</code>s with <code>PublicKeyBasedPrivKeyCertRequest</code>s.
400      * Called from <code>handlePrivKeyCertRequest()</code>. Default implementation throws an
401      * <code>UnsupportedCallbackException</code>.
402      */
403     protected void handlePublicKeyBasedPrivKeyCertRequest(SignatureKeyCallback callback,
404                                                           SignatureKeyCallback.PublicKeyBasedPrivKeyCertRequest request)
405             throws IOException, UnsupportedCallbackException {
406         throw new UnsupportedCallbackException(callback);
407     }
408 
409     //
410     // Signature verification
411     //
412 
413     /**
414      * Method that handles <code>SignatureVerificationKeyCallback</code>s. Called from <code>handleInternal()</code>.
415      * Default implementation delegates to specific handling methods.
416      *
417      * @see #handleX509CertificateRequest(com.sun.xml.wss.impl.callback.SignatureVerificationKeyCallback,
418      *      com.sun.xml.wss.impl.callback.SignatureVerificationKeyCallback.X509CertificateRequest)
419      */
420     protected final void handleSignatureVerificationKeyCallback(SignatureVerificationKeyCallback callback)
421             throws UnsupportedCallbackException, IOException {
422         if (callback.getRequest() instanceof SignatureVerificationKeyCallback.X509CertificateRequest) {
423             handleX509CertificateRequest(callback,
424                     (SignatureVerificationKeyCallback.X509CertificateRequest) callback.getRequest());
425         }
426         else {
427             throw new UnsupportedCallbackException(callback);
428         }
429     }
430 
431     /**
432      * Method that handles <code>SignatureVerificationKeyCallback</code>s with <code>X509CertificateRequest</code>s.
433      * Called from <code>handleSignatureVerificationKeyCallback()</code>. Default implementation delegates to specific
434      * handling methods.
435      *
436      * @see #handlePublicKeyBasedRequest(com.sun.xml.wss.impl.callback.SignatureVerificationKeyCallback,
437      *      com.sun.xml.wss.impl.callback.SignatureVerificationKeyCallback.PublicKeyBasedRequest)
438      * @see #handleX509IssuerSerialBasedRequest(com.sun.xml.wss.impl.callback.SignatureVerificationKeyCallback,
439      *      com.sun.xml.wss.impl.callback.SignatureVerificationKeyCallback.X509IssuerSerialBasedRequest)
440      * @see #handleX509SubjectKeyIdentifierBasedRequest(com.sun.xml.wss.impl.callback.SignatureVerificationKeyCallback,
441      *      com.sun.xml.wss.impl.callback.SignatureVerificationKeyCallback.X509SubjectKeyIdentifierBasedRequest)
442      */
443     protected final void handleX509CertificateRequest(SignatureVerificationKeyCallback callback,
444                                                       SignatureVerificationKeyCallback.X509CertificateRequest request)
445             throws UnsupportedCallbackException, IOException {
446         if (request instanceof SignatureVerificationKeyCallback.PublicKeyBasedRequest) {
447             handlePublicKeyBasedRequest(callback, (SignatureVerificationKeyCallback.PublicKeyBasedRequest) request);
448         }
449         else if (request instanceof SignatureVerificationKeyCallback.X509IssuerSerialBasedRequest) {
450             handleX509IssuerSerialBasedRequest(callback,
451                     (SignatureVerificationKeyCallback.X509IssuerSerialBasedRequest) request);
452         }
453         else if (request instanceof SignatureVerificationKeyCallback.X509SubjectKeyIdentifierBasedRequest) {
454             handleX509SubjectKeyIdentifierBasedRequest(callback,
455                     (SignatureVerificationKeyCallback.X509SubjectKeyIdentifierBasedRequest) request);
456         }
457         else {
458             throw new UnsupportedCallbackException(callback);
459         }
460     }
461 
462     /**
463      * Template method that handles <code>SignatureKeyCallback</code>s with <code>PublicKeyBasedPrivKeyCertRequest</code>s.
464      * Called from <code>handlePrivKeyCertRequest()</code>. Default implementation throws an
465      * <code>UnsupportedCallbackException</code>.
466      */
467     protected void handleX509SubjectKeyIdentifierBasedRequest(SignatureVerificationKeyCallback callback,
468                                                               SignatureVerificationKeyCallback.X509SubjectKeyIdentifierBasedRequest request)
469             throws IOException, UnsupportedCallbackException {
470         throw new UnsupportedCallbackException(callback);
471     }
472 
473     /**
474      * Template method that handles <code>SignatureKeyCallback</code>s with <code>X509IssuerSerialBasedRequest</code>s.
475      * Called from <code>handlePrivKeyCertRequest()</code>. Default implementation throws an
476      * <code>UnsupportedCallbackException</code>.
477      */
478     protected void handleX509IssuerSerialBasedRequest(SignatureVerificationKeyCallback callback,
479                                                       SignatureVerificationKeyCallback.X509IssuerSerialBasedRequest request)
480             throws IOException, UnsupportedCallbackException {
481         throw new UnsupportedCallbackException(callback);
482     }
483 
484     /**
485      * Template method that handles <code>SignatureKeyCallback</code>s with <code>PublicKeyBasedRequest</code>s. Called
486      * from <code>handlePrivKeyCertRequest()</code>. Default implementation throws an
487      * <code>UnsupportedCallbackException</code>.
488      */
489     protected void handlePublicKeyBasedRequest(SignatureVerificationKeyCallback callback,
490                                                SignatureVerificationKeyCallback.PublicKeyBasedRequest request)
491             throws IOException, UnsupportedCallbackException {
492         throw new UnsupportedCallbackException(callback);
493     }
494 }