Search in sources :

Example 1 with ResponderEntryWrapper

use of org.xipki.ca.server.impl.cmp.ResponderEntryWrapper in project xipki by xipki.

the class CaManagerImpl method initResponders.

// method initRequestors
private void initResponders() throws CaMgmtException {
    if (responderInitialized) {
        return;
    }
    responderDbEntries.clear();
    responders.clear();
    List<String> names = queryExecutor.namesFromTable("RESPONDER");
    for (String name : names) {
        ResponderEntry dbEntry = queryExecutor.createResponder(name);
        if (dbEntry == null) {
            LOG.error("could not initialize Responder '{}'", name);
            continue;
        }
        dbEntry.setConfFaulty(true);
        responderDbEntries.put(name, dbEntry);
        ResponderEntryWrapper responder = createResponder(dbEntry);
        if (responder != null) {
            dbEntry.setConfFaulty(false);
            responders.put(name, responder);
        }
    }
    responderInitialized = true;
}
Also used : ResponderEntry(org.xipki.ca.server.mgmt.api.ResponderEntry) ResponderEntryWrapper(org.xipki.ca.server.impl.cmp.ResponderEntryWrapper)

Example 2 with ResponderEntryWrapper

use of org.xipki.ca.server.impl.cmp.ResponderEntryWrapper in project xipki by xipki.

the class CaManagerImpl method createResponder.

// method shutdownPublisher
ResponderEntryWrapper createResponder(ResponderEntry dbEntry) throws CaMgmtException {
    ParamUtil.requireNonNull("dbEntry", dbEntry);
    ResponderEntryWrapper ret = new ResponderEntryWrapper();
    ret.setDbEntry(dbEntry);
    try {
        ret.initSigner(securityFactory);
    } catch (ObjectCreationException ex) {
        final String message = "createCmpResponder";
        LOG.debug(message, ex);
        throw new CaMgmtException(ex.getMessage());
    }
    return ret;
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) ObjectCreationException(org.xipki.common.ObjectCreationException) ResponderEntryWrapper(org.xipki.ca.server.impl.cmp.ResponderEntryWrapper)

Example 3 with ResponderEntryWrapper

use of org.xipki.ca.server.impl.cmp.ResponderEntryWrapper in project xipki by xipki.

the class CaManagerQueryExecutor method changeResponder.

