View Javadoc

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