KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > ca > helper > util > CAHelperUtils


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 package org.apache.geronimo.ca.helper.util;
19
20 import java.math.BigInteger JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Set JavaDoc;
23
24 import org.apache.geronimo.gbean.AbstractName;
25 import org.apache.geronimo.gbean.AbstractNameQuery;
26 import org.apache.geronimo.kernel.Kernel;
27 import org.apache.geronimo.kernel.KernelRegistry;
28 import org.apache.geronimo.management.geronimo.CertificateRequestStore;
29 import org.apache.geronimo.management.geronimo.CertificateStore;
30 import org.apache.geronimo.management.geronimo.SecureConnector;
31
32 /**
33  * This class implements some methods used by the CA Helper Application.
34  *
35  * @version $Rev: 476291 $ $Date: 2006-11-17 15:05:24 -0500 (Fri, 17 Nov 2006) $
36  */

37 public class CAHelperUtils {
38     /**
39      * This method removes a certificate request stored in the CertificateRequestStore.
40      * @param csrId Id of the CSR to be removed.
41      * @param sNo Serial number of the certificate issued in response to the CSR to be removed.
42      */

43     public static void removeRequest(String JavaDoc csrId, BigInteger JavaDoc sNo) {
44         getCertificateRequestStore().removeRequestStatus(csrId, sNo);
45     }
46     
47     /**
48      * This method returns the CertificateRequestStore.
49      */

50     public static CertificateRequestStore getCertificateRequestStore() {
51         Kernel kernel = KernelRegistry.getSingleKernel();
52         
53         AbstractNameQuery certReqStoreQuery = new AbstractNameQuery(org.apache.geronimo.management.geronimo.CertificateRequestStore.class.getName());
54         Set JavaDoc set = kernel.listGBeans(certReqStoreQuery);
55         try {
56             CertificateRequestStore certReqStore = (CertificateRequestStore)kernel.getGBean((AbstractName)set.iterator().next());
57             return certReqStore;
58         } catch (Exception JavaDoc e) {
59             e.printStackTrace();
60         }
61         return null;
62     }
63     
64     /**
65      * This method returns the CertificateStore.
66      */

67     public static CertificateStore getCertificateStore() {
68         Kernel kernel = KernelRegistry.getSingleKernel();
69         
70         AbstractNameQuery certStoreQuery = new AbstractNameQuery(org.apache.geronimo.management.geronimo.CertificateStore.class.getName());
71         Set JavaDoc set = kernel.listGBeans(certStoreQuery);
72         try {
73             CertificateStore certStore = (CertificateStore)kernel.getGBean((AbstractName)set.iterator().next());
74             return certStore;
75         } catch(Exception JavaDoc e) {
76             e.printStackTrace();
77         }
78         return null;
79     }
80
81     /**
82      * This method returns a port configured for HTTPS ClientAuthentication.
83      *
84      * @return Port configured for HTTPS Client Authentication.
85      * @return -1 if no HTTPS Client Authentication Connector is configured.
86      */

87     public static int getHttpsClientAuthPort() {
88         Kernel kernel = KernelRegistry.getSingleKernel();
89         
90         AbstractNameQuery connectorQuery = new AbstractNameQuery(SecureConnector.class.getName());
91         Set JavaDoc set = kernel.listGBeans(connectorQuery);
92         for(Iterator JavaDoc itr = set.iterator(); itr.hasNext(); ){
93             try {
94                 SecureConnector connector = (SecureConnector)kernel.getGBean((AbstractName)itr.next());
95                 if(connector.isClientAuthRequired())
96                     return connector.getPort();
97             } catch(Exception JavaDoc e) {
98                 e.printStackTrace();
99             }
100         }
101         return -1;
102     }
103 }
104
Popular Tags