// method changeRequestor
ResponderEntryWrapper changeResponder(String name, String type, String conf, String base64Cert, CaManagerImpl caManager, SecurityFactory securityFactory) throws CaMgmtException {
    ParamUtil.requireNonBlank("name", name);
    ParamUtil.requireNonNull("caManager", caManager);
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append("UPDATE RESPONDER SET ");
    AtomicInteger index = new AtomicInteger(1);
    Integer idxType = addToSqlIfNotNull(sqlBuilder, index, type, "TYPE");
    Integer idxCert = addToSqlIfNotNull(sqlBuilder, index, base64Cert, "CERT");
    Integer idxConf = addToSqlIfNotNull(sqlBuilder, index, conf, "CONF");
    sqlBuilder.deleteCharAt(sqlBuilder.length() - 1);
    sqlBuilder.append(" WHERE NAME=?");
    if (index.get() == 1) {
        throw new IllegalArgumentException("nothing to change");
    }
    ResponderEntry dbEntry = createResponder(name);
    String tmpType = (type != null) ? type : dbEntry.getType();
    String tmpConf;
    if (conf == null) {
        tmpConf = dbEntry.getConf();
    } else {
        tmpConf = CaManagerImpl.canonicalizeSignerConf(tmpType, conf, null, securityFactory);
    }
    String tmpBase64Cert;
    if (base64Cert == null) {
        tmpBase64Cert = dbEntry.getBase64Cert();
    } else {
        tmpBase64Cert = base64Cert;
    }
    ResponderEntry newDbEntry = new ResponderEntry(name, tmpType, tmpConf, tmpBase64Cert);
    ResponderEntryWrapper responder = caManager.createResponder(newDbEntry);
    final String sql = sqlBuilder.toString();
    StringBuilder sb = new StringBuilder();
    PreparedStatement ps = null;
    try {
        ps = prepareStatement(sql);
        if (idxType != null) {
            String txt = tmpType;
            ps.setString(idxType, txt);
            sb.append("type: '").append(txt).append("'; ");
        }
        if (idxConf != null) {
            String txt = getRealString(tmpConf);
            sb.append("conf: '").append(SignerConf.toString(txt, false, true));
            ps.setString(idxConf, txt);
        }
        if (idxCert != null) {
            String txt = getRealString(tmpBase64Cert);
            sb.append("cert: '");
            if (txt == null) {
                sb.append("null");
            } else {
                try {
                    String subject = canonicalizName(X509Util.parseBase64EncodedCert(txt).getSubjectX500Principal());
                    sb.append(subject);
                } catch (CertificateException ex) {
                    sb.append("ERROR");
                }
            }
            sb.append("'; ");
            ps.setString(idxCert, txt);
        }
        ps.setString(index.get(), name);
        if (ps.executeUpdate() == 0) {
            throw new CaMgmtException("could not change responder " + name);
        }
        if (sb.length() > 0) {
            sb.deleteCharAt(sb.length() - 1).deleteCharAt(sb.length() - 1);
        }
        LOG.info("changed responder: {}", sb);
        return responder;
    } catch (SQLException ex) {
        throw new CaMgmtException(datasource, sql, ex);
    } finally {
        datasource.releaseResources(ps, null);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SQLException(java.sql.SQLException) ResponderEntry(org.xipki.ca.server.mgmt.api.ResponderEntry) PreparedStatement(java.sql.PreparedStatement) CertificateException(java.security.cert.CertificateException) ResponderEntryWrapper(org.xipki.ca.server.impl.cmp.ResponderEntryWrapper)

Example 4 with ResponderEntryWrapper

use of org.xipki.ca.server.impl.cmp.ResponderEntryWrapper in project xipki by xipki.

the class CaManagerImpl method addResponder.

// method addCertprofile
@Override
public void addResponder(ResponderEntry dbEntry) throws CaMgmtException {
    ParamUtil.requireNonNull("dbEntry", dbEntry);
    asssertMasterMode();
    String name = dbEntry.getName();
    if (responderDbEntries.containsKey(name)) {
        throw new CaMgmtException(concat("Responder named ", name, " exists"));
    }
    String conf = dbEntry.getConf();
    if (conf != null) {
        String newConf = canonicalizeSignerConf(dbEntry.getType(), conf, null, securityFactory);
        if (!conf.equals(newConf)) {
            dbEntry.setConf(newConf);
        }
    }
    ResponderEntryWrapper responder = createResponder(dbEntry);
    queryExecutor.addResponder(dbEntry);
    responders.put(name, responder);
    responderDbEntries.put(name, dbEntry);
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) ResponderEntryWrapper(org.xipki.ca.server.impl.cmp.ResponderEntryWrapper)

Example 5 with ResponderEntryWrapper

use of org.xipki.ca.server.impl.cmp.ResponderEntryWrapper in project xipki by xipki.

the class CaManagerImpl method changeResponder.

// method removeResponder
@Override
public void changeResponder(String name, String type, String conf, String base64Cert) throws CaMgmtException {
    name = ParamUtil.requireNonBlank("name", name).toLowerCase();
    asssertMasterMode();
    if (type == null && conf == null && base64Cert == null) {
        throw new IllegalArgumentException("nothing to change");
    }
    ResponderEntryWrapper newResponder = queryExecutor.changeResponder(name, type, conf, base64Cert, this, securityFactory);
    // Update SCEP
    responders.remove(name);
    responderDbEntries.remove(name);
    responderDbEntries.put(name, newResponder.getDbEntry());
    responders.put(name, newResponder);
}
Also used : ResponderEntryWrapper(org.xipki.ca.server.impl.cmp.ResponderEntryWrapper)

Aggregations

ResponderEntryWrapper (org.xipki.ca.server.impl.cmp.ResponderEntryWrapper)5 CaMgmtException (org.xipki.ca.server.mgmt.api.CaMgmtException)3 ResponderEntry (org.xipki.ca.server.mgmt.api.ResponderEntry)2 CertificateException (java.security.cert.CertificateException)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ObjectCreationException (org.xipki.common.ObjectCreationException)1