KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > protocol > ws > TestEjbcaWS


1 package org.ejbca.core.protocol.ws;
2
3 import java.net.URL JavaDoc;
4 import java.security.KeyPair JavaDoc;
5 import java.security.cert.X509Certificate JavaDoc;
6 import java.util.Enumeration JavaDoc;
7 import java.util.List JavaDoc;
8
9 import javax.xml.namespace.QName JavaDoc;
10
11 import junit.framework.TestCase;
12
13 import org.bouncycastle.jce.PKCS10CertificationRequest;
14 import org.ejbca.core.model.ca.catoken.CATokenConstants;
15 import org.ejbca.core.model.ca.crl.RevokedCertInfo;
16 import org.ejbca.core.protocol.ws.client.gen.Certificate;
17 import org.ejbca.core.protocol.ws.client.gen.EjbcaException_Exception;
18 import org.ejbca.core.protocol.ws.client.gen.EjbcaWS;
19 import org.ejbca.core.protocol.ws.client.gen.EjbcaWSService;
20 import org.ejbca.core.protocol.ws.client.gen.KeyStore;
21 import org.ejbca.core.protocol.ws.client.gen.RevokeStatus;
22 import org.ejbca.core.protocol.ws.client.gen.UserDataVOWS;
23 import org.ejbca.core.protocol.ws.client.gen.UserMatch;
24 import org.ejbca.core.protocol.ws.common.CertificateHelper;
25 import org.ejbca.core.protocol.ws.common.KeyStoreHelper;
26 import org.ejbca.util.Base64;
27 import org.ejbca.util.CertTools;
28 import org.ejbca.util.KeyTools;
29
30 /**
31  * Running this test requires that you first create a JKS keystore wstest.jks with password
32  * foo123. This user must be a superadmin in EJBCA.
33  *
34  */

