Additional changes. Went to Hibernate 6, encountered issues with the

version of java.  Backed down to 5 but ran into different issues
This commit is contained in:
Cyrus 2022-06-27 06:44:29 -04:00
parent c426cec978
commit 2971459f32
40 changed files with 201 additions and 113 deletions

View File

@ -30,7 +30,6 @@ import hirs.data.persist.info.TPMInfo;
import hirs.data.service.DeviceRegister; import hirs.data.service.DeviceRegister;
import hirs.persist.CertificateManager; import hirs.persist.CertificateManager;
import hirs.persist.DeviceManager; import hirs.persist.DeviceManager;
import hirs.persist.ReferenceDigestManager;
import hirs.persist.ReferenceEventManager; import hirs.persist.ReferenceEventManager;
import hirs.persist.ReferenceManifestManager; import hirs.persist.ReferenceManifestManager;
import hirs.persist.TPM2ProvisionerState; import hirs.persist.TPM2ProvisionerState;
@ -179,7 +178,6 @@ public abstract class AbstractAttestationCertificateAuthority
private final ReferenceManifestManager referenceManifestManager; private final ReferenceManifestManager referenceManifestManager;
private final DeviceRegister deviceRegister; private final DeviceRegister deviceRegister;
private final DeviceManager deviceManager; private final DeviceManager deviceManager;
private final ReferenceDigestManager referenceDigestManager;
private final ReferenceEventManager referenceEventManager; private final ReferenceEventManager referenceEventManager;
private String tpmQuoteHash = ""; private String tpmQuoteHash = "";
private String tpmQuoteSignature = ""; private String tpmQuoteSignature = "";
@ -195,7 +193,6 @@ public abstract class AbstractAttestationCertificateAuthority
* @param deviceRegister the device register * @param deviceRegister the device register
* @param validDays the number of days issued certs are valid * @param validDays the number of days issued certs are valid
* @param deviceManager the device manager * @param deviceManager the device manager
* @param referenceDigestManager the reference digest manager
* @param referenceEventManager the reference event manager * @param referenceEventManager the reference event manager
*/ */
@SuppressWarnings("checkstyle:parameternumber") @SuppressWarnings("checkstyle:parameternumber")
@ -207,7 +204,6 @@ public abstract class AbstractAttestationCertificateAuthority
final ReferenceManifestManager referenceManifestManager, final ReferenceManifestManager referenceManifestManager,
final DeviceRegister deviceRegister, final int validDays, final DeviceRegister deviceRegister, final int validDays,
final DeviceManager deviceManager, final DeviceManager deviceManager,
final ReferenceDigestManager referenceDigestManager,
final ReferenceEventManager referenceEventManager) { final ReferenceEventManager referenceEventManager) {
this.supplyChainValidationService = supplyChainValidationService; this.supplyChainValidationService = supplyChainValidationService;
this.privateKey = privateKey; this.privateKey = privateKey;
@ -218,7 +214,6 @@ public abstract class AbstractAttestationCertificateAuthority
this.deviceRegister = deviceRegister; this.deviceRegister = deviceRegister;
this.validDays = validDays; this.validDays = validDays;
this.deviceManager = deviceManager; this.deviceManager = deviceManager;
this.referenceDigestManager = referenceDigestManager;
this.referenceEventManager = referenceEventManager; this.referenceEventManager = referenceEventManager;
} }

View File

@ -5,7 +5,6 @@ import hirs.attestationca.service.SupplyChainValidationService;
import hirs.data.service.DeviceRegister; import hirs.data.service.DeviceRegister;
import hirs.persist.CertificateManager; import hirs.persist.CertificateManager;
import hirs.persist.DeviceManager; import hirs.persist.DeviceManager;
import hirs.persist.ReferenceDigestManager;
import hirs.persist.ReferenceEventManager; import hirs.persist.ReferenceEventManager;
import hirs.persist.ReferenceManifestManager; import hirs.persist.ReferenceManifestManager;
import hirs.structs.converters.StructConverter; import hirs.structs.converters.StructConverter;
@ -41,7 +40,6 @@ public class RestfulAttestationCertificateAuthority
* @param deviceRegister the device register * @param deviceRegister the device register
* @param validDays the number of days issued certs are valid * @param validDays the number of days issued certs are valid
* @param deviceManager the device manager * @param deviceManager the device manager
* @param referenceDigestManager the reference digest manager
* @param referenceEventManager the reference event manager * @param referenceEventManager the reference event manager
*/ */
@SuppressWarnings({ "checkstyle:parameternumber" }) @SuppressWarnings({ "checkstyle:parameternumber" })
@ -54,13 +52,12 @@ public class RestfulAttestationCertificateAuthority
final ReferenceManifestManager referenceManifestManager, final ReferenceManifestManager referenceManifestManager,
final DeviceRegister deviceRegister, final DeviceRegister deviceRegister,
final DeviceManager deviceManager, final DeviceManager deviceManager,
final ReferenceDigestManager referenceDigestManager,
final ReferenceEventManager referenceEventManager, final ReferenceEventManager referenceEventManager,
@Value("${aca.certificates.validity}") final int validDays) { @Value("${aca.certificates.validity}") final int validDays) {
super(supplyChainValidationService, privateKey, acaCertificate, structConverter, super(supplyChainValidationService, privateKey, acaCertificate, structConverter,
certificateManager, referenceManifestManager, certificateManager, referenceManifestManager,
deviceRegister, validDays, deviceManager, deviceRegister, validDays, deviceManager,
referenceDigestManager, referenceEventManager); referenceEventManager);
} }
/* /*

View File

@ -132,7 +132,7 @@ public class AbstractAttestationCertificateAuthorityTest {
public void setup() { public void setup() {
aca = new AbstractAttestationCertificateAuthority(null, keyPair.getPrivate(), aca = new AbstractAttestationCertificateAuthority(null, keyPair.getPrivate(),
null, null, null, null, null, 1, null, null, null, null, null, 1,
null, null, null) { null, null) {
}; };
} }

View File

@ -7,6 +7,8 @@ import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.multipart.commons.CommonsMultipartResolver; import org.springframework.web.multipart.commons.CommonsMultipartResolver;
import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc;
@ -19,7 +21,9 @@ import java.nio.charset.StandardCharsets;
* Specifies the location to scan for page controllers, view resolver for JSON data, and view * Specifies the location to scan for page controllers, view resolver for JSON data, and view
* resolver to map view names to jsp files. * resolver to map view names to jsp files.
*/ */
@Repository
@Configuration @Configuration
@EnableTransactionManagement
@EnableWebMvc @EnableWebMvc
@ComponentScan("hirs.attestationca.portal.page.controllers") @ComponentScan("hirs.attestationca.portal.page.controllers")
@Import({ PersistenceConfiguration.class }) @Import({ PersistenceConfiguration.class })

