001: /*************************************************************************
002: * *
003: * EJBCA: The OpenSource Certificate Authority *
004: * *
005: * This software is free software; you can redistribute it and/or *
006: * modify it under the terms of the GNU Lesser General Public *
007: * License as published by the Free Software Foundation; either *
008: * version 2.1 of the License, or any later version. *
009: * *
010: * See terms of license at gnu.org. *
011: * *
012: *************************************************************************/package org.ejbca.core.model.ca.publisher;
013:
014: import java.io.ByteArrayInputStream;
015: import java.io.IOException;
016: import java.security.cert.Certificate;
017: import java.util.HashMap;
018: import java.util.Iterator;
019: import java.util.Properties;
020:
021: import javax.ejb.EJBException;
022:
023: import org.ejbca.core.model.log.Admin;
024: import org.ejbca.core.model.ra.ExtendedInformation;
025:
026: /**
027: * CustomPublisherContainer is a class handling a custom publisher. It is used
028: * to store and retrieve custom publisher configuration to database.
029: *
030: *
031: * @version $Id: CustomPublisherContainer.java,v 1.4 2007/09/12 14:22:46 anatom Exp $
032: */
033: public class CustomPublisherContainer extends BasePublisher {
034: private ICustomPublisher custompublisher = null;
035:
036: public static final float LATEST_VERSION = 1;
037:
038: public static final int TYPE_CUSTOMPUBLISHERCONTAINER = 1;
039:
040: // Default Values
041:
042: protected static final String CLASSPATH = "classpath";
043: protected static final String PROPERTYDATA = "propertydata";
044:
045: public CustomPublisherContainer() {
046: super ();
047: data.put(TYPE, new Integer(TYPE_CUSTOMPUBLISHERCONTAINER));
048: setClassPath("");
049: setPropertyData("");
050: }
051:
052: // Public Methods
053: /**
054: * Returns the class path of custom publisher used.
055: */
056: public String getClassPath() {
057: return (String) data.get(CLASSPATH);
058: }
059:
060: /**
061: * Sets the class path of custom publisher used.
062: */
063: public void setClassPath(String classpath) {
064: data.put(CLASSPATH, classpath);
065: }
066:
067: /**
068: * Returns the propertydata used to configure this custom publisher.
069: */
070: public String getPropertyData() {
071: return (String) data.get(PROPERTYDATA);
072: }
073:
074: /**
075: * Sets the propertydata used to configure this custom publisher.
076: */
077: public void setPropertyData(String propertydata) {
078: data.put(PROPERTYDATA, propertydata);
079: }
080:
081: public Properties getProperties() throws IOException {
082: Properties prop = new Properties();
083: prop
084: .load(new ByteArrayInputStream(getPropertyData()
085: .getBytes()));
086: return prop;
087: }
088:
089: /**
090: * @see org.ejbca.core.model.ca.publisher.BasePublisher
091: */
092: public boolean storeCertificate(Admin admin, Certificate incert,
093: String username, String password, String cafp, int status,
094: int type, long revocationDate, int revocationReason,
095: ExtendedInformation extendedinformation)
096: throws PublisherException {
097: return this .getCustomPublisher().storeCertificate(admin,
098: incert, username, password, cafp, status, type,
099: revocationDate, revocationReason, extendedinformation);
100: }
101:
102: /**
103: * @see org.ejbca.core.model.ca.publisher.BasePublisher
104: */
105: public boolean storeCRL(Admin admin, byte[] incrl, String cafp,
106: int number) throws PublisherException {
107: return this .getCustomPublisher().storeCRL(admin, incrl, cafp,
108: number);
109: }
110:
111: /**
112: * @see org.ejbca.core.model.ca.publisher.BasePublisher
113: */
114: public void revokeCertificate(Admin admin, Certificate cert,
115: String username, int reason) throws PublisherException {
116: this .getCustomPublisher()
117: .revokeCertificate(admin, cert, reason);
118: }
119:
120: /**
121: * @see org.ejbca.core.model.ca.publisher.BasePublisher
122: */
123: public void testConnection(Admin admin)
124: throws PublisherConnectionException {
125: this .getCustomPublisher().testConnection(admin);
126: }
127:
128: // Private methods
129: private ICustomPublisher getCustomPublisher() {
130: if (custompublisher == null) {
131: try {
132: Class implClass = Class.forName(getClassPath());
133: Object obj = implClass.newInstance();
134: this .custompublisher = (ICustomPublisher) obj;
135: this .custompublisher.init(getProperties());
136: } catch (ClassNotFoundException e) {
137: throw new EJBException(e);
138: } catch (IllegalAccessException iae) {
139: throw new EJBException(iae);
140: } catch (IOException ioe) {
141: throw new EJBException(ioe);
142: } catch (InstantiationException ie) {
143: throw new EJBException(ie);
144: }
145: }
146:
147: return custompublisher;
148: }
149:
150: /**
151: * @see org.ejbca.core.model.ca.publisher.BasePublisher#clone()
152: */
153: public Object clone() throws CloneNotSupportedException {
154: CustomPublisherContainer clone = new CustomPublisherContainer();
155: HashMap clonedata = (HashMap) clone.saveData();
156:
157: Iterator i = (data.keySet()).iterator();
158: while (i.hasNext()) {
159: Object key = i.next();
160: clonedata.put(key, data.get(key));
161: }
162:
163: clone.loadData(clonedata);
164: return clone;
165: }
166:
167: /* *
168: * @see org.ejbca.core.model.ca.publisher.BasePublisher#getLatestVersion()
169: */
170: public float getLatestVersion() {
171: return LATEST_VERSION;
172: }
173:
174: /**
175: * Resets the current custom publisher
176: * @see org.ejbca.core.model.UpgradeableDataHashMap#saveData()
177: */
178: public Object saveData() {
179: this.custompublisher = null;
180: return super.saveData();
181: }
182:
183: }
|