KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > jaas > JaasCertificateCallbackHandler


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * 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, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.activemq.jaas;
20
21
22 import javax.security.auth.callback.Callback JavaDoc;
23 import javax.security.auth.callback.CallbackHandler JavaDoc;
24 import javax.security.auth.callback.NameCallback JavaDoc;
25 import javax.security.auth.callback.PasswordCallback JavaDoc;
26 import javax.security.auth.callback.UnsupportedCallbackException JavaDoc;
27
28 import java.io.IOException JavaDoc;
29 import java.security.cert.X509Certificate JavaDoc;
30
31 /**
32  * A Standard JAAS callback handler for SSL certificate requests.
33  *
34  * Will only handle callbacks of type CertificateCallback.
35  *
36  * @author sepandm@gmail.com (Sepand)
37  *
38  */

39 public class JaasCertificateCallbackHandler implements CallbackHandler JavaDoc {
40     final X509Certificate JavaDoc certificates[];
41     
42     /**
43      * Basic constructor.
44      *
45      * @param cert The certificate returned when calling back.
46      */

47     public JaasCertificateCallbackHandler(X509Certificate JavaDoc certs[]) {
48         certificates = certs;
49     }
50     
51     /**
52      * Overriding handle method to handle certificates.
53      *
54      * @param callbacks The callbacks requested.
55      * @throws IOException
56      * @throws UnsupportedCallbackException Thrown if an unkown Callback type is encountered.
57      */

58     public void handle(Callback JavaDoc[] callbacks) throws IOException JavaDoc, UnsupportedCallbackException JavaDoc {
59         for (int i = 0; i < callbacks.length; i++) {
60             Callback JavaDoc callback = callbacks[i];
61             if (callback instanceof CertificateCallback) {
62                 CertificateCallback certCallback = (CertificateCallback) callback;
63                 
64                 certCallback.setCertificates(certificates);
65                 
66             } else {
67                 throw new UnsupportedCallbackException JavaDoc(callback);
68             }
69         }
70     }
71 }
72
Popular Tags