35 public class TestEjbcaWS extends TestCase {
36     
37     private static EjbcaWS ejbcaraws;
38
39
40     protected void setUp() throws Exception JavaDoc {
41         super.setUp();
42         CertTools.installBCProvider();
43         
44         String JavaDoc urlstr = "https://localhost:8443/ejbca/ejbcaws/ejbcaws?wsdl";
45
46         System.out.println("Contacting webservice at " + urlstr);
47         
48         System.setProperty("javax.net.ssl.trustStore","p12/wstest.jks");
49         System.setProperty("javax.net.ssl.trustStorePassword","foo123");
50         
51         System.setProperty("javax.net.ssl.keyStore","p12/wstest.jks");
52         System.setProperty("javax.net.ssl.keyStorePassword","foo123");
53         
54                       
55
56         QName JavaDoc qname = new QName JavaDoc("http://ws.protocol.core.ejbca.org/", "EjbcaWSService");
57         EjbcaWSService service = new EjbcaWSService(new URL JavaDoc(urlstr),qname);
58         ejbcaraws = service.getEjbcaWSPort();
59     }
60     
61     public void test01EditUser() throws Exception JavaDoc{
62         
63         // Test to add a user.
64
UserDataVOWS user1 = new UserDataVOWS();
65         user1.setUsername("WSTESTUSER1");
66         user1.setPassword("foo123");
67         user1.setClearPwd(true);
68         user1.setSubjectDN("CN=WSTESTUSER1");
69         user1.setCaName("AdminCA1");
70         user1.setEmail(null);
71         user1.setSubjectAltName(null);
72         user1.setStatus(10);
73         user1.setTokenType("USERGENERATED");
74         user1.setEndEntityProfileName("EMPTY");
75         user1.setCertificateProfileName("ENDUSER");
76             
77         ejbcaraws.editUser(user1);
78         
79         UserMatch usermatch = new UserMatch();
80         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_USERNAME);
81         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS);
82         usermatch.setMatchvalue("WSTESTUSER1");
83         
84         List JavaDoc<UserDataVOWS> userdatas = ejbcaraws.findUser(usermatch);
85         assertTrue(userdatas != null);
86         assertTrue(userdatas.size() == 1);
87         UserDataVOWS userdata = userdatas.get(0);
88         assertTrue(userdata.getUsername().equals("WSTESTUSER1"));
89         assertTrue(userdata.getPassword() == null);
90         assertTrue(!userdata.isClearPwd());
91         assertTrue(userdata.getSubjectDN().equals("CN=WSTESTUSER1"));
92         assertTrue(userdata.getCaName().equals("AdminCA1"));
93         assertTrue(userdata.getSubjectAltName() == null);
94         assertTrue(userdata.getEmail() == null);
95         assertTrue(userdata.getCertificateProfileName().equals("ENDUSER"));
96         assertTrue(userdata.getEndEntityProfileName().equals("EMPTY"));
97         assertTrue(userdata.getTokenType().equals("USERGENERATED"));
98         assertTrue(userdata.getStatus() == 10);
99         
100         // Edit the user
101
userdata.setSubjectDN("CN=WSTESTUSER1,O=Test");
102         ejbcaraws.editUser(userdata);
103         List JavaDoc<UserDataVOWS> userdatas2 = ejbcaraws.findUser(usermatch);
104         assertTrue(userdatas2 != null);
105         assertTrue(userdatas2.size() == 1);
106         UserDataVOWS userdata2 = userdatas.get(0);
107         assertTrue(userdata2.getSubjectDN().equals("CN=WSTESTUSER1,O=Test"));
108         
109     }
110     
111     public void test02findUser() throws Exception JavaDoc{
112         //Nonexisting users should return null
113
UserMatch usermatch = new UserMatch();
114         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_USERNAME);
115         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS);
116         usermatch.setMatchvalue("WSTESTUSER2");
117         List JavaDoc<UserDataVOWS> userdatas = ejbcaraws.findUser(usermatch);
118         assertTrue(userdatas != null);
119         assertTrue(userdatas.size() == 0);
120         
121         // Find an exising user
122
usermatch = new UserMatch();
123         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_USERNAME);
124         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS);
125         usermatch.setMatchvalue("WSTESTUSER1");
126         
127         List JavaDoc<UserDataVOWS> userdatas2 = ejbcaraws.findUser(usermatch);
128         assertTrue(userdatas2 != null);
129         assertTrue(userdatas2.size() == 1);
130         
131         // Find by O
132
usermatch = new UserMatch();
133         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_ORGANIZATION);
134         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_BEGINSWITH);
135         usermatch.setMatchvalue("Te");
136         List JavaDoc<UserDataVOWS> userdatas3 = ejbcaraws.findUser(usermatch);
137         assertTrue(userdatas3 != null);
138         assertTrue(userdatas3.size() == 1);
139         assertTrue(userdatas3.get(0).getSubjectDN().equals("CN=WSTESTUSER1,O=Test"));
140         
141         // Find by subjectDN pattern
142
usermatch = new UserMatch();
143         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_DN);
144         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_CONTAINS);
145         usermatch.setMatchvalue("WSTESTUSER1");
146         List JavaDoc<UserDataVOWS> userdatas4 = ejbcaraws.findUser(usermatch);
147         assertTrue(userdatas4 != null);
148         assertTrue(userdatas4.size() == 1);
149         assertTrue(userdatas4.get(0).getSubjectDN().equals("CN=WSTESTUSER1,O=Test"));
150         
151         usermatch = new UserMatch();
152         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_ENDENTITYPROFILE);
153         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS);
154         usermatch.setMatchvalue("EMPTY");
155         List JavaDoc<UserDataVOWS> userdatas5 = ejbcaraws.findUser(usermatch);
156         assertTrue(userdatas5 != null);
157         assertTrue(userdatas5.size() > 0);
158         
159         usermatch = new UserMatch();
160         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_CERTIFICATEPROFILE);
161         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS);
162         usermatch.setMatchvalue("ENDUSER");
163         List JavaDoc<UserDataVOWS> userdatas6 = ejbcaraws.findUser(usermatch);
164         assertTrue(userdatas6 != null);
165         assertTrue(userdatas6.size() > 0);
166
167         usermatch = new UserMatch();
168         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_CA);
169         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS);
170         usermatch.setMatchvalue("AdminCA1");
171         List JavaDoc<UserDataVOWS> userdatas7 = ejbcaraws.findUser(usermatch);
172         assertTrue(userdatas7 != null);
173         assertTrue(userdatas7.size() > 0);
174
175         usermatch = new UserMatch();
176         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_TOKEN);
177         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS);
178         usermatch.setMatchvalue("USERGENERATED");
179         List JavaDoc<UserDataVOWS> userdatas8 = ejbcaraws.findUser(usermatch);
180         assertTrue(userdatas8 != null);
181         assertTrue(userdatas8.size() > 0);
182     }
183     
184     public void test03GeneratePkcs10() throws Exception JavaDoc{
185         KeyPair JavaDoc keys = KeyTools.genKeys("1024", CATokenConstants.KEYALGORITHM_RSA);
186         PKCS10CertificationRequest pkcs10 = new PKCS10CertificationRequest("SHA1WithRSA",
187                 CertTools.stringToBcX509Name("CN=NOUSED"), keys.getPublic(), null, keys.getPrivate());
188         
189         Certificate JavaDoc certenv = ejbcaraws.pkcs10Req("WSTESTUSER1","foo123",new String JavaDoc(Base64.encode(pkcs10.getEncoded())),null);
190         
191         assertNotNull(certenv);
192         
193         X509Certificate JavaDoc cert = (X509Certificate JavaDoc) CertificateHelper.getCertificate(certenv.getCertificateData());
194         
195         assertNotNull(cert);
196         
197         assertTrue(cert.getSubjectDN().toString().equals("CN=WSTESTUSER1,O=Test"));
198         System.out.println("test03GeneratePkcs10() Certificate " +cert.getSubjectDN().toString() + " equals CN=WSTESTUSER1,O=Test");
199         
200     }
201     
202     public void test04GeneratePkcs12() throws Exception JavaDoc{
203
204         boolean exceptionThrown = false;
205         try{
206            ejbcaraws.pkcs12Req("WSTESTUSER1","foo123",null,"1024", CATokenConstants.KEYALGORITHM_RSA);
207         }catch(EjbcaException_Exception e){
208             exceptionThrown = true;
209         }
210         assertTrue(exceptionThrown);// Should fail
211

212         // Change token to P12
213
UserMatch usermatch = new UserMatch();
214         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_USERNAME);
215         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS);
216         usermatch.setMatchvalue("WSTESTUSER1");
217         List JavaDoc<UserDataVOWS> userdatas = ejbcaraws.findUser(usermatch);
218         assertTrue(userdatas != null);
219         assertTrue(userdatas.size() == 1);
220         userdatas.get(0).setTokenType("P12");
221         ejbcaraws.editUser(userdatas.get(0));
222         
223         exceptionThrown = false;
224         try{
225           ejbcaraws.pkcs12Req("WSTESTUSER1","foo123",null,"1024", CATokenConstants.KEYALGORITHM_RSA);
226         }catch(EjbcaException_Exception e){
227             exceptionThrown = true;
228         }
229         assertTrue(exceptionThrown); // Should fail
230

