Search in sources :

Example 1 with CertStore

use of org.xipki.ca.server.db.CertStore in project xipki by xipki.

the class CaManagerImpl method init.

private void init() throws CaMgmtException {
    if (securityFactory == null) {
        throw new IllegalStateException("securityFactory is not set");
    }
    if (datasourceFactory == null) {
        throw new IllegalStateException("datasourceFactory is not set");
    }
    if (certprofileFactoryRegister == null) {
        throw new IllegalStateException("certprofileFactoryRegister is not set");
    }
    if (certPublisherFactoryRegister == null) {
        throw new IllegalStateException("certPublisherFactoryRegister is not set");
    }
    if (caServerConf == null) {
        throw new IllegalStateException("caServerConf is not set");
    }
    masterMode = caServerConf.isMaster();
    LOG.info("ca.masterMode: {}", masterMode);
    shardId = caServerConf.getShardId();
    LOG.info("ca.shardId: {}", shardId);
    caServerConf.initSsl();
    if (caServerConf.getCtLog() != null) {
        try {
            ctLogPublicKeyFinder = new CtLogPublicKeyFinder(caServerConf.getCtLog());
        } catch (Exception ex) {
            throw new CaMgmtException("could not load CtLogPublicKeyFinder: " + ex.getMessage(), ex);
        }
    }
    if (this.datasourceNameConfFileMap == null) {
        this.datasourceNameConfFileMap = new ConcurrentHashMap<>();
        List<DataSourceConf> datasourceList = caServerConf.getDatasources();
        for (DataSourceConf datasource : datasourceList) {
            String name = datasource.getName();
            FileOrValue conf = datasource.getConf();
            this.datasourceNameConfFileMap.put(name, conf);
            if (conf.getFile() != null) {
                LOG.info("associate datasource {} to the file {}", name, conf.getFile());
            } else {
                LOG.info("associate datasource {} to text value", name);
            }
        }
        FileOrValue caDatasourceConf = datasourceNameConfFileMap.remove("ca");
        if (caDatasourceConf == null) {
            throw new CaMgmtException("no datasource named 'ca' configured");
        }
        this.datasource = loadDatasource("ca", caDatasourceConf);
    }
    this.queryExecutor = new CaManagerQueryExecutor(this.datasource);
    if (masterMode) {
        lockCa(true);
        List<String> names = queryExecutor.namesFromTable("REQUESTOR");
        final String[] embeddedNames = { RequestorInfo.NAME_BY_CA, RequestorInfo.NAME_BY_USER };
        for (String embeddedName : embeddedNames) {
            boolean contained = false;
            for (String name : names) {
                if (embeddedName.equalsIgnoreCase(name)) {
                    contained = true;
                    break;
                }
            }
            if (!contained) {
                queryExecutor.addEmbeddedRequestor(embeddedName);
            }
        }
    }
    final long epoch = DateUtil.parseUtcTimeyyyyMMdd("20100101").getTime();
    UniqueIdGenerator idGen = new UniqueIdGenerator(epoch, shardId);
    boolean initSucc = true;
    try {
        this.certstore = new CertStore(datasource, idGen, securityFactory.getPasswordResolver());
    } catch (DataAccessException ex) {
        initSucc = false;
        LogUtil.error(LOG, ex, "error constructing CertStore");
    }
    try {
        ca2Manager.initCaAliases();
    } catch (CaMgmtException ex) {
        initSucc = false;
        LogUtil.error(LOG, ex, "error initCaAliases");
    }
    try {
        certprofileManager.initCertprofiles();
    } catch (CaMgmtException ex) {
        initSucc = false;
        LogUtil.error(LOG, ex, "error initCertprofiles");
    }
    try {
        publisherManager.initPublishers();
    } catch (CaMgmtException ex) {
        initSucc = false;
        LogUtil.error(LOG, ex, "error initPublishers");
    }
    try {
        requestorManager.initRequestors();
    } catch (CaMgmtException ex) {
        initSucc = false;
        LogUtil.error(LOG, ex, "error initRequestors");
    }
    try {
        signerManager.initSigners();
    } catch (CaMgmtException ex) {
        initSucc = false;
        LogUtil.error(LOG, ex, "error initSigners");
    }
    try {
        keypairGenManager.initKeypairGens();
    } catch (CaMgmtException ex) {
        initSucc = false;
        LogUtil.error(LOG, ex, "error initKeypairGens");
    }
    try {
        ca2Manager.initCas();
    } catch (CaMgmtException ex) {
        initSucc = false;
        LogUtil.error(LOG, ex, "error initCas");
    }
    if (!initSucc) {
        throw new CaMgmtException("error initializing CA system");
    }
}
Also used : DataSourceConf(org.xipki.datasource.DataSourceConf) SocketException(java.net.SocketException) DataAccessException(org.xipki.datasource.DataAccessException) IOException(java.io.IOException) OperationException(org.xipki.ca.api.OperationException) PasswordResolverException(org.xipki.password.PasswordResolverException) CaManagerQueryExecutor(org.xipki.ca.server.db.CaManagerQueryExecutor) CertStore(org.xipki.ca.server.db.CertStore) DataAccessException(org.xipki.datasource.DataAccessException)

Aggregations

IOException (java.io.IOException)1 SocketException (java.net.SocketException)1 OperationException (org.xipki.ca.api.OperationException)1 CaManagerQueryExecutor (org.xipki.ca.server.db.CaManagerQueryExecutor)1 CertStore (org.xipki.ca.server.db.CertStore)1 DataAccessException (org.xipki.datasource.DataAccessException)1 DataSourceConf (org.xipki.datasource.DataSourceConf)1 PasswordResolverException (org.xipki.password.PasswordResolverException)1