private void createUser(String username, String password, int caid, KeyPair rsaKeys, boolean createJKS, boolean createPEM, boolean savekeys)
private void createUser(String username, String password, int caid, KeyPair rsaKeys, boolean createJKS, boolean createPEM, boolean savekeys, X509Certificate orgCert)
    private void createUser(String username, String password, int caid, KeyPair rsaKeys, boolean createJKS, boolean createPEM, boolean savekeys)            throws Exception {        log.debug(">createUser: username=" + username);        // Send the certificate request to the CA        ISignSessionRemote ss = signhome.create();        X509Certificate cert = (X509Certificate) ss.createCertificate(administrator, username,                password, rsaKeys.getPublic());        //System.out.println("issuer " + CertTools.getIssuerDN(cert) + ", " + cert.getClass().getName());        // Make a certificate chain from the certificate and the CA-certificate        Certificate[] cachain = getCACertChain(caid);        // Verify CA-certificate        if (CertTools.isSelfSigned((X509Certificate) cachain[cachain.length - 1])) {            try {                cachain[cachain.length - 1].verify(cachain[cachain.length - 1].getPublicKey());            } catch (GeneralSecurityException se) {                throw new Exception("RootCA certificate does not verify");            }        } else {            throw new Exception("RootCA certificate not self-signed");        }        // Verify that the user-certificate is signed by our CA        try {            cert.verify(cachain[0].getPublicKey());        } catch (GeneralSecurityException se) {            throw new Exception("Generated certificate does not verify using CA-certificate.");        }        if (usekeyrecovery && savekeys) {            // Save generated keys to database.            IKeyRecoverySessionRemote keyrecoverysession = keyrecoveryhome.create();            keyrecoverysession.addKeyRecoveryData(administrator, cert, username, rsaKeys);        }        // Use CN if as alias in the keystore, if CN is not present use username        String alias = CertTools.getPartFromDN(CertTools.getSubjectDN(cert), "CN");        if (alias == null) alias = username;        // Store keys and certificates in keystore.        KeyStore ks = null;        if (createJKS) {            ks = KeyTools.createJKS(alias, rsaKeys.getPrivate(), password, cert, cachain);        } else {            ks = KeyTools.createP12(alias, rsaKeys.getPrivate(), cert, cachain);        }        storeKeyStore(ks, username, password, createJKS, createPEM);        log.info("Created Keystore for " + username + ".");        log.debug("<createUser: username=" + username);    } // createUser