001: /**
002: *
003: * Licensed to the Apache Software Foundation (ASF) under one or more
004: * contributor license agreements. See the NOTICE file distributed with
005: * this work for additional information regarding copyright ownership.
006: * The ASF licenses this file to You under the Apache License, Version 2.0
007: * (the "License"); you may not use this file except in compliance with
008: * the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package org.apache.geronimo.ca.helper.util;
018:
019: import java.math.BigInteger;
020: import java.util.Iterator;
021: import java.util.Set;
022:
023: import org.apache.geronimo.gbean.AbstractName;
024: import org.apache.geronimo.gbean.AbstractNameQuery;
025: import org.apache.geronimo.kernel.Kernel;
026: import org.apache.geronimo.kernel.KernelRegistry;
027: import org.apache.geronimo.management.geronimo.CertificateRequestStore;
028: import org.apache.geronimo.management.geronimo.CertificateStore;
029: import org.apache.geronimo.management.geronimo.SecureConnector;
030:
031: /**
032: * This class implements some methods used by the CA Helper Application.
033: *
034: * @version $Rev: 514091 $ $Date: 2007-03-02 22:26:39 -0800 (Fri, 02 Mar 2007) $
035: */
036: public class CAHelperUtils {
037: /**
038: * This method removes a certificate request stored in the CertificateRequestStore.
039: * @param csrId Id of the CSR to be removed.
040: * @param sNo Serial number of the certificate issued in response to the CSR to be removed.
041: */
042: public static void removeRequest(String csrId, BigInteger sNo) {
043: getCertificateRequestStore().removeRequestStatus(csrId, sNo);
044: }
045:
046: /**
047: * This method returns the CertificateRequestStore.
048: */
049: public static CertificateRequestStore getCertificateRequestStore() {
050: Kernel kernel = KernelRegistry.getSingleKernel();
051:
052: AbstractNameQuery certReqStoreQuery = new AbstractNameQuery(
053: org.apache.geronimo.management.geronimo.CertificateRequestStore.class
054: .getName());
055: Set set = kernel.listGBeans(certReqStoreQuery);
056: try {
057: CertificateRequestStore certReqStore = (CertificateRequestStore) kernel
058: .getGBean((AbstractName) set.iterator().next());
059: return certReqStore;
060: } catch (Exception e) {
061: e.printStackTrace();
062: }
063: return null;
064: }
065:
066: /**
067: * This method returns the CertificateStore.
068: */
069: public static CertificateStore getCertificateStore() {
070: Kernel kernel = KernelRegistry.getSingleKernel();
071:
072: AbstractNameQuery certStoreQuery = new AbstractNameQuery(
073: org.apache.geronimo.management.geronimo.CertificateStore.class
074: .getName());
075: Set set = kernel.listGBeans(certStoreQuery);
076: try {
077: CertificateStore certStore = (CertificateStore) kernel
078: .getGBean((AbstractName) set.iterator().next());
079: return certStore;
080: } catch (Exception e) {
081: e.printStackTrace();
082: }
083: return null;
084: }
085:
086: /**
087: * This method returns a port configured for HTTPS ClientAuthentication.
088: *
089: * @return Port configured for HTTPS Client Authentication.
090: * @return -1 if no HTTPS Client Authentication Connector is configured.
091: */
092: public static int getHttpsClientAuthPort() {
093: Kernel kernel = KernelRegistry.getSingleKernel();
094:
095: AbstractNameQuery connectorQuery = new AbstractNameQuery(
096: SecureConnector.class.getName());
097: Set set = kernel.listGBeans(connectorQuery);
098: for (Iterator itr = set.iterator(); itr.hasNext();) {
099: try {
100: SecureConnector connector = (SecureConnector) kernel
101: .getGBean((AbstractName) itr.next());
102: if (connector.isClientAuthRequired())
103: return connector.getPort();
104: } catch (Exception e) {
105: e.printStackTrace();
106: }
107: }
108: return -1;
109: }
110: }
|