Search in sources :

Example 11 with CaMgmtException

use of org.xipki.ca.server.mgmt.api.CaMgmtException 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 12 with CaMgmtException

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

the class CaManagerQueryExecutor method getScep.

// method removeScep
ScepEntry getScep(String name, CaIdNameMap idNameMap) throws CaMgmtException {
    ParamUtil.requireNonBlank("name", name);
    final String sql = sqls.sqlSelectScep;
    ResultSet rs = null;
    PreparedStatement ps = null;
    try {
        ps = prepareStatement(sql);
        ps.setString(1, name);
        rs = ps.executeQuery();
        if (!rs.next()) {
            throw new CaMgmtException("unknown SCEP " + name);
        }
        int caId = rs.getInt("CA_ID");
        boolean active = rs.getBoolean("ACTIVE");
        String profilesText = rs.getString("PROFILES");
        String control = rs.getString("CONTROL");
        String responderName = rs.getString("RESPONDER_NAME");
        Set<String> profiles = StringUtil.splitByCommaAsSet(profilesText);
        return new ScepEntry(name, idNameMap.getCa(caId), active, responderName, profiles, control);
    } catch (SQLException ex) {
        throw new CaMgmtException(datasource, sql, ex);
    } catch (InvalidConfException ex) {
        throw new CaMgmtException(ex);
    } finally {
        datasource.releaseResources(ps, rs);
    }
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) InvalidConfException(org.xipki.common.InvalidConfException) PreparedStatement(java.sql.PreparedStatement) ScepEntry(org.xipki.ca.server.mgmt.api.x509.ScepEntry)

Example 13 with CaMgmtException

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

the class CaManagerQueryExecutor method revokeCa.

// method removePublisherFromCa
void revokeCa(String caName, CertRevocationInfo revocationInfo) throws CaMgmtException {
    ParamUtil.requireNonBlank("caName", caName);
    ParamUtil.requireNonNull("revocationInfo", revocationInfo);
    String sql = "UPDATE CA SET REV=?,RR=?,RT=?,RIT=? WHERE NAME=?";
    PreparedStatement ps = null;
    try {
        if (revocationInfo.getInvalidityTime() == null) {
            revocationInfo.setInvalidityTime(revocationInfo.getRevocationTime());
        }
        ps = prepareStatement(sql);
        int idx = 1;
        setBoolean(ps, idx++, true);
        ps.setInt(idx++, revocationInfo.getReason().getCode());
        ps.setLong(idx++, revocationInfo.getRevocationTime().getTime() / 1000);
        ps.setLong(idx++, revocationInfo.getInvalidityTime().getTime() / 1000);
        ps.setString(idx++, caName);
        if (ps.executeUpdate() == 0) {
            throw new CaMgmtException("could not revoke CA " + caName);
        }
    } catch (SQLException ex) {
        throw new CaMgmtException(datasource, sql, ex);
    } finally {
        datasource.releaseResources(ps, null);
    }
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement)

Example 14 with CaMgmtException

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

the class CaManagerQueryExecutor method removeCaAlias.

// method removeCa
void removeCaAlias(String aliasName) throws CaMgmtException {
    ParamUtil.requireNonBlank("aliasName", aliasName);
    final String sql = "DELETE FROM CAALIAS WHERE NAME=?";
    PreparedStatement ps = null;
    try {
        ps = prepareStatement(sql);
        ps.setString(1, aliasName);
        if (ps.executeUpdate() == 0) {
            throw new CaMgmtException("could not remove CA Alias " + aliasName);
        }
    } catch (SQLException ex) {
        throw new CaMgmtException(datasource, sql, ex);
    } finally {
        datasource.releaseResources(ps, null);
    }
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement)

Example 15 with CaMgmtException

use of org.xipki.ca.server.mgmt.api.CaMgmtException 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)

Aggregations

CaMgmtException (org.xipki.ca.server.mgmt.api.CaMgmtException)157 PreparedStatement (java.sql.PreparedStatement)63 SQLException (java.sql.SQLException)63 CmdFailure (org.xipki.console.karaf.CmdFailure)52 NameId (org.xipki.ca.api.NameId)31 ResultSet (java.sql.ResultSet)24 OperationException (org.xipki.ca.api.OperationException)18 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)16 InvalidConfException (org.xipki.common.InvalidConfException)11 DataAccessException (org.xipki.datasource.DataAccessException)11 CertificateEncodingException (java.security.cert.CertificateEncodingException)9 CaHasRequestorEntry (org.xipki.ca.server.mgmt.api.CaHasRequestorEntry)9 CertificateException (java.security.cert.CertificateException)8 ObjectCreationException (org.xipki.common.ObjectCreationException)8 X509Certificate (java.security.cert.X509Certificate)7 Date (java.util.Date)7 X509CaEntry (org.xipki.ca.server.mgmt.api.x509.X509CaEntry)7 IOException (java.io.IOException)6 Statement (java.sql.Statement)6 CaHasUserEntry (org.xipki.ca.server.mgmt.api.CaHasUserEntry)6