Search in sources :

Example 1 with RequestorEntryWrapper

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

the class CaManagerImpl method addRequestor.

@Override
public void addRequestor(RequestorEntry dbEntry) throws CaMgmtException {
    ParamUtil.requireNonNull("dbEntry", dbEntry);
    asssertMasterMode();
    String name = dbEntry.getIdent().getName();
    if (requestorDbEntries.containsKey(name)) {
        throw new CaMgmtException(concat("Requestor named ", name, " exists"));
    }
    RequestorEntryWrapper requestor = new RequestorEntryWrapper();
    requestor.setDbEntry(dbEntry);
    queryExecutor.addRequestor(dbEntry);
    idNameMap.addRequestor(dbEntry.getIdent());
    requestorDbEntries.put(name, dbEntry);
    requestors.put(name, requestor);
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) RequestorEntryWrapper(org.xipki.ca.server.impl.cmp.RequestorEntryWrapper)

Example 2 with RequestorEntryWrapper

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

the class CaManagerImpl method changeRequestor.

// method removeRequestor
@Override
public void changeRequestor(String name, String base64Cert) throws CaMgmtException {
    ParamUtil.requireNonNull("base64Cert", base64Cert);
    name = ParamUtil.requireNonBlank("name", name).toLowerCase();
    asssertMasterMode();
    NameId ident = idNameMap.getRequestor(name);
    if (ident == null) {
        String msg = concat("unknown requestor ", name);
        LOG.warn(msg);
        throw new CaMgmtException(msg);
    }
    RequestorEntryWrapper requestor = queryExecutor.changeRequestor(ident, base64Cert);
    requestorDbEntries.remove(name);
    requestors.remove(name);
    requestorDbEntries.put(name, requestor.getDbEntry());
    requestors.put(name, requestor);
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) NameId(org.xipki.ca.api.NameId) RequestorEntryWrapper(org.xipki.ca.server.impl.cmp.RequestorEntryWrapper)

Example 3 with RequestorEntryWrapper

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

the class CaManagerImpl method initRequestors.

private void initRequestors() throws CaMgmtException {
    if (requestorsInitialized) {
        return;
    }
    idNameMap.clearRequestor();
    requestorDbEntries.clear();
    requestors.clear();
    List<String> names = queryExecutor.namesFromTable("REQUESTOR");
    for (String name : names) {
        if (RequestorInfo.NAME_BY_CA.equals(name)) {
            Integer id = queryExecutor.getRequestorId(name);
            NameId ident = new NameId(id, name);
            byCaRequestor = new ByCaRequestorInfo(ident);
            idNameMap.addRequestor(ident);
        } else if (RequestorInfo.NAME_BY_USER.equals(name)) {
            Integer id = queryExecutor.getRequestorId(name);
            byUserRequestorId = new NameId(id, name);
            idNameMap.addRequestor(byUserRequestorId);
        } else {
            RequestorEntry requestorDbEntry = queryExecutor.createRequestor(name);
            if (requestorDbEntry == null) {
                continue;
            }
            idNameMap.addRequestor(requestorDbEntry.getIdent());
            requestorDbEntries.put(name, requestorDbEntry);
            RequestorEntryWrapper requestor = new RequestorEntryWrapper();
            requestor.setDbEntry(requestorDbEntry);
            requestors.put(name, requestor);
        }
    }
    requestorsInitialized = true;
}
Also used : BigInteger(java.math.BigInteger) NameId(org.xipki.ca.api.NameId) RequestorEntry(org.xipki.ca.server.mgmt.api.RequestorEntry) CaHasRequestorEntry(org.xipki.ca.server.mgmt.api.CaHasRequestorEntry) RequestorEntryWrapper(org.xipki.ca.server.impl.cmp.RequestorEntryWrapper)

Example 4 with RequestorEntryWrapper

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

the class CaManagerQueryExecutor method changeRequestor.

// method changeCmpControl
RequestorEntryWrapper changeRequestor(NameId nameId, String base64Cert) throws CaMgmtException {
    ParamUtil.requireNonNull("nameId", nameId);
    RequestorEntry newDbEntry = new RequestorEntry(nameId, base64Cert);
    RequestorEntryWrapper requestor = new RequestorEntryWrapper();
    requestor.setDbEntry(newDbEntry);
    final String sql = "UPDATE REQUESTOR SET CERT=? WHERE ID=?";
    PreparedStatement ps = null;
    try {
        ps = prepareStatement(sql);
        String b64Cert = getRealString(base64Cert);
        ps.setString(1, b64Cert);
        ps.setInt(2, nameId.getId());
        if (ps.executeUpdate() == 0) {
            throw new CaMgmtException("could not change requestor " + nameId);
        }
        String subject = null;
        if (b64Cert != null) {
            try {
                subject = canonicalizName(X509Util.parseBase64EncodedCert(b64Cert).getSubjectX500Principal());
            } catch (CertificateException ex) {
                subject = "ERROR";
            }
        }
        LOG.info("changed requestor '{}': {}", nameId, subject);
        return requestor;
    } 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) RequestorEntry(org.xipki.ca.server.mgmt.api.RequestorEntry) CaHasRequestorEntry(org.xipki.ca.server.mgmt.api.CaHasRequestorEntry) RequestorEntryWrapper(org.xipki.ca.server.impl.cmp.RequestorEntryWrapper) PreparedStatement(java.sql.PreparedStatement) CertificateException(java.security.cert.CertificateException)

Aggregations

RequestorEntryWrapper (org.xipki.ca.server.impl.cmp.RequestorEntryWrapper)4 CaMgmtException (org.xipki.ca.server.mgmt.api.CaMgmtException)3 NameId (org.xipki.ca.api.NameId)2 CaHasRequestorEntry (org.xipki.ca.server.mgmt.api.CaHasRequestorEntry)2 RequestorEntry (org.xipki.ca.server.mgmt.api.RequestorEntry)2 BigInteger (java.math.BigInteger)1 CertificateException (java.security.cert.CertificateException)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1