Search in sources :

Example 1 with ScepImpl

use of org.xipki.ca.server.impl.scep.ScepImpl in project xipki by xipki.

the class CaManagerImpl method initSceps.

// method initCmpControls
private void initSceps() throws CaMgmtException {
    if (scepsInitialized) {
        return;
    }
    sceps.clear();
    scepDbEntries.clear();
    List<String> names = queryExecutor.namesFromTable("SCEP");
    for (String name : names) {
        ScepEntry scepDb = queryExecutor.getScep(name, idNameMap);
        if (scepDb == null) {
            continue;
        }
        scepDbEntries.put(name, scepDb);
        try {
            ScepImpl scep = new ScepImpl(scepDb, this);
            sceps.put(name, scep);
        } catch (CaMgmtException ex) {
            LogUtil.error(LOG, ex, concat("could not initialize SCEP entry ", name, ", ignore it"));
        }
    }
    scepsInitialized = true;
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) ScepImpl(org.xipki.ca.server.impl.scep.ScepImpl) ChangeScepEntry(org.xipki.ca.server.mgmt.api.x509.ChangeScepEntry) ScepEntry(org.xipki.ca.server.mgmt.api.x509.ScepEntry)

Example 2 with ScepImpl

use of org.xipki.ca.server.impl.scep.ScepImpl in project xipki by xipki.

the class CaManagerImpl method addScep.

// method getCurrentCrl
@Override
public void addScep(ScepEntry dbEntry) throws CaMgmtException {
    ParamUtil.requireNonNull("dbEntry", dbEntry);
    asssertMasterMode();
    final String name = dbEntry.getName();
    if (scepDbEntries.containsKey(name)) {
        throw new CaMgmtException(concat("SCEP named ", name, " exists"));
    }
    String caName = dbEntry.getCaIdent().getName();
    NameId caIdent = idNameMap.getCa(caName);
    if (caIdent == null) {
        String msg = concat("unknown CA ", caName);
        LOG.warn(msg);
        throw new CaMgmtException(msg);
    }
    dbEntry.getCaIdent().setId(caIdent.getId());
    ScepImpl scep = new ScepImpl(dbEntry, this);
    queryExecutor.addScep(dbEntry);
    scepDbEntries.put(name, dbEntry);
    sceps.put(name, scep);
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) NameId(org.xipki.ca.api.NameId) ScepImpl(org.xipki.ca.server.impl.scep.ScepImpl)

Example 3 with ScepImpl

use of org.xipki.ca.server.impl.scep.ScepImpl in project xipki by xipki.

the class CaManagerImpl method changeScep.

// method removeScep
public void changeScep(ChangeScepEntry scepEntry) throws CaMgmtException {
    ParamUtil.requireNonNull("scepEntry", scepEntry);
    asssertMasterMode();
    String name = scepEntry.getName();
    NameId caId = scepEntry.getCaIdent();
    Boolean active = scepEntry.getActive();
    String responderName = scepEntry.getResponderName();
    String control = scepEntry.getControl();
    if (caId == null && responderName == null && control == null) {
        throw new IllegalArgumentException("nothing to change or SCEP " + name);
    }
    if (caId != null && caId.getId() == null) {
        String caName = caId.getName();
        caId = idNameMap.getCa(caName);
        if (caId == null) {
            throw new CaMgmtException(concat("Unknown CA ", caName));
        }
    }
    ScepImpl scep = queryExecutor.changeScep(name, caId, active, responderName, scepEntry.getCertProfiles(), control, this, securityFactory);
    if (scep == null) {
        throw new CaMgmtException("could not chagne SCEP " + name);
    }
    sceps.remove(name);
    scepDbEntries.remove(name);
    scepDbEntries.put(name, scep.getDbEntry());
    sceps.put(name, scep);
}
Also used : CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) NameId(org.xipki.ca.api.NameId) ScepImpl(org.xipki.ca.server.impl.scep.ScepImpl)

Example 4 with ScepImpl

use of org.xipki.ca.server.impl.scep.ScepImpl in project xipki by xipki.

the class CaManagerQueryExecutor method changeScep.

