1 13 14 package org.ejbca.core.ejb.hardtoken; 15 16 import java.io.UnsupportedEncodingException ; 17 import java.util.HashMap ; 18 19 import javax.ejb.CreateException ; 20 import javax.ejb.EJBException ; 21 22 import org.apache.log4j.Logger; 23 import org.ejbca.core.ejb.BaseEntityBean; 24 import org.ejbca.core.model.hardtoken.profiles.EnhancedEIDProfile; 25 import org.ejbca.core.model.hardtoken.profiles.HardTokenProfile; 26 import org.ejbca.core.model.hardtoken.profiles.SwedishEIDProfile; 27 import org.ejbca.core.model.hardtoken.profiles.TurkishEIDProfile; 28 import org.ejbca.util.Base64GetHashMap; 29 import org.ejbca.util.Base64PutHashMap; 30 31 32 89 public abstract class HardTokenProfileDataBean extends BaseEntityBean { 90 91 private static final Logger log = Logger.getLogger(HardTokenProfileDataBean.class); 92 93 98 public abstract Integer getId(); 99 100 102 public abstract void setId(Integer id); 103 104 108 public abstract String getName(); 109 110 113 public abstract void setName(String name); 114 115 119 public abstract int getUpdateCounter(); 120 121 123 public abstract void setUpdateCounter(int updatecounter); 124 125 128 public abstract String getData(); 129 130 132 public abstract void setData(String data); 133 134 135 136 140 public HardTokenProfile getHardTokenProfile() { 141 142 HardTokenProfile profile = null; 143 java.beans.XMLDecoder decoder; 144 try { 145 decoder = new java.beans.XMLDecoder ( 146 new java.io.ByteArrayInputStream (getData().getBytes("UTF8"))); 147 } catch (UnsupportedEncodingException e) { 148 throw new EJBException (e); 149 } 150 HashMap h = (HashMap ) decoder.readObject(); 151 decoder.close(); 152 HashMap data = new Base64GetHashMap(h); 154 155 switch (((Integer ) (data.get(HardTokenProfile.TYPE))).intValue()) { 156 case SwedishEIDProfile.TYPE_SWEDISHEID : 157 profile = new SwedishEIDProfile(); 158 break; 159 case EnhancedEIDProfile.TYPE_ENHANCEDEID: 160 profile = new EnhancedEIDProfile(); 161 break; 162 case TurkishEIDProfile.TYPE_TURKISHEID : 163 profile = new TurkishEIDProfile(); 164 break; 165 } 166 167 profile.loadData(data); 168 169 return profile; 170 } 171 172 176 public void setHardTokenProfile(HardTokenProfile hardtokenprofile){ 177 HashMap a = new Base64PutHashMap(); 179 a.putAll((HashMap )hardtokenprofile.saveData()); 180 181 java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream (); 182 java.beans.XMLEncoder encoder = new java.beans.XMLEncoder (baos); 183 encoder.writeObject(a); 184 encoder.close(); 185 186 try { 187 if (log.isDebugEnabled()) { 188 log.debug("Profiledata: \n" + baos.toString("UTF8")); 189 } 190 setData(baos.toString("UTF8")); 191 } catch (UnsupportedEncodingException e) { 192 throw new EJBException (e); 193 } 194 195 setUpdateCounter(getUpdateCounter() +1); 196 } 197 198 199 203 204 210 public Integer ejbCreate(Integer id, String name, HardTokenProfile profile) throws CreateException { 211 setId(id); 212 setName(name); 213 this.setUpdateCounter(0); 214 if(profile != null) 215 setHardTokenProfile(profile); 216 217 log.debug("Created Hard Token Profile "+ name ); 218 return id; 219 } 220 221 public void ejbPostCreate(Integer id, String name, HardTokenProfile profile) { 222 } 224 } 225 | Popular Tags |