View File

@ -8,9 +8,9 @@ import hirs.persist.CertificateManager;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.io.IOException; import java.io.IOException;
@ -22,8 +22,8 @@ import static hirs.attestationca.portal.page.Page.CERTIFICATE_DETAILS;
/** /**
* Controller for the Certificate Details page. * Controller for the Certificate Details page.
*/ */
@Controller @RestController
@RequestMapping("/certificate-details") @RequestMapping(path = "/certificate-details")
public class CertificateDetailsPageController extends PageController<CertificateDetailsPageParams> { public class CertificateDetailsPageController extends PageController<CertificateDetailsPageParams> {
/** /**
@ -31,6 +31,7 @@ public class CertificateDetailsPageController extends PageController<Certificate
*/ */
static final String INITIAL_DATA = "initialData"; static final String INITIAL_DATA = "initialData";
@Autowired
private final CertificateManager certificateManager; private final CertificateManager certificateManager;
private static final Logger LOGGER = private static final Logger LOGGER =
LogManager.getLogger(CertificateDetailsPageController.class); LogManager.getLogger(CertificateDetailsPageController.class);

View File

@ -26,14 +26,15 @@ import org.hibernate.criterion.Restrictions;
import org.hibernate.sql.JoinType; import org.hibernate.sql.JoinType;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@ -57,11 +58,13 @@ import static org.apache.logging.log4j.LogManager.getLogger;
/** /**
* Controller for the Certificates list all pages. * Controller for the Certificates list all pages.
*/ */
@Controller @RestController
@RequestMapping("/certificate-request") @RequestMapping(path = "/certificate-request")
public class CertificateRequestPageController extends PageController<NoPageParams> { public class CertificateRequestPageController extends PageController<NoPageParams> {
@Autowired
private final CertificateManager certificateManager; private final CertificateManager certificateManager;
@Autowired
private final OrderedListQuerier<Certificate> dataTableQuerier; private final OrderedListQuerier<Certificate> dataTableQuerier;
private CertificateAuthorityCredential certificateAuthorityCredential; private CertificateAuthorityCredential certificateAuthorityCredential;
@ -127,6 +130,7 @@ public class CertificateRequestPageController extends PageController<NoPageParam
* redirect. * redirect.
* @return the path for the view and data model for the page. * @return the path for the view and data model for the page.
*/ */
@GetMapping
@RequestMapping("/{certificateType}") @RequestMapping("/{certificateType}")
public ModelAndView initPage(@PathVariable("certificateType") final String certificateType, public ModelAndView initPage(@PathVariable("certificateType") final String certificateType,
final NoPageParams params, final Model model) { final NoPageParams params, final Model model) {
@ -168,6 +172,7 @@ public class CertificateRequestPageController extends PageController<NoPageParam
* @return the data table * @return the data table
*/ */
@ResponseBody @ResponseBody
@GetMapping
@RequestMapping(value = "/{certificateType}/list", @RequestMapping(value = "/{certificateType}/list",
produces = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE,
method = RequestMethod.GET) method = RequestMethod.GET)

View File

@ -1,19 +1,26 @@
package hirs.attestationca.portal.page.controllers; package hirs.attestationca.portal.page.controllers;
import hirs.FilteredRecordsList;
import hirs.attestationca.portal.datatables.DataTableInput; import hirs.attestationca.portal.datatables.DataTableInput;
import hirs.attestationca.portal.datatables.DataTableResponse; import hirs.attestationca.portal.datatables.DataTableResponse;
import hirs.attestationca.portal.datatables.OrderedListQueryDataTableAdapter; import hirs.attestationca.portal.datatables.OrderedListQueryDataTableAdapter;
import static hirs.attestationca.portal.page.Page.DEVICES;
import hirs.attestationca.portal.page.PageController; import hirs.attestationca.portal.page.PageController;
import hirs.attestationca.portal.page.params.NoPageParams; import hirs.attestationca.portal.page.params.NoPageParams;
import hirs.data.persist.Device;
import hirs.data.persist.certificate.Certificate;
import hirs.data.persist.certificate.DeviceAssociatedCertificate;
import hirs.persist.DBManager;
import hirs.persist.DeviceManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList; import java.util.ArrayList;
@ -22,23 +29,19 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import static hirs.attestationca.portal.page.Page.DEVICES;
import static org.apache.logging.log4j.LogManager.getLogger; import static org.apache.logging.log4j.LogManager.getLogger;
import org.hibernate.criterion.Restrictions;
import hirs.FilteredRecordsList;
import hirs.data.persist.Device;
import hirs.data.persist.certificate.Certificate;
import hirs.data.persist.certificate.DeviceAssociatedCertificate;
import hirs.persist.DBManager;
import hirs.persist.DeviceManager;
/** /**
* Controller for the Device page. * Controller for the Device page.
*/ */
@Controller @RestController
@RequestMapping("/devices") @RequestMapping(path = "/devices")
public class DevicesPageController extends PageController<NoPageParams> { public class DevicesPageController extends PageController<NoPageParams> {
@Autowired
private final DeviceManager deviceManager; private final DeviceManager deviceManager;
@Autowired
private final DBManager<Certificate> certificateDBManager; private final DBManager<Certificate> certificateDBManager;
private static final Logger LOGGER = getLogger(DevicesPageController.class); private static final Logger LOGGER = getLogger(DevicesPageController.class);
@ -76,6 +79,7 @@ public class DevicesPageController extends PageController<NoPageParams> {
* @return the data tables response, including the result set and paging information * @return the data tables response, including the result set and paging information
*/ */
@ResponseBody @ResponseBody
@GetMapping
@RequestMapping(value = "list", produces = MediaType.APPLICATION_JSON_VALUE, @RequestMapping(value = "list", produces = MediaType.APPLICATION_JSON_VALUE,
method = RequestMethod.GET) method = RequestMethod.GET)
public DataTableResponse<HashMap<String, Object>> getTableData( public DataTableResponse<HashMap<String, Object>> getTableData(

View File

@ -1,24 +1,26 @@
package hirs.attestationca.portal.page.controllers; package hirs.attestationca.portal.page.controllers;
import static hirs.attestationca.portal.page.Page.HELP;
import hirs.attestationca.portal.page.PageController; import hirs.attestationca.portal.page.PageController;
import hirs.attestationca.portal.page.params.NoPageParams; import hirs.attestationca.portal.page.params.NoPageParams;
import java.io.File;
import java.io.IOException;
import static org.apache.logging.log4j.LogManager.getLogger;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.io.File;
import java.io.IOException;
import static hirs.attestationca.portal.page.Page.HELP;
import static org.apache.logging.log4j.LogManager.getLogger;
/** /**
* Controller for the Help page. * Controller for the Help page.
*/ */
@Controller @RestController
@RequestMapping("/help") @RequestMapping(path = "/help")
public class HelpController extends PageController<NoPageParams> { public class HelpController extends PageController<NoPageParams> {
@Autowired @Autowired

View File

@ -12,11 +12,12 @@ import hirs.persist.PolicyManager;
import hirs.persist.PolicyManagerException; import hirs.persist.PolicyManagerException;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import org.springframework.web.servlet.view.RedirectView; import org.springframework.web.servlet.view.RedirectView;
@ -31,8 +32,8 @@ import static org.apache.logging.log4j.LogManager.getLogger;
/** /**
* Controller for the Policy page. * Controller for the Policy page.
*/ */
@Controller @RestController
@RequestMapping("/policy") @RequestMapping(path = "/policy")
public class PolicyPageController extends PageController<NoPageParams> { public class PolicyPageController extends PageController<NoPageParams> {
private static final Logger LOGGER = getLogger(PolicyPageController.class); private static final Logger LOGGER = getLogger(PolicyPageController.class);
@ -45,7 +46,9 @@ public class PolicyPageController extends PageController<NoPageParams> {
private static final String ENABLED_EXPIRES_PARAMETER_VALUE = "expires"; private static final String ENABLED_EXPIRES_PARAMETER_VALUE = "expires";
@Autowired
private PolicyManager policyManager; private PolicyManager policyManager;
@Autowired
private AppraiserManager appraiserManager; private AppraiserManager appraiserManager;
/** /**
@ -108,6 +111,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @return View containing the url and parameters * @return View containing the url and parameters
* @throws URISyntaxException if malformed URI * @throws URISyntaxException if malformed URI
*/ */
@GetMapping
@RequestMapping(value = "update-pc-validation", method = RequestMethod.POST) @RequestMapping(value = "update-pc-validation", method = RequestMethod.POST)
public RedirectView updatePcVal(@ModelAttribute final PolicyPageModel ppModel, public RedirectView updatePcVal(@ModelAttribute final PolicyPageModel ppModel,
final RedirectAttributes attr) throws URISyntaxException { final RedirectAttributes attr) throws URISyntaxException {
@ -159,6 +163,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @return View containing the url and parameters * @return View containing the url and parameters
* @throws URISyntaxException if malformed URI * @throws URISyntaxException if malformed URI
*/ */
@GetMapping
@RequestMapping(value = "update-pc-attribute-validation", method = RequestMethod.POST) @RequestMapping(value = "update-pc-attribute-validation", method = RequestMethod.POST)
public RedirectView updatePcAttributeVal(@ModelAttribute final PolicyPageModel ppModel, public RedirectView updatePcAttributeVal(@ModelAttribute final PolicyPageModel ppModel,
final RedirectAttributes attr) final RedirectAttributes attr)

View File

@ -25,9 +25,9 @@ import hirs.validation.SupplyChainValidatorException;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.io.IOException; import java.io.IOException;
@ -47,14 +47,18 @@ import java.util.UUID;
/** /**
* Controller for the Reference Manifest Details page. * Controller for the Reference Manifest Details page.
*/ */
@Controller @RestController
@RequestMapping("/rim-details") @RequestMapping(path = "/rim-details")
public class ReferenceManifestDetailsPageController public class ReferenceManifestDetailsPageController
extends PageController<ReferenceManifestDetailsPageParams> { extends PageController<ReferenceManifestDetailsPageParams> {
@Autowired
private final ReferenceManifestManager referenceManifestManager; private final ReferenceManifestManager referenceManifestManager;
@Autowired
private final ReferenceDigestManager referenceDigestManager; private final ReferenceDigestManager referenceDigestManager;
@Autowired
private final ReferenceEventManager referenceEventManager; private final ReferenceEventManager referenceEventManager;
@Autowired
private final CertificateManager certificateManager; private final CertificateManager certificateManager;
private static final ReferenceManifestValidator RIM_VALIDATOR private static final ReferenceManifestValidator RIM_VALIDATOR
= new ReferenceManifestValidator(); = new ReferenceManifestValidator();

View File

@ -30,13 +30,14 @@ import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes; import org.springframework.web.servlet.mvc.support.RedirectAttributes;
@ -66,8 +67,8 @@ import java.util.zip.ZipOutputStream;
/** /**
* Controller for the Reference Manifest page. * Controller for the Reference Manifest page.
*/ */
@Controller @RestController
@RequestMapping("/reference-manifests") @RequestMapping(path = "/reference-manifests")
public class ReferenceManifestPageController public class ReferenceManifestPageController
extends PageController<NoPageParams> { extends PageController<NoPageParams> {
@ -75,7 +76,9 @@ public class ReferenceManifestPageController
private static final String LOG_FILE_PATTERN = "([^\\s]+(\\.(?i)(rimpcr|rimel|bin|log))$)"; private static final String LOG_FILE_PATTERN = "([^\\s]+(\\.(?i)(rimpcr|rimel|bin|log))$)";
private final BiosDateValidator biosValidator; private final BiosDateValidator biosValidator;
@Autowired
private final ReferenceManifestManager referenceManifestManager; private final ReferenceManifestManager referenceManifestManager;
@Autowired
private final ReferenceEventManager referenceEventManager; private final ReferenceEventManager referenceEventManager;
private static final Logger LOGGER private static final Logger LOGGER
= LogManager.getLogger(ReferenceManifestPageController.class); = LogManager.getLogger(ReferenceManifestPageController.class);
@ -161,6 +164,7 @@ public class ReferenceManifestPageController
* information * information
*/ */
@ResponseBody @ResponseBody
@GetMapping
@RequestMapping(value = "/list", @RequestMapping(value = "/list",
produces = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE,
method = RequestMethod.GET) method = RequestMethod.GET)

View File

@ -23,11 +23,12 @@ import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.text.DateFormat; import java.text.DateFormat;
@ -37,8 +38,8 @@ import java.text.SimpleDateFormat;
/** /**
* Controller for the TPM Events page. * Controller for the TPM Events page.
*/ */
@Controller @RestController
@RequestMapping("/rim-database") @RequestMapping(path = "/rim-database")
public class RimDatabasePageController public class RimDatabasePageController
extends PageController<NoPageParams> { extends PageController<NoPageParams> {
@ -131,6 +132,7 @@ public class RimDatabasePageController
* information * information
*/ */
@ResponseBody @ResponseBody
@GetMapping
@RequestMapping(value = "/list", @RequestMapping(value = "/list",
produces = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE,
method = RequestMethod.GET) method = RequestMethod.GET)

View File

@ -22,11 +22,12 @@ import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
@ -52,12 +53,15 @@ import static org.apache.logging.log4j.LogManager.getLogger;
/** /**
* Controller for the Validation Reports page. * Controller for the Validation Reports page.
*/ */
@Controller @RestController
@RequestMapping("/validation-reports") @RequestMapping(path = "/validation-reports")
public class ValidationReportsPageController extends PageController<NoPageParams> { public class ValidationReportsPageController extends PageController<NoPageParams> {
@Autowired
private final CrudManager<SupplyChainValidationSummary> supplyChainValidatorSummaryManager; private final CrudManager<SupplyChainValidationSummary> supplyChainValidatorSummaryManager;
@Autowired
private final CertificateManager certificateManager; private final CertificateManager certificateManager;
@Autowired
private final DeviceManager deviceManager; private final DeviceManager deviceManager;
private static String systemColumnHeaders = "Verified Manufacturer," private static String systemColumnHeaders = "Verified Manufacturer,"
@ -105,6 +109,7 @@ public class ValidationReportsPageController extends PageController<NoPageParams
* @return the data table response containing the supply chain summary records * @return the data table response containing the supply chain summary records
*/ */
@ResponseBody @ResponseBody
@GetMapping
@RequestMapping(value = "list", produces = MediaType.APPLICATION_JSON_VALUE, @RequestMapping(value = "list", produces = MediaType.APPLICATION_JSON_VALUE,
method = RequestMethod.GET) method = RequestMethod.GET)
public DataTableResponse<SupplyChainValidationSummary> getTableData( public DataTableResponse<SupplyChainValidationSummary> getTableData(

View File

@ -20,11 +20,15 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean; import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/** /**
* Spring configuration class for persistence beans used by the Attestation CA Portal. * Spring configuration class for persistence beans used by the Attestation CA Portal.
*/ */
@Repository
@Configuration @Configuration
@EnableTransactionManagement
@Import({ HibernateConfiguration.class }) @Import({ HibernateConfiguration.class })
public class PersistenceConfiguration { public class PersistenceConfiguration {

View File

@ -33,7 +33,6 @@ dependencies {
compile libs.commons_http compile libs.commons_http
compile libs.commons_valid compile libs.commons_valid
compile libs.hibernate compile libs.hibernate
// compile libs.hikari
compile libs.jackson compile libs.jackson
compile libs.jadira_usertype compile libs.jadira_usertype
compile libs.joda_time compile libs.joda_time

View File

@ -1,8 +1,5 @@
package hirs.data.persist; package hirs.data.persist;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Type;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
@ -25,8 +22,6 @@ public abstract class AbstractEntity {
@Id @Id
@Column(name = "id") @Column(name = "id")
@GeneratedValue(generator = "uuid2") @GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Type(type = "uuid-char")
private UUID id; private UUID id;
@Column (name = "create_time") @Column (name = "create_time")

View File

@ -5,7 +5,6 @@ import com.google.common.base.Preconditions;
import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.binary.Hex;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.hibernate.annotations.Type;
import javax.persistence.Access; import javax.persistence.Access;
import javax.persistence.AccessType; import javax.persistence.AccessType;
@ -91,7 +90,6 @@ public abstract class ReferenceManifest extends ArchivableEntity {
private String platformModel = null; private String platformModel = null;
@Column(nullable = false) @Column(nullable = false)
private String fileName = null; private String fileName = null;
@Type(type = "uuid-char")
@Column @Column
private UUID associatedRim; private UUID associatedRim;
@Column @Column

View File

@ -1,7 +1,8 @@
package hirs.data.persist; package hirs.data.persist;
import java.util.Date; import org.apache.logging.log4j.LogManager;
import java.util.UUID; import org.apache.logging.log4j.Logger;
import javax.persistence.Access; import javax.persistence.Access;
import javax.persistence.AccessType; import javax.persistence.AccessType;
import javax.persistence.Column; import javax.persistence.Column;
@ -10,9 +11,8 @@ import javax.persistence.Id;
import javax.persistence.Inheritance; import javax.persistence.Inheritance;
import javax.persistence.InheritanceType; import javax.persistence.InheritanceType;
import javax.persistence.Table; import javax.persistence.Table;
import org.apache.logging.log4j.LogManager; import java.util.Date;
import org.apache.logging.log4j.Logger; import java.util.UUID;
import org.hibernate.annotations.Type;
/** /**
* The <code>State</code> class represents a state. This is an abstract class * The <code>State</code> class represents a state. This is an abstract class
@ -33,7 +33,6 @@ public abstract class State {
@Id @Id
@Column(name = "id") @Column(name = "id")
@Type(type = "uuid-char")
private final UUID id; private final UUID id;
@Column (nullable = false) @Column (nullable = false)

View File

@ -2,18 +2,16 @@ package hirs.data.persist.info;
import hirs.data.persist.DeviceInfoReport; import hirs.data.persist.DeviceInfoReport;
import hirs.data.persist.InetAddressXmlAdapter; import hirs.data.persist.InetAddressXmlAdapter;
import java.io.Serializable; import org.apache.logging.log4j.LogManager;
import java.net.InetAddress; import org.apache.logging.log4j.Logger;
import java.util.Arrays;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Embeddable; import javax.persistence.Embeddable;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.io.Serializable;
import org.apache.logging.log4j.Logger; import java.net.InetAddress;
import org.apache.logging.log4j.LogManager; import java.util.Arrays;
import org.hibernate.annotations.Type;
/** /**
* This class is used to represent the network info of a device. * This class is used to represent the network info of a device.
@ -33,7 +31,7 @@ public class NetworkInfo implements Serializable {
@XmlElement @XmlElement
@XmlJavaTypeAdapter(value = InetAddressXmlAdapter.class) @XmlJavaTypeAdapter(value = InetAddressXmlAdapter.class)
@Column(length = DeviceInfoReport.SHORT_STRING_LENGTH, nullable = true) @Column(length = DeviceInfoReport.SHORT_STRING_LENGTH, nullable = true)
@Type(type = "hirs.data.persist.type.InetAddressType") //@Type(type = "hirs.data.persist.type.InetAddressType")
private InetAddress ipAddress; private InetAddress ipAddress;
@XmlElement @XmlElement

View File

@ -3,20 +3,17 @@ package hirs.data.persist.info;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import hirs.data.persist.DeviceInfoReport; import hirs.data.persist.DeviceInfoReport;
import hirs.data.persist.X509CertificateAdapter; import hirs.data.persist.X509CertificateAdapter;
import hirs.utils.StringValidator;
import java.io.Serializable; import org.apache.logging.log4j.LogManager;
import java.security.cert.X509Certificate; import org.apache.logging.log4j.Logger;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Embeddable; import javax.persistence.Embeddable;
import javax.persistence.Lob; import javax.persistence.Lob;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.io.Serializable;
import hirs.utils.StringValidator; import java.security.cert.X509Certificate;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.hibernate.annotations.Type;
/** /**
* This class is used to represent the TPM information for a device. * This class is used to represent the TPM information for a device.
@ -49,7 +46,7 @@ public class TPMInfo implements Serializable {
@XmlElement @XmlElement
@XmlJavaTypeAdapter(X509CertificateAdapter.class) @XmlJavaTypeAdapter(X509CertificateAdapter.class)
@Lob @Lob
@Type(type = "hirs.data.persist.type.X509CertificateType") // @Type(type = "hirs.data.persist.type.X509CertificateType")
@JsonIgnore @JsonIgnore
private X509Certificate identityCertificate; private X509Certificate identityCertificate;

View File

@ -16,6 +16,7 @@ import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.hibernate.query.Query; import org.hibernate.query.Query;
import org.hibernate.service.spi.ServiceRegistryImplementor; import org.hibernate.service.spi.ServiceRegistryImplementor;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
@ -38,6 +39,7 @@ import static org.hibernate.criterion.Restrictions.sqlRestriction;
* *
* @param <T> type of objects to manage by this manager * @param <T> type of objects to manage by this manager
*/ */
@Service
public abstract class AbstractDbManager<T> implements CrudManager<T> { public abstract class AbstractDbManager<T> implements CrudManager<T> {
private static final Logger LOGGER = LogManager.getLogger(AbstractDbManager.class); private static final Logger LOGGER = LogManager.getLogger(AbstractDbManager.class);

View File

@ -4,6 +4,7 @@ import hirs.appraiser.Appraiser;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
@ -11,6 +12,7 @@ import java.util.List;
* This class defines a <code>ApprasierManager</code> that stores the * This class defines a <code>ApprasierManager</code> that stores the
* appraisers in a database. * appraisers in a database.
*/ */
@Service
public class DBAppraiserManager extends DBManager<Appraiser> implements AppraiserManager { public class DBAppraiserManager extends DBManager<Appraiser> implements AppraiserManager {
private static final Logger LOGGER = LogManager.getLogger(); private static final Logger LOGGER = LogManager.getLogger();

View File

@ -7,6 +7,7 @@ import org.hibernate.SessionFactory;
import org.springframework.retry.RetryCallback; import org.springframework.retry.RetryCallback;
import org.springframework.retry.RetryContext; import org.springframework.retry.RetryContext;
import org.springframework.retry.support.RetryTemplate; import org.springframework.retry.support.RetryTemplate;
import org.springframework.stereotype.Service;
import java.io.Serializable; import java.io.Serializable;
import java.util.HashSet; import java.util.HashSet;
@ -15,6 +16,7 @@ import java.util.Set;
/** /**
* This class is used to persist and retrieve {@link Certificate}s into and from a database. * This class is used to persist and retrieve {@link Certificate}s into and from a database.
*/ */
@Service
public class DBCertificateManager extends DBManager<Certificate> public class DBCertificateManager extends DBManager<Certificate>
implements CertificateManager { implements CertificateManager {

View File

@ -10,6 +10,7 @@ import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.query.Query; import org.hibernate.query.Query;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
@ -25,6 +26,7 @@ import java.util.Set;
* This class defines the <code>DBDeviceGroupManager</code> that is used to * This class defines the <code>DBDeviceGroupManager</code> that is used to
* store <code>DeviceGroup</code>s in the database. * store <code>DeviceGroup</code>s in the database.
*/ */
@Service
public class DBDeviceGroupManager extends DBManager<DeviceGroup> implements DeviceGroupManager { public class DBDeviceGroupManager extends DBManager<DeviceGroup> implements DeviceGroupManager {
private static final Logger LOGGER = LogManager.getLogger(DBDeviceGroupManager.class); private static final Logger LOGGER = LogManager.getLogger(DBDeviceGroupManager.class);

View File

@ -11,6 +11,7 @@ import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.query.Query; import org.hibernate.query.Query;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
@ -29,6 +30,7 @@ import java.util.Set;
* This class defines a <code>DeviceManager</code> that stores the devices * This class defines a <code>DeviceManager</code> that stores the devices
* in a database. * in a database.
*/ */
@Service
public class DBDeviceManager extends DBManager<Device> implements public class DBDeviceManager extends DBManager<Device> implements
DeviceManager { DeviceManager {

View File

@ -15,6 +15,7 @@ import org.springframework.retry.RetryListener;
import org.springframework.retry.backoff.FixedBackOffPolicy; import org.springframework.retry.backoff.FixedBackOffPolicy;
import org.springframework.retry.policy.SimpleRetryPolicy; import org.springframework.retry.policy.SimpleRetryPolicy;
import org.springframework.retry.support.RetryTemplate; import org.springframework.retry.support.RetryTemplate;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import java.io.Serializable; import java.io.Serializable;
@ -29,6 +30,7 @@ import java.util.Map;
* archive, and delete operations for managing objects in a database. * archive, and delete operations for managing objects in a database.
* *
*/ */
@Service
public class DBManager<T> extends AbstractDbManager<T> { public class DBManager<T> extends AbstractDbManager<T> {
private static final Logger LOGGER = LogManager.getLogger(DBManager.class); private static final Logger LOGGER = LogManager.getLogger(DBManager.class);

View File

@ -11,6 +11,7 @@ import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.query.Query; import org.hibernate.query.Query;
import org.springframework.stereotype.Repository;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
@ -23,6 +24,7 @@ import java.util.List;
* This class defines a <code>PolicyManager</code> that stores policies in a * This class defines a <code>PolicyManager</code> that stores policies in a
* database. * database.
*/ */
@Repository
public class DBPolicyManager extends DBManager<Policy> implements PolicyManager { public class DBPolicyManager extends DBManager<Policy> implements PolicyManager {
private static final Logger LOGGER = LogManager.getLogger(DBPolicyManager.class); private static final Logger LOGGER = LogManager.getLogger(DBPolicyManager.class);

View File

@ -1,19 +1,20 @@
package hirs.persist; package hirs.persist;
import hirs.data.persist.info.PortalInfo;
import hirs.data.persist.enums.PortalScheme; import hirs.data.persist.enums.PortalScheme;
import hirs.data.persist.info.PortalInfo;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;
import java.net.URI;
import java.net.URISyntaxException;
/** /**
* A <code>DBPortalInfoManager</code> is a service (extends <code>DBManager</code>) that * A <code>DBPortalInfoManager</code> is a service (extends <code>DBManager</code>) that
* implements the <code>PortalInfoManager</code> that stores and retrieves Portal Info objects. * implements the <code>PortalInfoManager</code> that stores and retrieves Portal Info objects.
*/ */
@Service
public class DBPortalInfoManager extends DBManager<PortalInfo> implements PortalInfoManager { public class DBPortalInfoManager extends DBManager<PortalInfo> implements PortalInfoManager {
private static final Logger LOGGER = LogManager.getLogger(DBPortalInfoManager.class); private static final Logger LOGGER = LogManager.getLogger(DBPortalInfoManager.class);

View File

@ -11,6 +11,7 @@ import org.hibernate.Session;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.query.Query; import org.hibernate.query.Query;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
@ -26,6 +27,7 @@ import java.util.UUID;
* This class is used to persist and retrieve {@link hirs.data.persist.ReferenceDigestValue}s into * This class is used to persist and retrieve {@link hirs.data.persist.ReferenceDigestValue}s into
* and from the database. * and from the database.
*/ */
@Service
public class DBReferenceEventManager extends DBManager<ReferenceDigestValue> public class DBReferenceEventManager extends DBManager<ReferenceDigestValue>
implements ReferenceEventManager { implements ReferenceEventManager {

View File

@ -3,7 +3,7 @@ package hirs.persist;
import hirs.data.persist.ReferenceManifest; import hirs.data.persist.ReferenceManifest;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.hibernate.SessionFactory; import org.springframework.stereotype.Service;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
@ -20,6 +20,7 @@ import java.util.Set;
* This class is used to persist and retrieve {@link ReferenceManifest}s into * This class is used to persist and retrieve {@link ReferenceManifest}s into
* and from the database. * and from the database.
*/ */
@Service
public class DBReferenceManifestManager extends DBManager<ReferenceManifest> public class DBReferenceManifestManager extends DBManager<ReferenceManifest>
implements ReferenceManifestManager { implements ReferenceManifestManager {

View File

@ -8,6 +8,7 @@ import org.hibernate.criterion.Conjunction;
import org.hibernate.criterion.Disjunction; import org.hibernate.criterion.Disjunction;
import org.hibernate.criterion.MatchMode; import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -20,6 +21,7 @@ import static org.hibernate.criterion.Restrictions.ilike;
* This class defines a <code>ReportManager</code> that stores the reports in a * This class defines a <code>ReportManager</code> that stores the reports in a
* database. * database.
*/ */
@Service
public class DBReportManager extends DBManager<Report> implements ReportManager { public class DBReportManager extends DBManager<Report> implements ReportManager {
private static final Logger LOGGER = getLogger(DBReportManager.class); private static final Logger LOGGER = getLogger(DBReportManager.class);

View File

@ -5,6 +5,7 @@ import hirs.data.persist.ReportRequestState;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
@ -17,6 +18,7 @@ import java.util.List;
* This class defines a <code>ReportRequestStateManager</code> that stores ReportRequestStates in a * This class defines a <code>ReportRequestStateManager</code> that stores ReportRequestStates in a
* database. * database.
*/ */
@Service
public class DBReportRequestStateManager extends DBManager<ReportRequestState> public class DBReportRequestStateManager extends DBManager<ReportRequestState>
implements ReportRequestStateManager { implements ReportRequestStateManager {
private static final Logger LOGGER = LogManager.getLogger(DBReportRequestStateManager.class); private static final Logger LOGGER = LogManager.getLogger(DBReportRequestStateManager.class);

View File

@ -7,6 +7,7 @@ import org.hibernate.SessionFactory;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.criterion.Order; import org.hibernate.criterion.Order;
import org.hibernate.query.Query; import org.hibernate.query.Query;
import org.springframework.stereotype.Service;
import javax.persistence.criteria.CriteriaBuilder; import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
@ -23,6 +24,7 @@ import static org.apache.logging.log4j.LogManager.getLogger;
* report * report
* summary in a database. * summary in a database.
*/ */
@Service
public class DBReportSummaryManager extends DBManager<ReportSummary> public class DBReportSummaryManager extends DBManager<ReportSummary>
implements ReportSummaryManager { implements ReportSummaryManager {

View File

@ -3,6 +3,7 @@ package hirs.persist;
import hirs.repository.RepoPackage; import hirs.repository.RepoPackage;
import hirs.repository.Repository; import hirs.repository.Repository;
import org.hibernate.SessionFactory; import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;
import java.io.Serializable; import java.io.Serializable;
import java.util.List; import java.util.List;
@ -11,6 +12,7 @@ import java.util.List;
* This class defines a {@link RepositoryManager} that stores Repositories and RepoPackages * This class defines a {@link RepositoryManager} that stores Repositories and RepoPackages
* in a database. * in a database.
*/ */
@Service
public class DBRepositoryManager implements RepositoryManager { public class DBRepositoryManager implements RepositoryManager {
private final DBManager<Repository> repositoryDBManager; private final DBManager<Repository> repositoryDBManager;
private final DBManager<RepoPackage> repoPackageDBManager; private final DBManager<RepoPackage> repoPackageDBManager;

View File

@ -2,6 +2,7 @@ package hirs.persist;
import hirs.FilteredRecordsList; import hirs.FilteredRecordsList;
import hirs.data.persist.Device; import hirs.data.persist.Device;
import org.springframework.stereotype.Repository;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -11,6 +12,7 @@ import java.util.Set;
* <code>DeviceManager</code> is used to store and manage devices. It has * <code>DeviceManager</code> is used to store and manage devices. It has
* support for the basic create, read, update, and delete methods. * support for the basic create, read, update, and delete methods.
*/ */
@Repository
public interface DeviceManager extends OrderedListQuerier<Device> { public interface DeviceManager extends OrderedListQuerier<Device> {
/** /**

View File

@ -1,18 +1,19 @@
package hirs.persist; package hirs.persist;
import com.zaxxer.hikari.HikariDataSource;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource; import org.springframework.context.annotation.PropertySource;
import org.springframework.context.annotation.PropertySources; import org.springframework.context.annotation.PropertySources;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate5.HibernateTransactionManager; import org.springframework.orm.hibernate5.HibernateTransactionManager;
import org.springframework.orm.hibernate5.LocalSessionFactoryBean; import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
import org.springframework.transaction.annotation.EnableTransactionManagement; import org.springframework.transaction.annotation.EnableTransactionManagement;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
/** /**
@ -86,14 +87,16 @@ public class HibernateConfiguration {
*/ */
@Bean @Bean
public DataSource dataSource() { public DataSource dataSource() {
HikariDataSource dataSource = new HikariDataSource(); DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setJdbcUrl(url); dataSource.setUrl(url);
dataSource.setUsername(username); dataSource.setUsername(username);
dataSource.setPassword(password); dataSource.setPassword(password);
dataSource.setDriverClassName(driverClass); dataSource.setDriverClassName(driverClass);
dataSource.setMaximumPoolSize(Integer.parseInt(maximumPoolSize));
dataSource.setConnectionTimeout(Long.parseLong(connectionTimeout)); // dataSource.setMaximumPoolSize(Integer.parseInt(maximumPoolSize));
dataSource.setLeakDetectionThreshold(Long.parseLong(leakDetectionThreshold)); // dataSource.setConnectionTimeout(Long.parseLong(connectionTimeout));
// dataSource.setLeakDetectionThreshold(Long.parseLong(leakDetectionThreshold));
return dataSource; return dataSource;
} }
@ -121,26 +124,71 @@ public class HibernateConfiguration {
*/ */
@Bean @Bean
public LocalSessionFactoryBean sessionFactory() { public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); // Hibernate 5.4 SessionFactory example without XML
sessionFactory.setDataSource(dataSource()); Map<String, String> settings = new HashMap<>();
settings.put("connection.driver_class", "com.mysql.jdbc.Driver");
settings.put("dialect", "org.hibernate.dialect.MySQL8Dialect");
settings.put("hibernate.connection.url",
"jdbc:mysql://localhost/hibernate_examples");
settings.put("hibernate.connection.username", "root");
settings.put("hibernate.connection.password", "root");
settings.put("hibernate.current_session_context_class", "thread");
settings.put("hibernate.show_sql", "true");
settings.put("hibernate.format_sql", "true");
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
.applySettings(settings).build();
MetadataSources metadataSources = new MetadataSources(serviceRegistry);
// metadataSources.addAnnotatedClass(Player.class);
Metadata metadata = metadataSources.buildMetadata();
// here we build the SessionFactory (Hibernate 5.4)
LocalSessionFactoryBean sessionFactory = (LocalSessionFactoryBean) metadata
.getSessionFactoryBuilder()
.build();
sessionFactory.setHibernateProperties(hibernateProperties()); sessionFactory.setHibernateProperties(hibernateProperties());
sessionFactory.setPackagesToScan("hirs"); sessionFactory.setPackagesToScan("hirs");
return sessionFactory; return sessionFactory;
} }
// public static SessionFactory getCurrentSessionFromJPA() {
// // JPA and Hibernate SessionFactory example
// EntityManagerFactory emf =
// Persistence.createEntityManagerFactory("jpa-tutorial");
// EntityManager entityManager = emf.createEntityManager();
// // Get the Hibernate Session from the EntityManager in JPA
// Session session = entityManager.unwrap(org.hibernate.Session.class);
// SessionFactory factory = session.getSessionFactory();
// return factory;
// }
// /**
// * Configures a session factory bean that in turn configures the hibernate session factory.
// * Enables auto scanning of annotations such that entities do not need to be registered in a
// * hibernate configuration file.
// *
// * @return session factory
// */
// @Bean
// public LocalSessionFactoryBean sessionFactory() {
// LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();
// sessionFactory.setDataSource(dataSource());
// sessionFactory.setHibernateProperties(hibernateProperties());
// sessionFactory.setPackagesToScan("hirs");
// return sessionFactory;
// }
/** /**
* Configure a transaction manager for the hibernate session factory. * Configure a transaction manager for the hibernate session factory.
* *
* @return transaction manager * @return transaction manager
*/ */
@Bean @Bean
public HibernateTransactionManager transactionManager() { public HibernateTransactionManager getTransactionManager() {
SessionFactory sessionFactory = sessionFactory().getObject(); HibernateTransactionManager transactionManager = new HibernateTransactionManager();
if (sessionFactory != null) { transactionManager.setSessionFactory(sessionFactory().getObject());
return new HibernateTransactionManager(sessionFactory); return transactionManager;
} else {
return new HibernateTransactionManager();
}
} }
/** /**

View File

@ -1,6 +1,5 @@
package hirs.persist; package hirs.persist;
import org.hibernate.annotations.Type;
import org.joda.time.Interval; import org.joda.time.Interval;
import org.joda.time.LocalDateTime; import org.joda.time.LocalDateTime;
import org.joda.time.LocalTime; import org.joda.time.LocalTime;
@ -8,7 +7,6 @@ import org.joda.time.Period;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Embeddable; import javax.persistence.Embeddable;
import java.util.Date; import java.util.Date;
/** /**
@ -26,7 +24,6 @@ public class ScheduledJobInfo {
public static final LocalTime DEFAULT_START_TIME = new LocalTime(22, 0, 0); public static final LocalTime DEFAULT_START_TIME = new LocalTime(22, 0, 0);
@Column @Column
@Type(type = "org.jadira.usertype.dateandtime.joda.PersistentLocalTime")
private LocalTime startTime; private LocalTime startTime;
@Column @Column

View File

@ -2,7 +2,6 @@ package hirs.repository;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import hirs.data.persist.Digest; import hirs.data.persist.Digest;
import org.hibernate.annotations.Type;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Column; import javax.persistence.Column;
@ -33,7 +32,6 @@ import java.util.UUID;
public abstract class RepoPackage { public abstract class RepoPackage {
@Id @Id
@Column(name = "id") @Column(name = "id")
@Type(type = "uuid-char")
private UUID id; private UUID id;
@Column @Column

View File

@ -1,6 +1,6 @@
package hirs.utils; package hirs.utils;
import org.hibernate.dialect.MySQL5InnoDBDialect; import org.hibernate.dialect.MySQLDialect;
/** /**
* This class is a shim on top of the standard MySQL5InnoDBDialect to set the row format * This class is a shim on top of the standard MySQL5InnoDBDialect to set the row format
@ -24,7 +24,7 @@ import org.hibernate.dialect.MySQL5InnoDBDialect;
* https://dev.mysql.com/doc/refman/5.7/en/innodb-row-format-dynamic.html * https://dev.mysql.com/doc/refman/5.7/en/innodb-row-format-dynamic.html
* https://dev.mysql.com/doc/refman/5.5/en/innodb-restrictions.html * https://dev.mysql.com/doc/refman/5.5/en/innodb-restrictions.html
*/ */
public class MySqlUtf8CompatibleDialect extends MySQL5InnoDBDialect { public class MySqlUtf8CompatibleDialect extends MySQLDialect {
/** /**
* Returns the table 'type' string, which specifies the storage engine (via the * Returns the table 'type' string, which specifies the storage engine (via the
* super call) and appends the desired row format. * super call) and appends the desired row format.

View File

@ -106,10 +106,9 @@ subprojects {
findbugs: 'com.google.code.findbugs:findbugs:3.0.0', findbugs: 'com.google.code.findbugs:findbugs:3.0.0',
gson: 'com.google.code.gson:gson:2.9.0', gson: 'com.google.code.gson:gson:2.9.0',
guava: 'com.google.guava:guava:31.1-jre', guava: 'com.google.guava:guava:31.1-jre',
hibernate: [ 'org.hibernate.common:hibernate-commons-annotations:5.0.0.Final', hibernate: [ 'org.hibernate.common:hibernate-commons-annotations:5.1.1.Final',
'org.hibernate:hibernate-core:5.0.0.Final', 'org.hibernate:hibernate-core:5.2.4.Final',
'org.hibernate:hibernate-hikaricp:5.0.0.Final'], 'org.hibernate:hibernate-hikaricp:5.2.4.Final'],
// hikari: 'com.zaxxer:HikariCP:5.0.1',
hsqldb: 'org.hsqldb:hsqldb:2.6.1', hsqldb: 'org.hsqldb:hsqldb:2.6.1',
http: 'org.apache.httpcomponents:httpclient:4.5.13', http: 'org.apache.httpcomponents:httpclient:4.5.13',
jackson: [ 'com.fasterxml.jackson.core:jackson-core:2.13.2', jackson: [ 'com.fasterxml.jackson.core:jackson-core:2.13.2',