231         // Change token to P12
232
userdatas.get(0).setStatus(10);
233         userdatas.get(0).setPassword("foo456");
234         userdatas.get(0).setClearPwd(true);
235         ejbcaraws.editUser(userdatas.get(0));
236         
237         KeyStore ksenv = null;
238         try{
239           ksenv = ejbcaraws.pkcs12Req("WSTESTUSER1","foo456",null,"1024", CATokenConstants.KEYALGORITHM_RSA);
240         }catch(EjbcaException_Exception e){
241             assertTrue(e.getMessage(),false);
242         }
243         
244         assertNotNull(ksenv);
245                 
246         java.security.KeyStore JavaDoc ks = KeyStoreHelper.getKeyStore(ksenv.getKeystoreData(),"PKCS12","foo456");
247         
248         assertNotNull(ks);
249         Enumeration JavaDoc en = ks.aliases();
250         String JavaDoc alias = (String JavaDoc) en.nextElement();
251         X509Certificate JavaDoc cert = (X509Certificate JavaDoc) ks.getCertificate(alias);
252         assertTrue(cert.getSubjectDN().toString().equals("CN=WSTESTUSER1,O=Test"));
253         System.out.println("test03GeneratePkcs12() Certificate " +cert.getSubjectDN().toString() + " equals CN=WSTESTUSER1,O=Test");
254
255     }
256     
257     public void test05findCerts() throws Exception JavaDoc{
258         
259         // First find all certs
260
UserMatch usermatch = new UserMatch();
261         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_USERNAME);
262         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS);
263         usermatch.setMatchvalue("WSTESTUSER1");
264         List JavaDoc<UserDataVOWS> userdatas = ejbcaraws.findUser(usermatch);
265         assertTrue(userdatas != null);
266         assertTrue(userdatas.size() == 1);
267         userdatas.get(0).setTokenType("P12");
268         userdatas.get(0).setStatus(10);
269         userdatas.get(0).setPassword("foo123");
270         userdatas.get(0).setClearPwd(true);
271         ejbcaraws.editUser(userdatas.get(0));
272         KeyStore ksenv = null;
273         try{
274             ksenv = ejbcaraws.pkcs12Req("WSTESTUSER1","foo123",null,"1024", CATokenConstants.KEYALGORITHM_RSA);
275         }catch(EjbcaException_Exception e){
276             assertTrue(e.getMessage(),false);
277         }
278         java.security.KeyStore JavaDoc ks = KeyStoreHelper.getKeyStore(ksenv.getKeystoreData(),"PKCS12","foo123");
279         
280         assertNotNull(ks);
281         Enumeration JavaDoc en = ks.aliases();
282         String JavaDoc alias = (String JavaDoc) en.nextElement();
283         X509Certificate JavaDoc gencert = (X509Certificate JavaDoc) ks.getCertificate(alias);
284         
285         List JavaDoc<Certificate JavaDoc> foundcerts = ejbcaraws.findCerts("WSTESTUSER1",false);
286         assertTrue(foundcerts != null);
287         assertTrue(foundcerts.size() > 0);
288         
289         boolean certFound = false;
290         for(int i=0;i<foundcerts.size();i++){
291             X509Certificate JavaDoc cert = (X509Certificate JavaDoc) CertificateHelper.getCertificate(foundcerts.get(i).getCertificateData());
292             if(gencert.getSerialNumber().equals(cert.getSerialNumber())){
293                 certFound = true;
294             }
295         }
296         assertTrue(certFound);
297         
298         String JavaDoc issuerdn = gencert.getIssuerDN().toString();
299         String JavaDoc serno = gencert.getSerialNumber().toString(16);
300         
301         ejbcaraws.revokeCert(issuerdn,serno, RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE);
302         
303         foundcerts = ejbcaraws.findCerts("WSTESTUSER1",true);
304         assertTrue(foundcerts != null);
305         assertTrue(foundcerts.size() > 0);
306         
307         certFound = false;
308         for(int i=0;i<foundcerts.size();i++){
309             X509Certificate JavaDoc cert = (X509Certificate JavaDoc) CertificateHelper.getCertificate(foundcerts.get(i).getCertificateData());
310             if(gencert.getSerialNumber().equals(cert.getSerialNumber())){
311                 certFound = true;
312             }
313         }
314         assertFalse(certFound);
315         
316         
317     }
318     
319     public void test06revokeCert() throws Exception JavaDoc{
320         UserMatch usermatch = new UserMatch();
321         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_USERNAME);
322         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS);
323         usermatch.setMatchvalue("WSTESTUSER1");
324         List JavaDoc<UserDataVOWS> userdatas = ejbcaraws.findUser(usermatch);
325         assertTrue(userdatas != null);
326         assertTrue(userdatas.size() == 1);
327         userdatas.get(0).setTokenType("P12");
328         userdatas.get(0).setStatus(10);
329         userdatas.get(0).setPassword("foo456");
330         userdatas.get(0).setClearPwd(true);
331         ejbcaraws.editUser(userdatas.get(0));
332         
333         KeyStore ksenv = null;
334         try{
335           ksenv = ejbcaraws.pkcs12Req("WSTESTUSER1","foo456",null,"1024", CATokenConstants.KEYALGORITHM_RSA);
336         }catch(EjbcaException_Exception e){
337             assertTrue(e.getMessage(),false);
338         }
339         
340         java.security.KeyStore JavaDoc ks = KeyStoreHelper.getKeyStore(ksenv.getKeystoreData(),"PKCS12","foo456");
341         assertNotNull(ks);
342         Enumeration JavaDoc en = ks.aliases();
343         String JavaDoc alias = (String JavaDoc) en.nextElement();
344         X509Certificate JavaDoc cert = (X509Certificate JavaDoc) ks.getCertificate(alias);
345         assertTrue(cert.getSubjectDN().toString().equals("CN=WSTESTUSER1,O=Test"));
346         
347         String JavaDoc issuerdn = cert.getIssuerDN().toString();
348         String JavaDoc serno = cert.getSerialNumber().toString(16);
349         
350         ejbcaraws.revokeCert(issuerdn,serno, RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE);
351         
352         RevokeStatus revokestatus = ejbcaraws.checkRevokationStatus(issuerdn,serno);
353         assertNotNull(revokestatus);
354         assertTrue(revokestatus.getReason() == RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE);
355         
356         assertTrue(revokestatus.getCertificateSN().equals(serno));
357         assertTrue(revokestatus.getIssuerDN().equals(issuerdn));
358         assertNotNull(revokestatus.getRevocationDate());
359             
360     }
361     
362     public void test07revokeToken() throws Exception JavaDoc{
363         UserMatch usermatch = new UserMatch();
364         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_USERNAME);
365         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS);
366         usermatch.setMatchvalue("WSTESTUSER1");
367         List JavaDoc<UserDataVOWS> userdatas = ejbcaraws.findUser(usermatch);
368         userdatas.get(0).setTokenType("P12");
369         userdatas.get(0).setStatus(10);
370         userdatas.get(0).setPassword("foo123");
371         userdatas.get(0).setClearPwd(true);
372         ejbcaraws.editUser(userdatas.get(0));
373         KeyStore ksenv = null;
374         try{
375             ksenv = ejbcaraws.pkcs12Req("WSTESTUSER1","foo123","12345678","1024", CATokenConstants.KEYALGORITHM_RSA);
376         }catch(EjbcaException_Exception e){
377             assertTrue(e.getMessage(),false);
378         }
379         java.security.KeyStore JavaDoc ks = KeyStoreHelper.getKeyStore(ksenv.getKeystoreData(),"PKCS12","foo123");
380         
381         assertNotNull(ks);
382         Enumeration JavaDoc en = ks.aliases();
383         String JavaDoc alias = (String JavaDoc) en.nextElement();
384         X509Certificate JavaDoc cert1 = (X509Certificate JavaDoc) ks.getCertificate(alias);
385         
386         userdatas.get(0).setStatus(10);
387         userdatas.get(0).setPassword("foo123");
388         userdatas.get(0).setClearPwd(true);
389         ejbcaraws.editUser(userdatas.get(0));
390         
391         try{
392             ksenv = ejbcaraws.pkcs12Req("WSTESTUSER1","foo123","12345678","1024", CATokenConstants.KEYALGORITHM_RSA);
393         }catch(EjbcaException_Exception e){
394             assertTrue(e.getMessage(),false);
395         }
396         ks = KeyStoreHelper.getKeyStore(ksenv.getKeystoreData(),"PKCS12","foo123");
397         
398         assertNotNull(ks);
399         en = ks.aliases();
400         alias = (String JavaDoc) en.nextElement();
401         X509Certificate JavaDoc cert2 = (X509Certificate JavaDoc) ks.getCertificate(alias);
402         
403         ejbcaraws.revokeToken("12345678",RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE);
404         
405         String JavaDoc issuerdn1 = cert1.getIssuerDN().toString();
406         String JavaDoc serno1 = cert1.getSerialNumber().toString(16);
407         
408         RevokeStatus revokestatus = ejbcaraws.checkRevokationStatus(issuerdn1,serno1);
409         assertNotNull(revokestatus);
410         assertTrue(revokestatus.getReason() == RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE);
411         
412         String JavaDoc issuerdn2 = cert2.getIssuerDN().toString();
413         String JavaDoc serno2 = cert2.getSerialNumber().toString(16);
414         
415         revokestatus = ejbcaraws.checkRevokationStatus(issuerdn2,serno2);
416         assertNotNull(revokestatus);
417         assertTrue(revokestatus.getReason() == RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE);
418         
419     }
420     
421     public void test08checkRevokeStatus() throws Exception JavaDoc{
422         UserMatch usermatch = new UserMatch();
423         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_USERNAME);
424         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS);
425         usermatch.setMatchvalue("WSTESTUSER1");
426         List JavaDoc<UserDataVOWS> userdatas = ejbcaraws.findUser(usermatch);
427         userdatas.get(0).setTokenType("P12");
428         userdatas.get(0).setStatus(10);
429         userdatas.get(0).setPassword("foo123");
430         userdatas.get(0).setClearPwd(true);
431         ejbcaraws.editUser(userdatas.get(0));
432         KeyStore ksenv = null;
433         try{
434             ksenv = ejbcaraws.pkcs12Req("WSTESTUSER1","foo123","12345678","1024", CATokenConstants.KEYALGORITHM_RSA);
435         }catch(EjbcaException_Exception e){
436             assertTrue(e.getMessage(),false);
437         }
438         java.security.KeyStore JavaDoc ks = KeyStoreHelper.getKeyStore(ksenv.getKeystoreData(),"PKCS12","foo123");
439         
440         assertNotNull(ks);
441         Enumeration JavaDoc en = ks.aliases();
442         String JavaDoc alias = (String JavaDoc) en.nextElement();
443         X509Certificate JavaDoc cert = (X509Certificate JavaDoc) ks.getCertificate(alias);
444         
445         String JavaDoc issuerdn = cert.getIssuerDN().toString();
446         String JavaDoc serno = cert.getSerialNumber().toString(16);
447         
448         RevokeStatus revokestatus = ejbcaraws.checkRevokationStatus(issuerdn,serno);
449         assertNotNull(revokestatus);
450         assertTrue(revokestatus.getReason() == RevokedCertInfo.NOT_REVOKED);
451         
452         ejbcaraws.revokeCert(issuerdn,serno, RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE);
453         
454         revokestatus = ejbcaraws.checkRevokationStatus(issuerdn,serno);
455         assertNotNull(revokestatus);
456         assertTrue(revokestatus.getReason() == RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE);
457         assertTrue(revokestatus.getCertificateSN().equals(serno));
458         assertTrue(revokestatus.getIssuerDN().equals(issuerdn));
459         assertNotNull(revokestatus.getRevocationDate());
460     }
461     
462     public void test01UTF8() throws Exception JavaDoc{
463         
464         // Test to add a user.
465
UserDataVOWS user1 = new UserDataVOWS();
466         user1.setUsername("WSTESTUSER1");
467         user1.setPassword("foo123");
468         user1.setClearPwd(true);
469         user1.setSubjectDN("CN=WS������");
470         user1.setCaName("AdminCA1");
471         user1.setEmail(null);
472         user1.setSubjectAltName(null);
473         user1.setStatus(10);
474         user1.setTokenType("USERGENERATED");
475         user1.setEndEntityProfileName("EMPTY");
476         user1.setCertificateProfileName("ENDUSER");
477             
478         ejbcaraws.editUser(user1);
479         
480         UserMatch usermatch = new UserMatch();
481         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_USERNAME);
482         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS);
483         usermatch.setMatchvalue("WSTESTUSER1");
484         
485         List JavaDoc<UserDataVOWS> userdatas = ejbcaraws.findUser(usermatch);
486         assertTrue(userdatas != null);
487         assertTrue(userdatas.size() == 1);
488         UserDataVOWS userdata = userdatas.get(0);
489         assertTrue(userdata.getUsername().equals("WSTESTUSER1"));
490         assertTrue(userdata.getSubjectDN().equals("CN=WS������"));
491         
492     }
493     
494     
495     public void test10revokeUser() throws Exception JavaDoc{
496         
497         // Revoke and delete
498
ejbcaraws.revokeUser("WSTESTUSER1",RevokedCertInfo.REVOKATION_REASON_KEYCOMPROMISE,true);
499         
500         UserMatch usermatch = new UserMatch();
501         usermatch.setMatchwith(org.ejbca.util.query.UserMatch.MATCH_WITH_USERNAME);
502         usermatch.setMatchtype(org.ejbca.util.query.UserMatch.MATCH_TYPE_EQUALS);
503         usermatch.setMatchvalue("WSTESTUSER1");
504         List JavaDoc<UserDataVOWS> userdatas = ejbcaraws.findUser(usermatch);
505         assertTrue(userdatas != null);
506         assertTrue(userdatas.size() == 0);
507
508     }
509
510 }
511
512
Popular Tags