Search in sources :

Example 36 with CaMgmtException

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

the class CaManagerQueryExecutor method changeEnvParam.

// method changeScep
void changeEnvParam(String name, String value) throws CaMgmtException {
    ParamUtil.requireNonBlank("name", name);
    ParamUtil.requireNonNull("value", value);
    if (CaManagerImpl.ENV_EPOCH.equalsIgnoreCase(name)) {
        throw new CaMgmtException(concat("environment ", name, " is reserved"));
    }
    final String sql = "UPDATE ENVIRONMENT SET VALUE2=? WHERE NAME=?";
    PreparedStatement ps = null;
    try {
        ps = prepareStatement(sql);
        ps.setString(1, getRealString(value));
        ps.setString(2, name);
        if (ps.executeUpdate() == 0) {
            throw new CaMgmtException("could not change environment param " + name);
        }
        LOG.info("changed environment param '{}': {}", name, value);
    } 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 37 with CaMgmtException

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

the class CaManagerQueryExecutor method createCaHasRequestors.

// method createCaInfo
Set<CaHasRequestorEntry> createCaHasRequestors(NameId ca) throws CaMgmtException {
    Map<Integer, String> idNameMap = getIdNameMap("REQUESTOR");
    final String sql = "SELECT REQUESTOR_ID,RA,PERMISSION,PROFILES FROM CA_HAS_REQUESTOR WHERE CA_ID=?";
    PreparedStatement stmt = null;
    ResultSet rs = null;
    try {
        stmt = prepareStatement(sql);
        stmt.setInt(1, ca.getId());
        rs = stmt.executeQuery();
        Set<CaHasRequestorEntry> ret = new HashSet<>();
        while (rs.next()) {
            int id = rs.getInt("REQUESTOR_ID");
            String name = idNameMap.get(id);
            boolean ra = rs.getBoolean("RA");
            int permission = rs.getInt("PERMISSION");
            String str = rs.getString("PROFILES");
            List<String> list = StringUtil.splitByComma(str);
            Set<String> profiles = (list == null) ? null : new HashSet<>(list);
            CaHasRequestorEntry entry = new CaHasRequestorEntry(new NameId(id, name));
            entry.setRa(ra);
            entry.setPermission(permission);
            entry.setProfiles(profiles);
            ret.add(entry);
        }
        return ret;
    } catch (SQLException ex) {
        throw new CaMgmtException(datasource, sql, ex);
    } finally {
        datasource.releaseResources(stmt, rs);
    }
}
Also used : NameId(org.xipki.ca.api.NameId) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) ResultSet(java.sql.ResultSet) CaHasRequestorEntry(org.xipki.ca.server.mgmt.api.CaHasRequestorEntry) HashSet(java.util.HashSet)

Example 38 with CaMgmtException

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

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

the class CaManagerImpl method generateCrlOnDemand.

@Override
public X509CRL generateCrlOnDemand(String caName) throws CaMgmtException {
    caName = ParamUtil.requireNonBlank("caName", caName).toLowerCase();
    X509Ca ca = getX509Ca(caName);
    try {
        return ca.generateCrlOnDemand(CaAuditConstants.MSGID_ca_mgmt);
    } catch (OperationException ex) {
        throw new CaMgmtException(ex.getMessage(), ex);
    }
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) OperationException(org.xipki.ca.api.OperationException)

Example 40 with CaMgmtException

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

the class CaManagerImpl method createPublisher.

// method createCertprofile
IdentifiedX509CertPublisher createPublisher(PublisherEntry dbEntry) throws CaMgmtException {
    ParamUtil.requireNonNull("dbEntry", dbEntry);
    String type = dbEntry.getType();
    X509CertPublisher publisher;
    IdentifiedX509CertPublisher ret;
    try {
        if ("OCSP".equalsIgnoreCase(type)) {
            publisher = new OcspCertPublisher();
        } else {
            publisher = x509CertPublisherFactoryRegister.newPublisher(type);
        }
        ret = new IdentifiedX509CertPublisher(dbEntry, publisher);
        ret.initialize(securityFactory.getPasswordResolver(), datasources);
        return ret;
    } catch (ObjectCreationException | CertPublisherException | RuntimeException ex) {
        String msg = "invalid configuration for the publisher " + dbEntry.getIdent();
        LogUtil.error(LOG, ex, msg);
        throw new CaMgmtException(msg, ex);
    }
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) OcspCertPublisher(org.xipki.ca.server.impl.ocsp.OcspCertPublisher) X509CertPublisher(org.xipki.ca.api.publisher.x509.X509CertPublisher) ObjectCreationException(org.xipki.common.ObjectCreationException) CertPublisherException(org.xipki.ca.api.publisher.CertPublisherException)

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