1 13 14 package org.ejbca.core.model.ca.publisher; 15 16 import java.io.ByteArrayInputStream ; 17 import java.io.IOException ; 18 import java.security.cert.Certificate ; 19 import java.util.HashMap ; 20 import java.util.Iterator ; 21 import java.util.Properties ; 22 23 import javax.ejb.EJBException ; 24 25 import org.ejbca.core.model.log.Admin; 26 import org.ejbca.core.model.ra.ExtendedInformation; 27 28 29 30 37 public class CustomPublisherContainer extends BasePublisher{ 38 private ICustomPublisher custompublisher = null; 39 40 public static final float LATEST_VERSION = 1; 41 42 public static final int TYPE_CUSTOMPUBLISHERCONTAINER = 1; 43 44 46 protected static final String CLASSPATH = "classpath"; 47 protected static final String PROPERTYDATA = "propertydata"; 48 49 50 51 public CustomPublisherContainer(){ 52 super(); 53 data.put(TYPE, new Integer (TYPE_CUSTOMPUBLISHERCONTAINER)); 54 setClassPath(""); 55 setPropertyData(""); 56 } 57 58 62 public String getClassPath(){ 63 return (String ) data.get(CLASSPATH); 64 } 65 66 69 public void setClassPath(String classpath){ 70 data.put(CLASSPATH, classpath); 71 } 72 73 76 public String getPropertyData(){ 77 return (String ) data.get(PROPERTYDATA); 78 } 79 80 83 public void setPropertyData(String propertydata){ 84 data.put(PROPERTYDATA, propertydata); 85 } 86 87 public Properties getProperties() throws IOException { 88 Properties prop = new Properties (); 89 prop.load(new ByteArrayInputStream (getPropertyData().getBytes())); 90 return prop; 91 } 92 93 94 97 public boolean storeCertificate(Admin admin, Certificate incert, String username, String password, String cafp, int status, int type, long revocationDate, int revocationReason, ExtendedInformation extendedinformation) throws PublisherException{ 98 return this.getCustomPublisher().storeCertificate(admin,incert,username,password, cafp,status,type, revocationDate, revocationReason, extendedinformation); 99 } 100 101 104 public boolean storeCRL(Admin admin, byte[] incrl, String cafp, int number) throws PublisherException{ 105 return this.getCustomPublisher().storeCRL(admin,incrl,cafp,number); 106 } 107 108 111 public void revokeCertificate(Admin admin, Certificate cert, int reason) throws PublisherException{ 112 this.getCustomPublisher().revokeCertificate(admin,cert,reason); 113 } 114 115 118 public void testConnection(Admin admin) throws PublisherConnectionException{ 119 this.getCustomPublisher().testConnection(admin); 120 } 121 122 private ICustomPublisher getCustomPublisher() { 124 if(custompublisher == null){ 125 try{ 126 Class implClass = Class.forName( getClassPath() ); 127 Object obj = implClass.newInstance(); 128 this.custompublisher = (ICustomPublisher) obj; 129 this.custompublisher.init(getProperties()); 130 }catch(ClassNotFoundException e){ 131 throw new EJBException (e); 132 } 133 catch(IllegalAccessException iae){ 134 throw new EJBException (iae); 135 } 136 catch(IOException ioe){ 137 throw new EJBException (ioe); 138 } 139 catch(InstantiationException ie){ 140 throw new EJBException (ie); 141 } 142 } 143 144 return custompublisher; 145 } 146 147 150 public Object clone() throws CloneNotSupportedException { 151 CustomPublisherContainer clone = new CustomPublisherContainer(); 152 HashMap clonedata = (HashMap ) clone.saveData(); 153 154 Iterator i = (data.keySet()).iterator(); 155 while(i.hasNext()){ 156 Object key = i.next(); 157 clonedata.put(key, data.get(key)); 158 } 159 160 clone.loadData(clonedata); 161 return clone; 162 } 163 164 167 public float getLatestVersion() { 168 return LATEST_VERSION; 169 } 170 171 175 public Object saveData() { 176 this.custompublisher = null; 177 return super.saveData(); 178 } 179 180 181 } 182 | Popular Tags |