Search in sources :

Example 1 with PublisherEntry

use of org.xipki.ca.server.mgmt.api.PublisherEntry in project xipki by xipki.

the class CaManagerQueryExecutor method createPublisher.

// method getNamesFromTable
PublisherEntry createPublisher(String name) throws CaMgmtException {
    final String sql = sqls.sqlSelectPublisher;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        stmt = prepareStatement(sql);
        stmt.setString(1, name);
        rs = stmt.executeQuery();
        if (!rs.next()) {
            throw new CaMgmtException("unkown Publisher " + name);
        }
        int id = rs.getInt("ID");
        String type = rs.getString("TYPE");
        String conf = rs.getString("CONF");
        return new PublisherEntry(new NameId(id, name), type, conf);
    } catch (SQLException ex) {
        throw new CaMgmtException(datasource, sql, ex);
    } finally {
        datasource.releaseResources(stmt, rs);
    }
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) PublisherEntry(org.xipki.ca.server.mgmt.api.PublisherEntry) NameId(org.xipki.ca.api.NameId) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with PublisherEntry

use of org.xipki.ca.server.mgmt.api.PublisherEntry in project xipki by xipki.

the class CaManagerQueryExecutor method changePublisher.

// method changeEnvParam
IdentifiedX509CertPublisher changePublisher(String name, String type, String conf, CaManagerImpl caManager) throws CaMgmtException {
    ParamUtil.requireNonBlank("name", name);
    ParamUtil.requireNonNull("caManager", caManager);
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append("UPDATE PUBLISHER SET ");
    String tmpType = type;
    String tmpConf = conf;
    AtomicInteger index = new AtomicInteger(1);
    Integer idxType = addToSqlIfNotNull(sqlBuilder, index, tmpType, "TYPE");
    Integer idxConf = addToSqlIfNotNull(sqlBuilder, index, tmpConf, "CONF");
    sqlBuilder.deleteCharAt(sqlBuilder.length() - 1);
    sqlBuilder.append(" WHERE NAME=?");
    if (index.get() == 1) {
        throw new IllegalArgumentException("nothing to change");
    }
    PublisherEntry currentDbEntry = createPublisher(name);
    if (tmpType == null) {
        tmpType = currentDbEntry.getType();
    }
    if (tmpConf == null) {
        tmpConf = currentDbEntry.getConf();
    }
    PublisherEntry dbEntry = new PublisherEntry(currentDbEntry.getIdent(), tmpType, tmpConf);
    IdentifiedX509CertPublisher publisher = caManager.createPublisher(dbEntry);
    if (publisher == null) {
        throw new CaMgmtException("could not create publisher object");
    }
    final String sql = sqlBuilder.toString();
    PreparedStatement ps = null;
    try {
        StringBuilder sb = new StringBuilder();
        ps = prepareStatement(sql);
        if (idxType != null) {
            sb.append("type: '").append(tmpType).append("'; ");
            ps.setString(idxType, tmpType);
        }
        if (idxConf != null) {
            String txt = getRealString(tmpConf);
            sb.append("conf: '").append(txt).append("'; ");
            ps.setString(idxConf, getRealString(tmpConf));
        }
        ps.setString(index.get(), name);
        if (ps.executeUpdate() == 0) {
            throw new CaMgmtException("could not change publisher " + name);
        }
        if (sb.length() > 0) {
            sb.deleteCharAt(sb.length() - 1).deleteCharAt(sb.length() - 1);
        }
        LOG.info("changed publisher '{}': {}", name, sb);
        return publisher;
    } 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) PublisherEntry(org.xipki.ca.server.mgmt.api.PublisherEntry) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement)

Example 3 with PublisherEntry

use of org.xipki.ca.server.mgmt.api.PublisherEntry in project xipki by xipki.

the class PublisherInfoCmd method execute0.

