usersession.setUserStatus(admin,"foo",UserDataConstants.STATUS_NEW, false);
usersession.setUserStatus(admin,"foo",UserDataConstants.STATUS_NEW);
    public void test04RevokeAndUnrevoke() throws Exception {        log.debug(">test04RevokeAndUnrevoke()");        // Make user that we know...        boolean userExists = false;        try {            usersession.addUser(admin,"foo","foo123","C=SE,O=AnaTom,CN=foo",null,"foo@anatom.se",false,SecConst.EMPTY_ENDENTITYPROFILE,SecConst.CERTPROFILE_FIXED_ENDUSER,SecConst.USER_ENDUSER,SecConst.TOKEN_SOFT_PEM,0,caid);            log.debug("created user: foo, foo123, C=SE, O=AnaTom, CN=foo");        } catch (RemoteException re) {            if (re.detail instanceof DuplicateKeyException) {                userExists = true;            }        } catch (DuplicateKeyException dke) {            userExists = true;        }        if (userExists) {            log.info("User foo already exists, resetting status.");            usersession.setUserStatus(admin,"foo",UserDataConstants.STATUS_NEW, false);            log.debug("Reset status to NEW");        }        KeyPair keys = genKeys();        // user that we know exists...        X509Certificate cert = (X509Certificate)signsession.createCertificate(admin, "foo", "foo123", keys.getPublic());        assertNotNull("Misslyckades skapa cert", cert);        log.debug("Cert=" + cert.toString());        // Create a new CRL again...        remote.run(admin, cadn);        // Check that our newloy signed certificate is not present in a new CRL        byte[] crl = storeremote.getLastCRL(admin, cadn);        assertNotNull("Could not get CRL", crl);        X509CRL x509crl = CertTools.getCRLfromByteArray(crl);        Set revset = x509crl.getRevokedCertificates();        if (revset != null) {            Iterator iter = revset.iterator();            while (iter.hasNext()) {                X509CRLEntry ce = (X509CRLEntry)iter.next();                 assertTrue(ce.getSerialNumber().compareTo(cert.getSerialNumber()) != 0);            }                    } // If no revoked certificates exist at all, this test passed...        storeremote.revokeCertificate(admin, cert, null, RevokedCertInfo.REVOKATION_REASON_CERTIFICATEHOLD);        // Create a new CRL again...        remote.run(admin, cadn);        // Check that our newly signed certificate IS present in a new CRL        crl = storeremote.getLastCRL(admin, cadn);        assertNotNull("Could not get CRL", crl);        x509crl = CertTools.getCRLfromByteArray(crl);        revset = x509crl.getRevokedCertificates();        assertNotNull(revset);        Iterator iter = revset.iterator();        boolean found = false;        while (iter.hasNext()) {            X509CRLEntry ce = (X509CRLEntry)iter.next();         	if (ce.getSerialNumber().compareTo(cert.getSerialNumber()) == 0) {        		found = true;        		// TODO: verify the reason code        	}        }        assertTrue(found);                // Unrevoke the certificate that we just revoked        storeremote.revokeCertificate(admin, cert, null, RevokedCertInfo.NOT_REVOKED);        // Create a new CRL again...        remote.run(admin, cadn);        // Check that our newly signed certificate IS NOT present in the new CRL.        crl = storeremote.getLastCRL(admin, cadn);        assertNotNull("Could not get CRL", crl);        x509crl = CertTools.getCRLfromByteArray(crl);        revset = x509crl.getRevokedCertificates();        if (revset != null) {        	iter = revset.iterator();        	found = false;        	while (iter.hasNext()) {        		X509CRLEntry ce = (X509CRLEntry)iter.next();         		if (ce.getSerialNumber().compareTo(cert.getSerialNumber()) == 0) {        			found = true;        		}        	}        	assertFalse(found);        } // If no revoked certificates exist at all, this test passed...        storeremote.revokeCertificate(admin, cert, null, RevokedCertInfo.REVOKATION_REASON_CACOMPROMISE);        // Create a new CRL again...        remote.run(admin, cadn);        // Check that our newly signed certificate IS present in a new CRL        crl = storeremote.getLastCRL(admin, cadn);        assertNotNull("Could not get CRL", crl);        x509crl = CertTools.getCRLfromByteArray(crl);        revset = x509crl.getRevokedCertificates();        iter = revset.iterator();        found = false;        while (iter.hasNext()) {            X509CRLEntry ce = (X509CRLEntry)iter.next();         	if (ce.getSerialNumber().compareTo(cert.getSerialNumber()) == 0) {        		found = true;        		// TODO: verify the reason code        	}        }        assertTrue(found);        storeremote.revokeCertificate(admin, cert, null, RevokedCertInfo.NOT_REVOKED);        // Create a new CRL again...        remote.run(admin, cadn);        // Check that our newly signed certificate is present in the new CRL, because the revocation reason        // was not CERTIFICATE_HOLD, we can olny unrevoke certificates that are on hold.        crl = storeremote.getLastCRL(admin, cadn);        assertNotNull("Could not get CRL", crl);        x509crl = CertTools.getCRLfromByteArray(crl);        revset = x509crl.getRevokedCertificates();        iter = revset.iterator();        found = false;        while (iter.hasNext()) {            X509CRLEntry ce = (X509CRLEntry)iter.next();         	if (ce.getSerialNumber().compareTo(cert.getSerialNumber()) == 0) {        		found = true;        	}        }        assertTrue(found);        log.debug("<test04RevokeAndUnrevoke()");    }