// method changeCrlSigner
ScepImpl changeScep(String name, NameId caIdent, Boolean active, String responderName, Set<String> certProfiles, String control, CaManagerImpl caManager, final SecurityFactory securityFactory) throws CaMgmtException {
    ParamUtil.requireNonBlank("name", name);
    ParamUtil.requireNonNull("caManager", caManager);
    StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append("UPDATE SCEP SET ");
    AtomicInteger index = new AtomicInteger(1);
    Integer idxCa = addToSqlIfNotNull(sqlBuilder, index, caIdent, "CA_ID");
    Integer idxActive = addToSqlIfNotNull(sqlBuilder, index, active, "ACTIVE");
    Integer idxName = addToSqlIfNotNull(sqlBuilder, index, responderName, "RESPONDER_NAME");
    Integer idxProfiles = addToSqlIfNotNull(sqlBuilder, index, certProfiles, "PROFILES");
    Integer idxControl = addToSqlIfNotNull(sqlBuilder, index, control, "CONTROL");
    sqlBuilder.deleteCharAt(sqlBuilder.length() - 1);
    sqlBuilder.append(" WHERE NAME=?");
    if (index.get() == 1) {
        throw new IllegalArgumentException("nothing to change");
    }
    ScepEntry dbEntry = getScep(name, caManager.idNameMap());
    boolean tmpActive = (active == null) ? dbEntry.isActive() : active;
    String tmpResponderName = (responderName == null) ? dbEntry.getResponderName() : responderName;
    NameId tmpCaIdent;
    if (caIdent == null) {
        tmpCaIdent = dbEntry.getCaIdent();
    } else {
        tmpCaIdent = caIdent;
    }
    Set<String> tmpCertProfiles;
    if (certProfiles == null) {
        tmpCertProfiles = dbEntry.getCertProfiles();
    } else {
        tmpCertProfiles = certProfiles;
    }
    String tmpControl;
    if (control == null) {
        tmpControl = dbEntry.getControl();
    } else if (CaManager.NULL.equals(control)) {
        tmpControl = null;
    } else {
        tmpControl = control;
    }
    ScepEntry newDbEntry;
    try {
        newDbEntry = new ScepEntry(name, tmpCaIdent, tmpActive, tmpResponderName, tmpCertProfiles, tmpControl);
    } catch (InvalidConfException ex) {
        throw new CaMgmtException(ex);
    }
    ScepImpl scep = new ScepImpl(newDbEntry, caManager);
    final String sql = sqlBuilder.toString();
    StringBuilder sb = new StringBuilder();
    PreparedStatement ps = null;
    try {
        ps = prepareStatement(sql);
        if (idxActive != null) {
            setBoolean(ps, idxActive, tmpActive);
            sb.append("active: '").append(tmpActive).append("'; ");
        }
        if (idxCa != null) {
            sb.append("ca: '").append(caIdent).append("'; ");
            ps.setInt(idxCa, caIdent.getId());
        }
        if (idxName != null) {
            String txt = getRealString(tmpResponderName);
            ps.setString(idxName, txt);
            sb.append("responder type: '").append(txt).append("'; ");
        }
        if (idxProfiles != null) {
            sb.append("profiles: '").append(certProfiles).append("'; ");
            ps.setString(idxProfiles, StringUtil.collectionAsStringByComma(certProfiles));
        }
        if (idxControl != null) {
            String txt = getRealString(tmpControl);
            sb.append("control: '").append(tmpControl);
            ps.setString(idxControl, txt);
        }
        if (idxCa != null) {
            sb.append("ca: ").append(caIdent);
            ps.setInt(idxCa, caIdent.getId());
        }
        ps.setString(index.get(), name);
        if (ps.executeUpdate() == 0) {
            throw new CaMgmtException("could not change SCEP " + name);
        }
        final int sbLen = sb.length();
        if (sbLen > 0) {
            sb.delete(sbLen - 2, sbLen);
        }
        LOG.info("changed SCEP: {}", sb);
        return scep;
    } catch (SQLException ex) {
        throw new CaMgmtException(datasource, sql, ex);
    } finally {
        datasource.releaseResources(ps, null);
    }
}
Also used : NameId(org.xipki.ca.api.NameId) SQLException(java.sql.SQLException) InvalidConfException(org.xipki.common.InvalidConfException) ScepImpl(org.xipki.ca.server.impl.scep.ScepImpl) PreparedStatement(java.sql.PreparedStatement) ScepEntry(org.xipki.ca.server.mgmt.api.x509.ScepEntry) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CaMgmtException(org.xipki.ca.server.mgmt.api.CaMgmtException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Aggregations

ScepImpl (org.xipki.ca.server.impl.scep.ScepImpl)4 CaMgmtException (org.xipki.ca.server.mgmt.api.CaMgmtException)4 NameId (org.xipki.ca.api.NameId)3 ScepEntry (org.xipki.ca.server.mgmt.api.x509.ScepEntry)2 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 ChangeScepEntry (org.xipki.ca.server.mgmt.api.x509.ChangeScepEntry)1 InvalidConfException (org.xipki.common.InvalidConfException)1