use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.
the class CaManagerQueryExecutor method addCaAlias.
// method addCa
void addCaAlias(String aliasName, NameId ca) throws CaMgmtException {
ParamUtil.requireNonNull("aliasName", aliasName);
ParamUtil.requireNonNull("ca", ca);
final String sql = "INSERT INTO CAALIAS (NAME,CA_ID) VALUES (?,?)";
PreparedStatement ps = null;
try {
ps = prepareStatement(sql);
ps.setString(1, aliasName);
ps.setInt(2, ca.getId());
if (ps.executeUpdate() == 0) {
throw new CaMgmtException("could not add CA alias " + aliasName);
}
LOG.info("added CA alias '{}' for CA '{}'", aliasName, ca);
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(ps, null);
}
}
use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.
the class CaManagerQueryExecutor method getUser.
UserEntry getUser(String username, boolean nullable) throws CaMgmtException {
ParamUtil.requireNonNull("username", username);
NameId ident = new NameId(null, username);
final String sql = sqls.sqlSelectUser;
ResultSet rs = null;
PreparedStatement ps = null;
try {
ps = prepareStatement(sql);
int idx = 1;
ps.setString(idx++, ident.getName());
rs = ps.executeQuery();
if (!rs.next()) {
if (nullable) {
return null;
} else {
throw new CaMgmtException("unknown user " + username);
}
}
int id = rs.getInt("ID");
ident.setId(id);
boolean active = rs.getBoolean("ACTIVE");
String hashedPassword = rs.getString("PASSWORD");
return new UserEntry(ident, active, hashedPassword);
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(ps, rs);
}
}
use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.
the class CaManagerQueryExecutor method getCaHasUsersForUser.
// method addUserToCa
Map<String, CaHasUserEntry> getCaHasUsersForUser(String user, CaIdNameMap idNameMap) throws CaMgmtException {
Integer existingId = getIdForName(sqls.sqlSelectUserId, user);
if (existingId == null) {
throw new CaMgmtException(concat("user '", user, " ' does not exist"));
}
final String sql = "SELECT CA_ID,PERMISSION,PROFILES FROM CA_HAS_USER WHERE USER_ID=?";
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = prepareStatement(sql);
ps.setInt(1, existingId);
rs = ps.executeQuery();
Map<String, CaHasUserEntry> ret = new HashMap<>();
while (rs.next()) {
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);
CaHasUserEntry caHasUser = new CaHasUserEntry(new NameId(existingId, user));
caHasUser.setPermission(permission);
caHasUser.setProfiles(profiles);
int caId = rs.getInt("CA_ID");
String caName = idNameMap.getCaName(caId);
ret.put(caName, caHasUser);
}
return ret;
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(ps, rs);
}
}
use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.
the class CaManagerQueryExecutor method createResponder.
// method createCmpControl
ResponderEntry createResponder(String name) throws CaMgmtException {
final String sql = sqls.sqlSelectResponder;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
stmt = prepareStatement(sql);
stmt.setString(1, name);
rs = stmt.executeQuery();
if (!rs.next()) {
throw new CaMgmtException("unknown responder " + name);
}
String type = rs.getString("TYPE");
String conf = rs.getString("CONF");
String b64Cert = rs.getString("CERT");
return new ResponderEntry(name, type, conf, b64Cert);
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(stmt, rs);
}
}
use of org.xipki.ca.server.mgmt.api.CaMgmtException in project xipki by xipki.
the class CaManagerQueryExecutor method addEnvParam.
private void addEnvParam(String name, String value, boolean force) throws CaMgmtException {
ParamUtil.requireNonBlank("name", name);
ParamUtil.requireNonNull("value", value);
if (!force) {
if (CaManagerImpl.ENV_EPOCH.equalsIgnoreCase(name)) {
throw new CaMgmtException("environment " + name + " is reserved");
}
}
final String sql = "INSERT INTO ENVIRONMENT (NAME,VALUE2) VALUES (?,?)";
PreparedStatement ps = null;
try {
ps = prepareStatement(sql);
ps.setString(1, name);
ps.setString(2, value);
if (ps.executeUpdate() == 0) {
throw new CaMgmtException("could not add environment param " + name);
}
LOG.info("added environment param '{}': {}", name, value);
} catch (SQLException ex) {
throw new CaMgmtException(datasource, sql, ex);
} finally {
datasource.releaseResources(ps, null);
}
}
Aggregations