1 13 14 package se.anatom.ejbca.hardtoken; 15 16 import java.util.Arrays ; 17 18 import javax.naming.Context ; 19 import javax.naming.NamingException ; 20 21 import junit.framework.TestCase; 22 23 import org.apache.log4j.Logger; 24 import org.ejbca.core.ejb.hardtoken.IHardTokenSessionHome; 25 import org.ejbca.core.ejb.hardtoken.IHardTokenSessionRemote; 26 import org.ejbca.core.model.hardtoken.HardTokenProfileExistsException; 27 import org.ejbca.core.model.hardtoken.profiles.EnhancedEIDProfile; 28 import org.ejbca.core.model.hardtoken.profiles.HardTokenProfile; 29 import org.ejbca.core.model.hardtoken.profiles.SwedishEIDProfile; 30 import org.ejbca.core.model.hardtoken.profiles.TurkishEIDProfile; 31 import org.ejbca.core.model.log.Admin; 32 import org.ejbca.util.CertTools; 33 34 35 40 public class TestHardTokenProfile extends TestCase { 41 private static Logger log = Logger.getLogger(TestHardTokenProfile.class); 42 private IHardTokenSessionRemote cacheAdmin; 43 44 private static int SVGFILESIZE = 512 * 1024; 46 47 private static IHardTokenSessionHome cacheHome; 48 49 private static final Admin admin = new Admin(Admin.TYPE_INTERNALUSER); 50 51 56 public TestHardTokenProfile(String name) { 57 super(name); 58 } 59 60 protected void setUp() throws Exception { 61 62 log.debug(">setUp()"); 63 CertTools.installBCProvider(); 64 65 if (cacheAdmin == null) { 66 if (cacheHome == null) { 67 Context jndiContext = getInitialContext(); 68 Object obj1 = jndiContext.lookup("HardTokenSession"); 69 cacheHome = (IHardTokenSessionHome) javax.rmi.PortableRemoteObject.narrow(obj1, IHardTokenSessionHome.class); 70 71 } 72 73 cacheAdmin = cacheHome.create(); 74 } 75 76 77 log.debug("<setUp()"); 78 } 79 80 protected void tearDown() throws Exception { 81 } 82 83 private Context getInitialContext() throws NamingException { 84 log.debug(">getInitialContext"); 85 86 Context ctx = new javax.naming.InitialContext (); 87 log.debug("<getInitialContext"); 88 89 return ctx; 90 } 91 92 93 98 public void test01AddHardTokenProfile() throws Exception { 99 log.debug(">test01AddHardTokenProfile()"); 100 boolean ret = false; 101 try { 102 SwedishEIDProfile profile = new SwedishEIDProfile(); 103 EnhancedEIDProfile profile2 = new EnhancedEIDProfile(); 104 TurkishEIDProfile turprofile = new TurkishEIDProfile(); 105 106 107 String svgdata = createSVGData(); 108 profile.setPINEnvelopeData(svgdata); 109 profile2.setIsKeyRecoverable(EnhancedEIDProfile.CERTUSAGE_ENC, true); 110 111 112 cacheAdmin.addHardTokenProfile(admin, "SWETEST", profile); 113 cacheAdmin.addHardTokenProfile(admin, "ENHTEST", profile2); 114 cacheAdmin.addHardTokenProfile(admin, "TURTEST", turprofile); 115 116 SwedishEIDProfile profile3 = (SwedishEIDProfile) cacheAdmin.getHardTokenProfile(admin, "SWETEST"); 117 EnhancedEIDProfile profile4 = (EnhancedEIDProfile) cacheAdmin.getHardTokenProfile(admin, "ENHTEST"); 118 TurkishEIDProfile turprofile2 = (TurkishEIDProfile) cacheAdmin.getHardTokenProfile(admin, "TURTEST"); 119 120 String svgdata2 = profile3.getPINEnvelopeData(); 121 122 assertTrue("Saving SVG Data failed", svgdata.equals(svgdata2)); 123 assertTrue("Saving Hard Token Profile failed", profile4.getIsKeyRecoverable(EnhancedEIDProfile.CERTUSAGE_ENC)); 124 assertTrue("Saving Turkish Hard Token Profile failed", (turprofile2 != null)); 125 126 ret = true; 127 } catch (HardTokenProfileExistsException pee) { 128 } 129 130 assertTrue("Creating Hard Token Profile failed", ret); 131 log.debug("<test01AddHardTokenProfile()"); 132 } 133 134 139 public void test02RenameHardTokenProfile() throws Exception { 140 log.debug(">test02RenameHardTokenProfile()"); 141 142 boolean ret = false; 143 try { 144 cacheAdmin.renameHardTokenProfile(admin, "SWETEST", "SWETEST2"); 145 ret = true; 146 } catch (HardTokenProfileExistsException pee) { 147 } 148 assertTrue("Renaming Hard Token Profile failed", ret); 149 150 log.debug("<test02RenameHardTokenProfile()"); 151 } 152 153 158 public void test03CloneHardTokenProfile() throws Exception { 159 log.debug(">test03CloneHardTokenProfile()"); 160 161 boolean ret = false; 162 try { 163 cacheAdmin.cloneHardTokenProfile(admin, "SWETEST2", "SWETEST"); 164 ret = true; 165 } catch (HardTokenProfileExistsException pee) { 166 } 167 assertTrue("Cloning Hard Token Profile failed", ret); 168 169 log.debug("<test03CloneHardTokenProfile()"); 170 } 171 172 173 178 public void test04EditHardTokenProfile() throws Exception { 179 log.debug(">test04EditHardTokenProfile()"); 180 181 boolean ret = false; 182 183 HardTokenProfile profile = cacheAdmin.getHardTokenProfile(admin, "ENHTEST"); 184 185 186 profile.setHardTokenSNPrefix("11111"); 187 188 cacheAdmin.changeHardTokenProfile(admin, "ENHTEST", profile); 189 ret = true; 190 191 assertTrue("Editing HardTokenProfile failed", ret); 192 193 194 log.debug("<test04EditHardTokenProfile()"); 195 } 196 197 198 203 public void test05removeHardTokenProfiles() throws Exception { 204 log.debug(">test05removeHardTokenProfiles()"); 205 boolean ret = false; 206 try { 207 cacheAdmin.removeHardTokenProfile(admin, "SWETEST"); 209 cacheAdmin.removeHardTokenProfile(admin, "SWETEST2"); 210 cacheAdmin.removeHardTokenProfile(admin, "ENHTEST"); 211 cacheAdmin.removeHardTokenProfile(admin, "TURTEST"); 212 ret = true; 213 } catch (Exception pee) { 214 } 215 assertTrue("Removing Hard Token Profile failed", ret); 216 217 log.debug("<test05removeHardTokenProfiles()"); 218 } 219 220 private String createSVGData() { 221 char[] chararray = new char[SVGFILESIZE]; 222 Arrays.fill(chararray, 'a'); 223 224 return new String (chararray); 225 } 226 227 228 } 229 | Popular Tags |