|
|
@ -229,6 +229,60 @@ public abstract class AbstractCertificateDAOImpl implements CertificateDAO{
|
|
|
|
return certificates;
|
|
|
|
return certificates;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<CertificateResponse> retrieveEmptyDeviceIdCerts() throws CertificateManagementDAOException {
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
|
|
|
|
CertificateResponse certificateResponse = null;
|
|
|
|
|
|
|
|
List<CertificateResponse> certificates = new ArrayList<>();
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
|
|
|
|
String query =
|
|
|
|
|
|
|
|
"SELECT ID, CERTIFICATE FROM DM_DEVICE_CERTIFICATE "
|
|
|
|
|
|
|
|
+ "WHERE DEVICE_IDENTIFIER is NULL";
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(query);
|
|
|
|
|
|
|
|
resultSet = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
|
|
|
|
certificateResponse = new CertificateResponse();
|
|
|
|
|
|
|
|
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
|
|
|
|
|
|
|
certificateResponse.setId(resultSet.getInt("ID"));
|
|
|
|
|
|
|
|
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
|
|
|
|
|
|
|
certificates.add(certificateResponse);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String errorMsg =
|
|
|
|
|
|
|
|
"Error while reading null device identifier certificates";
|
|
|
|
|
|
|
|
log.error(errorMsg, e);
|
|
|
|
|
|
|
|
throw new CertificateManagementDAOException(errorMsg, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
CertificateManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return certificates;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public int updateDeviceIdentifier(CertificateResponse cert) throws CertificateManagementDAOException {
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getConnection();
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(
|
|
|
|
|
|
|
|
"UPDATE DM_DEVICE_CERTIFICATE SET DEVICE_IDENTIFIER = ? WHERE ID = ?");
|
|
|
|
|
|
|
|
stmt.setString(1, cert.getOrganization());
|
|
|
|
|
|
|
|
stmt.setInt(2, cert.getId());
|
|
|
|
|
|
|
|
return stmt.executeUpdate();
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new CertificateManagementDAOException("Error occurred while updating device identifier "
|
|
|
|
|
|
|
|
+ cert.getOrganization() + " of certificate id " + cert.getId()
|
|
|
|
|
|
|
|
, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
CertificateManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<CertificateResponse> getAllCertificates() throws CertificateManagementDAOException {
|
|
|
|
public List<CertificateResponse> getAllCertificates() throws CertificateManagementDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|