@Override
protected Object execute0() throws Exception {
    if (name == null) {
        Set<String> names = caManager.getPublisherNames();
        int size = names.size();
        StringBuilder sb = new StringBuilder();
        if (size == 0 || size == 1) {
            sb.append((size == 0) ? "no" : "1");
            sb.append(" publisher is configured\n");
        } else {
            sb.append(size).append(" publishers are configured:\n");
        }
        List<String> sorted = new ArrayList<>(names);
        Collections.sort(sorted);
        for (String entry : sorted) {
            sb.append("\t").append(entry).append("\n");
        }
        println(sb.toString());
    } else {
        PublisherEntry entry = caManager.getPublisher(name);
        if (entry == null) {
            throw new CmdFailure("\tno publisher named '" + name + "' is configured");
        } else {
            println(entry.toString());
        }
    }
    return null;
}
Also used : PublisherEntry(org.xipki.ca.server.mgmt.api.PublisherEntry) CmdFailure(org.xipki.console.karaf.CmdFailure) ArrayList(java.util.ArrayList)

Example 4 with PublisherEntry

use of org.xipki.ca.server.mgmt.api.PublisherEntry in project xipki by xipki.

the class PublisherCheckCmd method execute0.

@Override
protected Object execute0() throws Exception {
    println("checking publisher " + name);
    PublisherEntry cp = caManager.getPublisher(name);
    if (cp == null) {
        throw new CmdFailure("publisher named '" + name + "' is not configured");
    }
    if (cp.getType() != null) {
        MgmtQaShellUtil.assertEquals("type", type, cp.getType());
    }
    if (cp.getConf() != null) {
        MgmtQaShellUtil.assertEquals("signer conf", conf, cp.getConf());
    }
    println(" checked publisher " + name);
    return null;
}
Also used : PublisherEntry(org.xipki.ca.server.mgmt.api.PublisherEntry) CmdFailure(org.xipki.console.karaf.CmdFailure)

Example 5 with PublisherEntry

use of org.xipki.ca.server.mgmt.api.PublisherEntry in project xipki by xipki.

the class CaPublisherCheckCmd method execute0.

@Override
protected Object execute0() throws Exception {
    println("checking CA publisher CA='" + caName + "', publisher='" + publisherName + "'");
    if (caManager.getCa(caName) == null) {
        throw new CmdFailure("could not find CA '" + caName + "'");
    }
    List<PublisherEntry> entries = caManager.getPublishersForCa(caName);
    String upPublisherName = publisherName.toLowerCase();
    for (PublisherEntry m : entries) {
        if (m.getIdent().getName().equals(upPublisherName)) {
            println(" checked CA publisher CA='" + caName + "', publisher='" + publisherName + "'");
            return null;
        }
    }
    throw new CmdFailure("CA is not associated with publisher '" + publisherName + "'");
}
Also used : PublisherEntry(org.xipki.ca.server.mgmt.api.PublisherEntry) CmdFailure(org.xipki.console.karaf.CmdFailure)

Aggregations

PublisherEntry (org.xipki.ca.server.mgmt.api.PublisherEntry)11 CaMgmtException (org.xipki.ca.server.mgmt.api.CaMgmtException)5 CmdFailure (org.xipki.console.karaf.CmdFailure)5 NameId (org.xipki.ca.api.NameId)3 AddUserEntry (org.xipki.ca.server.mgmt.api.AddUserEntry)3 CaHasRequestorEntry (org.xipki.ca.server.mgmt.api.CaHasRequestorEntry)3 CaHasUserEntry (org.xipki.ca.server.mgmt.api.CaHasUserEntry)3 CertprofileEntry (org.xipki.ca.server.mgmt.api.CertprofileEntry)3 CmpControlEntry (org.xipki.ca.server.mgmt.api.CmpControlEntry)3 RequestorEntry (org.xipki.ca.server.mgmt.api.RequestorEntry)3 ResponderEntry (org.xipki.ca.server.mgmt.api.ResponderEntry)3 UserEntry (org.xipki.ca.server.mgmt.api.UserEntry)3 ScepEntry (org.xipki.ca.server.mgmt.api.x509.ScepEntry)3 X509CaEntry (org.xipki.ca.server.mgmt.api.x509.X509CaEntry)3 X509CrlSignerEntry (org.xipki.ca.server.mgmt.api.x509.X509CrlSignerEntry)3 IOException (java.io.IOException)2 CertificateEncodingException (java.security.cert.CertificateEncodingException)2 X509Certificate (java.security.cert.X509Certificate)2 PreparedStatement (java.sql.PreparedStatement)2 SQLException (java.sql.SQLException)2