mirror of
https://github.com/nsacyber/HIRS.git
synced 2025-02-21 02:01:24 +00:00
Additional changes to move data managers to the ACA module
This commit is contained in:
parent
1df40473bd
commit
a7a555ed5e
@ -1,9 +1,8 @@
|
||||
package hirs.attestationca;
|
||||
|
||||
import hirs.persist.DBAppraiserManager;
|
||||
import hirs.persist.DBDeviceGroupManager;
|
||||
import hirs.persist.DBPolicyManager;
|
||||
import hirs.persist.PersistenceConfiguration;
|
||||
import hirs.attestationca.persist.DBAppraiserManager;
|
||||
import hirs.attestationca.persist.DBDeviceGroupManager;
|
||||
import hirs.attestationca.persist.DBPolicyManager;
|
||||
import hirs.utils.HIRSProfiles;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
@ -1,12 +1,11 @@
|
||||
package hirs.attestationca.configuration;
|
||||
|
||||
import hirs.persist.DBDeviceGroupManager;
|
||||
import hirs.persist.DBDeviceManager;
|
||||
import hirs.persist.DBReferenceEventManager;
|
||||
import hirs.persist.DBReferenceManifestManager;
|
||||
import hirs.attestationca.persist.DBDeviceGroupManager;
|
||||
import hirs.attestationca.persist.DBDeviceManager;
|
||||
import hirs.attestationca.persist.DBReferenceEventManager;
|
||||
import hirs.attestationca.persist.DBReferenceManifestManager;
|
||||
import hirs.persist.DeviceGroupManager;
|
||||
import hirs.persist.DeviceManager;
|
||||
import hirs.persist.HibernateConfiguration;
|
||||
import hirs.persist.ReferenceEventManager;
|
||||
import hirs.persist.ReferenceManifestManager;
|
||||
import hirs.structs.converters.SimpleStructConverter;
|
||||
@ -27,6 +26,8 @@ import org.springframework.context.annotation.PropertySources;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.orm.hibernate5.HibernateTransactionManager;
|
||||
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
|
||||
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
@ -34,6 +35,7 @@ import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.sql.DataSource;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -43,6 +45,7 @@ import java.security.KeyStoreException;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.Security;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Provides application context configuration for the Attestation Certificate
|
||||
@ -61,7 +64,7 @@ import java.security.cert.X509Certificate;
|
||||
})
|
||||
@ComponentScan({ "hirs.attestationca", "hirs.attestationca.service", "hirs.attestationca.rest",
|
||||
"hirs.validation", "hirs.data.service" })
|
||||
@Import(HibernateConfiguration.class)
|
||||
@Import(PersistenceConfiguration.class)
|
||||
@EnableWebMvc
|
||||
public class AttestationCertificateAuthorityConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@ -78,6 +81,45 @@ public class AttestationCertificateAuthorityConfiguration implements WebMvcConfi
|
||||
|
||||
private static final String CLIENT_FILES_PATH = "file:/etc/hirs/aca/client-files/";
|
||||
|
||||
@Value("${persistence.db.url}")
|
||||
private String url;
|
||||
|
||||
@Value("${persistence.db.username}")
|
||||
private String username;
|
||||
|
||||
@Value("${persistence.db.password}")
|
||||
private String password;
|
||||
|
||||
@Value("${persistence.db.driverClass}")
|
||||
private String driverClass;
|
||||
|
||||
@Value("${persistence.db.maximumPoolSize}")
|
||||
private String maximumPoolSize;
|
||||
|
||||
@Value("${persistence.db.connectionTimeout}")
|
||||
private String connectionTimeout;
|
||||
|
||||
@Value("${persistence.db.leakDetectionThreshold}")
|
||||
private String leakDetectionThreshold;
|
||||
|
||||
@Value("${persistence.hibernate.dialect}")
|
||||
private String dialect;
|
||||
|
||||
@Value("${persistence.hibernate.ddl}")
|
||||
private String ddl;
|
||||
|
||||
@Value("${persistence.hibernate.contextClass}")
|
||||
private String contextClass;
|
||||
|
||||
@Value("${persistence.hibernate.provider}")
|
||||
private String provider;
|
||||
|
||||
@Value("${persistence.db.maxTransactionRetryAttempts}")
|
||||
private int maxTransactionRetryAttempts;
|
||||
|
||||
@Value("${persistence.db.retryWaitTimeMilliseconds}")
|
||||
private long retryWaitTimeMilliseconds;
|
||||
|
||||
@Value("${aca.directories.certificates}")
|
||||
private String certificatesLocation;
|
||||
|
||||
@ -105,6 +147,26 @@ public class AttestationCertificateAuthorityConfiguration implements WebMvcConfi
|
||||
return new PropertySourcesPlaceholderConfigurer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the data source to be used by the hibernate session factory.
|
||||
*
|
||||
* @return configured data source
|
||||
*/
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setUrl(url);
|
||||
dataSource.setUsername(username);
|
||||
dataSource.setPassword(password);
|
||||
dataSource.setDriverClassName(driverClass);
|
||||
|
||||
// dataSource.setMaximumPoolSize(Integer.parseInt(maximumPoolSize));
|
||||
// dataSource.setConnectionTimeout(Long.parseLong(connectionTimeout));
|
||||
// dataSource.setLeakDetectionThreshold(Long.parseLong(leakDetectionThreshold));
|
||||
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialization of the ACA. Detects environment and runs configuration
|
||||
* methods as required. This method is intended to be invoked by the Spring
|
||||
@ -141,7 +203,6 @@ public class AttestationCertificateAuthorityConfiguration implements WebMvcConfi
|
||||
*/
|
||||
@Bean
|
||||
public PrivateKey privateKey() {
|
||||
|
||||
// obtain the key store
|
||||
KeyStore keyStore = keyStore();
|
||||
|
||||
@ -164,6 +225,64 @@ public class AttestationCertificateAuthorityConfiguration implements WebMvcConfi
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates properties using configuration file that will be used to configure the session
|
||||
* factory.
|
||||
*
|
||||
* @return properties for hibernate session factory
|
||||
*/
|
||||
@Bean
|
||||
public Properties hibernateProperties() {
|
||||
Properties properties = new Properties();
|
||||
properties.put("hibernate.hbm2ddl.auto", ddl);
|
||||
properties.put("hibernate.dialect", dialect);
|
||||
properties.put("hibernate.current_session_context_class", "thread");
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @return transaction manager
|
||||
*/
|
||||
@Bean
|
||||
public HibernateTransactionManager transactionManager() {
|
||||
return new HibernateTransactionManager(sessionFactory().getObject());
|
||||
}
|
||||
|
||||
/**
|
||||
* Bean holding the maximum retry attempts for a DB transaction.
|
||||
* @return the maximum retry count
|
||||
*/
|
||||
@Bean(name = "maxTransactionRetryAttempts")
|
||||
public int maxTransactionRetryAttempts() {
|
||||
return maxTransactionRetryAttempts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bean holding the time to wait until retrying a failed transaction.
|
||||
* @return the wait time, in milliseconds
|
||||
*/
|
||||
@Bean(name = "retryWaitTimeMilliseconds")
|
||||
public long retryWaitTimeMilliseconds() {
|
||||
return retryWaitTimeMilliseconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the {@link X509Certificate} of the ACA
|
||||
*/
|
||||
|
@ -1,13 +1,33 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.configuration;
|
||||
|
||||
import hirs.data.persist.SupplyChainValidationSummary;
|
||||
import hirs.persist.CertificateManager;
|
||||
import hirs.persist.CrudManager;
|
||||
import hirs.attestationca.persist.DBCertificateManager;
|
||||
import hirs.attestationca.persist.DBDeviceGroupManager;
|
||||
import hirs.attestationca.persist.DBDeviceManager;
|
||||
import hirs.attestationca.persist.DBManager;
|
||||
import hirs.attestationca.persist.DBPolicyManager;
|
||||
import hirs.attestationca.persist.DBPortalInfoManager;
|
||||
import hirs.attestationca.persist.DBReferenceEventManager;
|
||||
import hirs.attestationca.persist.DBReferenceManifestManager;
|
||||
import hirs.attestationca.persist.DBReportManager;
|
||||
import hirs.attestationca.persist.DBReportRequestStateManager;
|
||||
import hirs.attestationca.persist.DBReportSummaryManager;
|
||||
import hirs.persist.DeviceGroupManager;
|
||||
import hirs.persist.DeviceManager;
|
||||
import hirs.persist.PolicyManager;
|
||||
import hirs.persist.PortalInfoManager;
|
||||
import hirs.persist.ReferenceEventManager;
|
||||
import hirs.persist.ReferenceManifestManager;
|
||||
import hirs.persist.ReportManager;
|
||||
import hirs.persist.ReportRequestStateManager;
|
||||
import hirs.persist.ReportSummaryManager;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
|
||||
|
||||
|
||||
/**
|
||||
* Persistence Configuration for Spring enabled applications. Constructs a Hibernate SessionFactory
|
||||
* backed powered by a HikariCP connection pooled data source. Module-specific settings
|
||||
@ -16,7 +36,6 @@ import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
|
||||
* file, the default persistence file will be used instead.
|
||||
*/
|
||||
@Configuration
|
||||
@Import({ HibernateConfiguration.class })
|
||||
public class PersistenceConfiguration {
|
||||
|
||||
/**
|
||||
@ -34,21 +53,9 @@ public class PersistenceConfiguration {
|
||||
private int maxTransactionRetryAttempts;
|
||||
|
||||
/**
|
||||
* Creates a {@link AppraiserManager} ready to use.
|
||||
* Creates a {@link hirs.persist.PolicyManager} ready to use.
|
||||
*
|
||||
* @return {@link AppraiserManager}
|
||||
*/
|
||||
@Bean
|
||||
public AppraiserManager appraiserManager() {
|
||||
DBAppraiserManager manager = new DBAppraiserManager(sessionFactory.getObject());
|
||||
setDbManagerRetrySettings(manager);
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link PolicyManager} ready to use.
|
||||
*
|
||||
* @return {@link PolicyManager}
|
||||
* @return {@link hirs.persist.PolicyManager}
|
||||
*/
|
||||
@Bean
|
||||
public PolicyManager policyManager() {
|
||||
@ -58,9 +65,9 @@ public class PersistenceConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link ReportManager} ready to use.
|
||||
* Creates a {@link hirs.persist.ReportManager} ready to use.
|
||||
*
|
||||
* @return {@link ReportManager}
|
||||
* @return {@link hirs.persist.ReportManager}
|
||||
*/
|
||||
@Bean
|
||||
public ReportManager reportManager() {
|
||||
@ -70,9 +77,9 @@ public class PersistenceConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link DeviceManager} ready to use.
|
||||
* Creates a {@link hirs.persist.DeviceManager} ready to use.
|
||||
*
|
||||
* @return {@link DeviceManager}
|
||||
* @return {@link hirs.persist.DeviceManager}
|
||||
*/
|
||||
@Bean
|
||||
public DeviceManager deviceManager() {
|
||||
@ -82,9 +89,9 @@ public class PersistenceConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link ReportSummaryManager} ready to use.
|
||||
* Creates a {@link hirs.persist.ReportSummaryManager} ready to use.
|
||||
*
|
||||
* @return {@link ReportSummaryManager}
|
||||
* @return {@link hirs.persist.ReportSummaryManager}
|
||||
*/
|
||||
@Bean
|
||||
public ReportSummaryManager reportSummaryManager() {
|
||||
@ -94,9 +101,9 @@ public class PersistenceConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link DeviceGroupManager} ready to use.
|
||||
* Creates a {@link hirs.persist.DeviceGroupManager} ready to use.
|
||||
*
|
||||
* @return {@link DeviceGroupManager}
|
||||
* @return {@link hirs.persist.DeviceGroupManager}
|
||||
*/
|
||||
@Bean
|
||||
public DeviceGroupManager deviceGroupManager() {
|
||||
@ -106,9 +113,9 @@ public class PersistenceConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link CertificateManager} ready to use.
|
||||
* Creates a {@link hirs.persist.CertificateManager} ready to use.
|
||||
*
|
||||
* @return {@link CertificateManager}
|
||||
* @return {@link hirs.persist.CertificateManager}
|
||||
*/
|
||||
@Bean
|
||||
public CertificateManager certificateManager() {
|
||||
@ -118,9 +125,9 @@ public class PersistenceConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link ReferenceManifestManager} ready to use.
|
||||
* Creates a {@link hirs.persist.ReferenceManifestManager} ready to use.
|
||||
*
|
||||
* @return {@link ReferenceManifestManager}
|
||||
* @return {@link hirs.persist.ReferenceManifestManager}
|
||||
*/
|
||||
@Bean
|
||||
public ReferenceManifestManager referenceManifestManager() {
|
||||
@ -131,9 +138,9 @@ public class PersistenceConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link ReferenceEventManager} ready to use.
|
||||
* Creates a {@link hirs.persist.ReferenceEventManager} ready to use.
|
||||
*
|
||||
* @return {@link ReferenceEventManager}
|
||||
* @return {@link hirs.persist.ReferenceEventManager}
|
||||
*/
|
||||
@Bean
|
||||
public ReferenceEventManager referenceEventManager() {
|
||||
@ -144,9 +151,9 @@ public class PersistenceConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link ReportRequestStateManager} ready to use.
|
||||
* Creates a {@link hirs.persist.ReportRequestStateManager} ready to use.
|
||||
*
|
||||
* @return {@link ReportRequestStateManager}
|
||||
* @return {@link hirs.persist.ReportRequestStateManager}
|
||||
*/
|
||||
@Bean
|
||||
public ReportRequestStateManager reportRequestStateManager() {
|
||||
@ -157,21 +164,9 @@ public class PersistenceConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link RepositoryManager} ready to use.
|
||||
* Creates a {@link hirs.persist.PortalInfoManager} ready to use.
|
||||
*
|
||||
* @return {@link RepositoryManager}
|
||||
*/
|
||||
@Bean
|
||||
public RepositoryManager repositoryManager() {
|
||||
DBRepositoryManager manager = new DBRepositoryManager(sessionFactory.getObject());
|
||||
manager.setRetryTemplate(maxTransactionRetryAttempts, retryWaitTimeMilliseconds);
|
||||
return manager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link PortalInfoManager} ready to use.
|
||||
*
|
||||
* @return {@link PortalInfoManager}
|
||||
* @return {@link hirs.persist.PortalInfoManager}
|
||||
*/
|
||||
@Bean
|
||||
public PortalInfoManager portalInfoManager() {
|
||||
@ -181,9 +176,9 @@ public class PersistenceConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link DBManager} for SupplyChainValidationSummary persistence, ready for use.
|
||||
* Creates a {@link hirs.attestationca.persist.DBManager} for SupplyChainValidationSummary persistence, ready for use.
|
||||
*
|
||||
* @return {@link DBManager}
|
||||
* @return {@link hirs.attestationca.persist.DBManager}
|
||||
*/
|
||||
@Bean
|
||||
public CrudManager<SupplyChainValidationSummary> supplyChainValidationSummaryManager() {
|
@ -1,7 +1,10 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.FilteredRecordsList;
|
||||
import hirs.data.persist.ArchivableEntity;
|
||||
import hirs.persist.CriteriaModifier;
|
||||
import hirs.persist.CrudManager;
|
||||
import hirs.persist.DBManagerException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.HibernateException;
|
@ -1,6 +1,9 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.appraiser.Appraiser;
|
||||
import hirs.persist.AppraiserManager;
|
||||
import hirs.persist.AppraiserManagerException;
|
||||
import hirs.persist.DBManagerException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.SessionFactory;
|
||||
@ -36,7 +39,7 @@ public class DBAppraiserManager extends DBManager<Appraiser> implements Appraise
|
||||
* @param appraiser
|
||||
* appraiser to save
|
||||
* @return reference to saved appraiser
|
||||
* @throws AppraiserManagerException
|
||||
* @throws hirs.persist.AppraiserManagerException
|
||||
* if appraiser has previously been saved or an error occurs
|
||||
* while trying to save it to the database
|
||||
*/
|
@ -1,6 +1,9 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.data.persist.certificate.Certificate;
|
||||
import hirs.persist.CertificateManager;
|
||||
import hirs.persist.CertificateSelector;
|
||||
import hirs.persist.DBManagerException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.SessionFactory;
|
||||
@ -36,7 +39,7 @@ public class DBCertificateManager extends DBManager<Certificate>
|
||||
}
|
||||
|
||||
/**
|
||||
* This method does not need to be used directly as it is used by {@link CertificateSelector}'s
|
||||
* This method does not need to be used directly as it is used by {@link hirs.persist.CertificateSelector}'s
|
||||
* get* methods. Regardless, it may be used to retrieve certificates by other code in this
|
||||
* package, given a configured CertificateSelector.
|
||||
*
|
||||
@ -52,7 +55,7 @@ public class DBCertificateManager extends DBManager<Certificate>
|
||||
* </pre>
|
||||
*
|
||||
* @param <T> the type of certificate that will be retrieved
|
||||
* @param certificateSelector a configured {@link CertificateSelector} to use for querying
|
||||
* @param certificateSelector a configured {@link hirs.persist.CertificateSelector} to use for querying
|
||||
* @return the resulting set of Certificates, possibly empty
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@ -83,7 +86,7 @@ public class DBCertificateManager extends DBManager<Certificate>
|
||||
*
|
||||
* @param object object to save
|
||||
* @return reference to saved object
|
||||
* @throws DBManagerException if object has previously been saved or an
|
||||
* @throws hirs.persist.DBManagerException if object has previously been saved or an
|
||||
* error occurs while trying to save it to the database
|
||||
*/
|
||||
@Override
|
@ -1,8 +1,13 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.FilteredRecordsList;
|
||||
import hirs.data.persist.DeviceGroup;
|
||||
import hirs.data.persist.Policy;
|
||||
import hirs.persist.CriteriaModifier;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.DeviceGroupManager;
|
||||
import hirs.persist.DeviceGroupManagerException;
|
||||
import hirs.persist.PolicyMapper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.Criteria;
|
||||
@ -50,7 +55,7 @@ public class DBDeviceGroupManager extends DBManager<DeviceGroup> implements Devi
|
||||
* @param deviceGroup
|
||||
* device group to save
|
||||
* @return reference to saved device group
|
||||
* @throws DeviceGroupManagerException
|
||||
* @throws hirs.persist.DeviceGroupManagerException
|
||||
* if device group had been previously saved or an error occurs
|
||||
* while trying to save it to the database
|
||||
*/
|
@ -1,8 +1,12 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.FilteredRecordsList;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.DeviceGroup;
|
||||
import hirs.persist.CriteriaModifier;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.DeviceManager;
|
||||
import hirs.persist.DeviceManagerException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.Criteria;
|
||||
@ -56,7 +60,7 @@ public class DBDeviceManager extends DBManager<Device> implements
|
||||
* @param device
|
||||
* device to save
|
||||
* @return reference to saved device
|
||||
* @throws DeviceManagerException
|
||||
* @throws hirs.persist.DeviceManagerException
|
||||
* if device has previously been saved or an error occurs
|
||||
* while trying to save it to the database
|
||||
*/
|
||||
@ -295,7 +299,7 @@ public class DBDeviceManager extends DBManager<Device> implements
|
||||
*
|
||||
* @param name of the device to be deleted
|
||||
* @return true if successfully found and deleted, false if otherwise
|
||||
* @throws DeviceGroupManagerException
|
||||
* @throws hirs.persist.DeviceGroupManagerException
|
||||
* if unable to find the device group or delete it from the
|
||||
* database
|
||||
*/
|
@ -1,7 +1,9 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.FilteredRecordsList;
|
||||
import hirs.data.persist.ArchivableEntity;
|
||||
import hirs.persist.CriteriaModifier;
|
||||
import hirs.persist.DBManagerException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.Criteria;
|
||||
@ -115,7 +117,7 @@ public class DBManager<T> extends AbstractDbManager<T> {
|
||||
* @param predicateCollection the collection of Criterion to apply
|
||||
*
|
||||
* @return a List of objects that match the criteria
|
||||
* @throws DBManagerException if an error is encountered while performing the query or creating
|
||||
* @throws hirs.persist.DBManagerException if an error is encountered while performing the query or creating
|
||||
* the result objects
|
||||
*/
|
||||
public final List<T> getWithCriteria(final Collection<Predicate> predicateCollection)
|
@ -1,10 +1,14 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import hirs.appraiser.Appraiser;
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.DeviceGroup;
|
||||
import hirs.data.persist.Policy;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.PolicyManager;
|
||||
import hirs.persist.PolicyManagerException;
|
||||
import hirs.persist.PolicyMapper;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.Session;
|
||||
@ -46,7 +50,7 @@ public class DBPolicyManager extends DBManager<Policy> implements PolicyManager
|
||||
* @param policy
|
||||
* policy to save
|
||||
* @return <code>Policy</code> that was saved
|
||||
* @throws PolicyManagerException
|
||||
* @throws hirs.persist.PolicyManagerException
|
||||
* if policy has previously been saved or an error occurs while
|
||||
* trying to save it to the database
|
||||
*/
|
@ -1,7 +1,10 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.data.persist.enums.PortalScheme;
|
||||
import hirs.data.persist.info.PortalInfo;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.PortalInfoManager;
|
||||
import hirs.persist.PortalInfoManagerException;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.SessionFactory;
|
||||
@ -36,7 +39,7 @@ public class DBPortalInfoManager extends DBManager<PortalInfo> implements Portal
|
||||
*
|
||||
* @param info PortalInfo to save
|
||||
* @return reference to saved PortalInfo
|
||||
* @throws PortalInfoManagerException if PortalInfo has previously been saved or an
|
||||
* @throws hirs.persist.PortalInfoManagerException if PortalInfo has previously been saved or an
|
||||
* error occurs while trying to save it to the database
|
||||
*/
|
||||
@Override
|
@ -1,10 +1,13 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.data.persist.BaseReferenceManifest;
|
||||
import hirs.data.persist.ReferenceDigestRecord;
|
||||
import hirs.data.persist.ReferenceDigestValue;
|
||||
import hirs.data.persist.ReferenceManifest;
|
||||
import hirs.data.persist.SupportReferenceManifest;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.DeviceManagerException;
|
||||
import hirs.persist.ReferenceEventManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.Session;
|
@ -1,8 +1,11 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.data.persist.ReferenceManifest;
|
||||
import hirs.persist.ReferenceManifestManager;
|
||||
import hirs.persist.ReferenceManifestSelector;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
@ -77,12 +80,12 @@ public class DBReferenceManifestManager extends DBManager<ReferenceManifest>
|
||||
|
||||
/**
|
||||
* This method does not need to be used directly as it is used by
|
||||
* {@link ReferenceManifestSelector}'s get* methods. Regardless, it may be
|
||||
* {@link hirs.persist.ReferenceManifestSelector}'s get* methods. Regardless, it may be
|
||||
* used to retrieve ReferenceManifest by other code in this package, given a
|
||||
* configured ReferenceManifestSelector.
|
||||
*
|
||||
* @param referenceManifestSelector a configured
|
||||
* {@link ReferenceManifestSelector} to use for querying
|
||||
* {@link hirs.persist.ReferenceManifestSelector} to use for querying
|
||||
* @return the resulting set of ReferenceManifest, possibly empty
|
||||
*/
|
||||
@Override
|
@ -1,6 +1,9 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.data.persist.Report;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.ReportManager;
|
||||
import hirs.persist.ReportManagerException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.SessionFactory;
|
||||
@ -41,7 +44,7 @@ public class DBReportManager extends DBManager<Report> implements ReportManager
|
||||
* @param report
|
||||
* report to save
|
||||
* @return <code>Report</code> that was saved
|
||||
* @throws DBManagerException
|
||||
* @throws hirs.persist.DBManagerException
|
||||
* if Report has previously been saved or an error occurs while
|
||||
* trying to save it to the database
|
||||
*/
|
@ -1,7 +1,8 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.data.persist.Device;
|
||||
import hirs.data.persist.ReportRequestState;
|
||||
import hirs.persist.ReportRequestStateManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.SessionFactory;
|
@ -1,6 +1,9 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.data.persist.ReportSummary;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.ReportSummaryManager;
|
||||
import hirs.persist.ReportSummaryManagerException;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
@ -48,7 +51,7 @@ public class DBReportSummaryManager extends DBManager<ReportSummary>
|
||||
* @param report
|
||||
* report summary to save
|
||||
* @return <code>ReportSummary</code> that was saved
|
||||
* @throws ReportSummaryManagerException
|
||||
* @throws hirs.persist.ReportSummaryManagerException
|
||||
* if ReportSummary has previously been saved or an error
|
||||
* occurs while trying to save it to the database
|
||||
*/
|
@ -1,5 +1,6 @@
|
||||
package hirs.persist;
|
||||
package hirs.attestationca.persist;
|
||||
|
||||
import hirs.persist.RepositoryManager;
|
||||
import hirs.repository.RepoPackage;
|
||||
import hirs.repository.Repository;
|
||||
import org.hibernate.SessionFactory;
|
||||
@ -9,7 +10,7 @@ import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class defines a {@link RepositoryManager} that stores Repositories and RepoPackages
|
||||
* This class defines a {@link hirs.persist.RepositoryManager} that stores Repositories and RepoPackages
|
||||
* in a database.
|
||||
*/
|
||||
@Service
|
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* Data access objects (DAOs) for storing and retrieving objects from the
|
||||
* database.
|
||||
*/
|
||||
|
||||
package hirs.attestationca.persist;
|
||||
|
@ -25,7 +25,6 @@ import hirs.persist.AppraiserManager;
|
||||
import hirs.persist.CertificateManager;
|
||||
import hirs.persist.CrudManager;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.PersistenceConfiguration;
|
||||
import hirs.persist.PolicyManager;
|
||||
import hirs.persist.ReferenceDigestManager;
|
||||
import hirs.persist.ReferenceEventManager;
|
||||
|
17
HIRS_AttestationCA/src/main/resources/persistence.properties
Normal file
17
HIRS_AttestationCA/src/main/resources/persistence.properties
Normal file
@ -0,0 +1,17 @@
|
||||
# Properties used to create JDBC connection
|
||||
# WARNING: DO NOT USE "disableSslHostnameVerification=true" FOR A REMOTE DATABASE
|
||||
persistence.db.url = jdbc:mariadb://localhost/hirs_db?autoReconnect=true&useSSL=true&requireSSL=true&enabledSslProtocolSuites=TLSv1&disableSslHostnameVerification=true
|
||||
persistence.db.username = hirs_db
|
||||
persistence.db.password = hirs_db
|
||||
persistence.db.driverClass = org.mariadb.jdbc.Driver
|
||||
persistence.db.maximumPoolSize = 10
|
||||
persistence.db.connectionTimeout = 30000
|
||||
persistence.db.leakDetectionThreshold = 0
|
||||
persistence.db.maxTransactionRetryAttempts = 10
|
||||
persistence.db.retryWaitTimeMilliseconds = 3000
|
||||
|
||||
# Properties used by the Hibernate Session Factory
|
||||
persistence.hibernate.dialect = hirs.utils.MySqlUtf8CompatibleDialect
|
||||
persistence.hibernate.ddl = update
|
||||
persistence.hibernate.contextClass = org.springframework.orm.hibernate5.SpringSessionContext
|
||||
persistence.hibernate.provider = org.hibernate.hikaricp.internal.HikariCPConnectionProvider
|
@ -17,9 +17,9 @@ import hirs.data.persist.certificate.PlatformCredential;
|
||||
import hirs.persist.AppraiserManager;
|
||||
import hirs.persist.CertificateManager;
|
||||
import hirs.persist.CrudManager;
|
||||
import hirs.persist.DBCertificateManager;
|
||||
import hirs.persist.DBDeviceGroupManager;
|
||||
import hirs.persist.DBDeviceManager;
|
||||
import hirs.attestationca.persist.DBCertificateManager;
|
||||
import hirs.attestationca.persist.DBDeviceGroupManager;
|
||||
import hirs.attestationca.persist.DBDeviceManager;
|
||||
import hirs.persist.DeviceGroupManager;
|
||||
import hirs.persist.DeviceManager;
|
||||
import hirs.persist.PolicyManager;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package hirs.attestationca.portal.page;
|
||||
|
||||
import hirs.attestationca.portal.datatables.DataTableView;
|
||||
import hirs.persist.PersistenceConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
@ -9,7 +9,7 @@ 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.attestationca.persist.DBManager;
|
||||
import hirs.persist.DeviceManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.criterion.Restrictions;
|
||||
|
@ -13,8 +13,8 @@ import hirs.data.persist.SupportReferenceManifest;
|
||||
import hirs.data.persist.certificate.Certificate;
|
||||
import hirs.persist.CriteriaModifier;
|
||||
import hirs.persist.DBManagerException;
|
||||
import hirs.persist.DBReferenceEventManager;
|
||||
import hirs.persist.DBReferenceManifestManager;
|
||||
import hirs.attestationca.persist.DBReferenceEventManager;
|
||||
import hirs.attestationca.persist.DBReferenceManifestManager;
|
||||
import hirs.persist.ReferenceEventManager;
|
||||
import hirs.persist.ReferenceManifestManager;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
@ -1,6 +1,5 @@
|
||||
package integration.hirs.repository.spacewalk;
|
||||
|
||||
import hirs.persist.PersistenceConfiguration;
|
||||
import hirs.persist.RepositoryManager;
|
||||
import hirs.repository.RepositoryException;
|
||||
import hirs.repository.RepositoryUpdateService;
|
||||
|
@ -15,7 +15,7 @@ public class AppraiserManagerException extends RuntimeException {
|
||||
* @param msg
|
||||
* exception message
|
||||
*/
|
||||
AppraiserManagerException(final String msg) {
|
||||
public AppraiserManagerException(final String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ public class AppraiserManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
AppraiserManagerException(final Throwable t) {
|
||||
public AppraiserManagerException(final Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class AppraiserManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
AppraiserManagerException(final String msg, final Throwable t) {
|
||||
public AppraiserManagerException(final String msg, final Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ import java.util.UUID;
|
||||
|
||||
/**
|
||||
* This class is used to select one or many certificates in conjunction
|
||||
* with a {@link CertificateManager}. To make use of this object,
|
||||
* with a {@link hirs.persist.CertificateManager}. To make use of this object,
|
||||
* use (some CertificateImpl).select(CertificateManager).
|
||||
*
|
||||
* This class loosely follows the builder pattern. It is instantiated with
|
||||
|
@ -39,7 +39,7 @@ public class DBManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
DBManagerException(final String msg, final Throwable t) {
|
||||
public DBManagerException(final String msg, final Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ public class DeviceGroupManagerException extends RuntimeException {
|
||||
* @param msg
|
||||
* exception message
|
||||
*/
|
||||
DeviceGroupManagerException(final String msg) {
|
||||
public DeviceGroupManagerException(final String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ public class DeviceGroupManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
DeviceGroupManagerException(final Throwable t) {
|
||||
public DeviceGroupManagerException(final Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class DeviceGroupManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
DeviceGroupManagerException(final String msg, final Throwable t) {
|
||||
public DeviceGroupManagerException(final String msg, final Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class DeviceManagerException extends RuntimeException {
|
||||
* @param msg
|
||||
* exception message
|
||||
*/
|
||||
DeviceManagerException(final String msg) {
|
||||
public DeviceManagerException(final String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ public class DeviceManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
DeviceManagerException(final Throwable t) {
|
||||
public DeviceManagerException(final Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class DeviceManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
DeviceManagerException(final String msg, final Throwable t) {
|
||||
public DeviceManagerException(final String msg, final Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
|
||||
|
@ -1,211 +0,0 @@
|
||||
package hirs.persist;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.context.annotation.PropertySources;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
import org.springframework.jdbc.datasource.DriverManagerDataSource;
|
||||
import org.springframework.orm.hibernate5.HibernateTransactionManager;
|
||||
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* A spring configuration that houses the properties associated with the hibernate connection
|
||||
* to the database. Beans for classes doing actual queries on DB tables should go in to a separate
|
||||
* configuration (which would likely import this configuration).
|
||||
*/
|
||||
@Configuration
|
||||
@EnableTransactionManagement
|
||||
@PropertySources(value = {
|
||||
@PropertySource(value = "file:/etc/hirs/persistence.properties", ignoreResourceNotFound =
|
||||
true),
|
||||
@PropertySource(value = "classpath:persistence.properties"),
|
||||
@PropertySource(value = "classpath:persistence-extended.properties",
|
||||
ignoreResourceNotFound = true)
|
||||
})
|
||||
public class HibernateConfiguration {
|
||||
|
||||
@Value("${persistence.db.url}")
|
||||
private String url;
|
||||
|
||||
@Value("${persistence.db.username}")
|
||||
private String username;
|
||||
|
||||
@Value("${persistence.db.password}")
|
||||
private String password;
|
||||
|
||||
@Value("${persistence.db.driverClass}")
|
||||
private String driverClass;
|
||||
|
||||
@Value("${persistence.db.maximumPoolSize}")
|
||||
private String maximumPoolSize;
|
||||
|
||||
@Value("${persistence.db.connectionTimeout}")
|
||||
private String connectionTimeout;
|
||||
|
||||
@Value("${persistence.db.leakDetectionThreshold}")
|
||||
private String leakDetectionThreshold;
|
||||
|
||||
@Value("${persistence.hibernate.dialect}")
|
||||
private String dialect;
|
||||
|
||||
@Value("${persistence.hibernate.ddl}")
|
||||
private String ddl;
|
||||
|
||||
@Value("${persistence.hibernate.contextClass}")
|
||||
private String contextClass;
|
||||
|
||||
@Value("${persistence.hibernate.provider}")
|
||||
private String provider;
|
||||
|
||||
@Value("${persistence.db.maxTransactionRetryAttempts}")
|
||||
private int maxTransactionRetryAttempts;
|
||||
|
||||
@Value("${persistence.db.retryWaitTimeMilliseconds}")
|
||||
private long retryWaitTimeMilliseconds;
|
||||
|
||||
/**
|
||||
* @return bean to resolve injected Value.
|
||||
* property expressions for beans.
|
||||
*/
|
||||
@Bean
|
||||
public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
|
||||
return new PropertySourcesPlaceholderConfigurer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the data source to be used by the hibernate session factory.
|
||||
*
|
||||
* @return configured data source
|
||||
*/
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
DriverManagerDataSource dataSource = new DriverManagerDataSource();
|
||||
dataSource.setUrl(url);
|
||||
dataSource.setUsername(username);
|
||||
dataSource.setPassword(password);
|
||||
dataSource.setDriverClassName(driverClass);
|
||||
|
||||
// dataSource.setMaximumPoolSize(Integer.parseInt(maximumPoolSize));
|
||||
// dataSource.setConnectionTimeout(Long.parseLong(connectionTimeout));
|
||||
// dataSource.setLeakDetectionThreshold(Long.parseLong(leakDetectionThreshold));
|
||||
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates properties using configuration file that will be used to configure the session
|
||||
* factory.
|
||||
*
|
||||
* @return properties for hibernate session factory
|
||||
*/
|
||||
@Bean
|
||||
public Properties hibernateProperties() {
|
||||
Properties properties = new Properties();
|
||||
properties.put("hibernate.hbm2ddl.auto", ddl);
|
||||
properties.put("hibernate.dialect", dialect);
|
||||
properties.put("hibernate.current_session_context_class", "thread");
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
// Hibernate 5.4 SessionFactory example without XML
|
||||
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.setPackagesToScan("hirs");
|
||||
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.
|
||||
*
|
||||
* @return transaction manager
|
||||
*/
|
||||
@Bean
|
||||
public HibernateTransactionManager getTransactionManager() {
|
||||
HibernateTransactionManager transactionManager = new HibernateTransactionManager();
|
||||
transactionManager.setSessionFactory(sessionFactory().getObject());
|
||||
return transactionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bean holding the maximum retry attempts for a DB transaction.
|
||||
* @return the maximum retry count
|
||||
*/
|
||||
@Bean(name = "maxTransactionRetryAttempts")
|
||||
public int maxTransactionRetryAttempts() {
|
||||
return maxTransactionRetryAttempts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bean holding the time to wait until retrying a failed transaction.
|
||||
* @return the wait time, in milliseconds
|
||||
*/
|
||||
@Bean(name = "retryWaitTimeMilliseconds")
|
||||
public long retryWaitTimeMilliseconds() {
|
||||
return retryWaitTimeMilliseconds;
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ public class PolicyManagerException extends RuntimeException {
|
||||
* @param msg
|
||||
* exception message
|
||||
*/
|
||||
PolicyManagerException(final String msg) {
|
||||
public PolicyManagerException(final String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ public class PolicyManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
PolicyManagerException(final Throwable t) {
|
||||
public PolicyManagerException(final Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class PolicyManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
PolicyManagerException(final String msg, final Throwable t) {
|
||||
public PolicyManagerException(final String msg, final Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class PortalInfoManagerException extends RuntimeException {
|
||||
*
|
||||
* @param msg exception message
|
||||
*/
|
||||
PortalInfoManagerException(final String msg) {
|
||||
public PortalInfoManagerException(final String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ public class PortalInfoManagerException extends RuntimeException {
|
||||
*
|
||||
* @param t root cause
|
||||
*/
|
||||
PortalInfoManagerException(final Throwable t) {
|
||||
public PortalInfoManagerException(final Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ public class PortalInfoManagerException extends RuntimeException {
|
||||
* @param msg exception message
|
||||
* @param t root cause
|
||||
*/
|
||||
PortalInfoManagerException(final String msg, final Throwable t) {
|
||||
public PortalInfoManagerException(final String msg, final Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ public class ReportManagerException extends RuntimeException {
|
||||
* @param msg
|
||||
* exception message
|
||||
*/
|
||||
ReportManagerException(final String msg) {
|
||||
public ReportManagerException(final String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ public class ReportManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
ReportManagerException(final Throwable t) {
|
||||
public ReportManagerException(final Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class ReportManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
ReportManagerException(final String msg, final Throwable t) {
|
||||
public ReportManagerException(final String msg, final Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ public class ReportSummaryManagerException extends RuntimeException {
|
||||
* @param msg
|
||||
* exception message
|
||||
*/
|
||||
ReportSummaryManagerException(final String msg) {
|
||||
public ReportSummaryManagerException(final String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ public class ReportSummaryManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
ReportSummaryManagerException(final Throwable t) {
|
||||
public ReportSummaryManagerException(final Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
@ -36,7 +36,7 @@ public class ReportSummaryManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
ReportSummaryManagerException(final String msg, final Throwable t) {
|
||||
public ReportSummaryManagerException(final String msg, final Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
}
|
||||
|
@ -1,193 +0,0 @@
|
||||
package hirs.persist;
|
||||
|
||||
import hirs.appraiser.Appraiser;
|
||||
import hirs.appraiser.AppraiserPlugin;
|
||||
import hirs.appraiser.AppraiserPluginManager;
|
||||
import hirs.appraiser.DeviceInfoAppraiser;
|
||||
import hirs.appraiser.HIRSAppraiser;
|
||||
import hirs.appraiser.IMAAppraiser;
|
||||
import hirs.appraiser.TPMAppraiser;
|
||||
import hirs.data.persist.DeviceGroup;
|
||||
import hirs.data.persist.HIRSPolicy;
|
||||
import hirs.data.persist.Policy;
|
||||
import hirs.utils.HIRSProfiles;
|
||||
import hirs.utils.SpringContextProvider;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
|
||||
import org.springframework.core.type.filter.AssignableTypeFilter;
|
||||
import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* This class initializes the system for appraisals. This stores the requisite items in the database
|
||||
* to ensure that an appraisal can happen. For example, the system requires that a set of
|
||||
* <code>Appraiser</code>s be defined in the database. This class will initialize the set of
|
||||
* <code>Appraiser</code>s.
|
||||
*/
|
||||
public final class SystemInit {
|
||||
private static final Logger LOGGER = LogManager.getLogger(SystemInit.class);
|
||||
private static final int ALL_MASK = 0xFFFFFF;
|
||||
private static final int NONE_MASK = 0x000000;
|
||||
|
||||
private static final String IMA_POLICY_NAME = "Test IMA Policy";
|
||||
private static final String TPM_POLICY_NAME = "Test TPM Policy";
|
||||
|
||||
/**
|
||||
* Default constructor that does nothing.
|
||||
*/
|
||||
private SystemInit() {
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the system by creating a new <code>IMAAppraiser</code> and storing it in the
|
||||
* database.
|
||||
* <p>
|
||||
* This method is currently available for command line use, but is not used within the project.
|
||||
*
|
||||
* @param args not used
|
||||
*/
|
||||
@SuppressWarnings("checkstyle:methodlength")
|
||||
public static void main(final String[] args) {
|
||||
LOGGER.info("Seeding database with initial entries...");
|
||||
// construct application context
|
||||
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
context.getEnvironment().addActiveProfile(HIRSProfiles.SERVER);
|
||||
|
||||
// create class path scanner for discovering appraiser plugins
|
||||
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context, false);
|
||||
scanner.addIncludeFilter(new AssignableTypeFilter(AppraiserPlugin.class));
|
||||
scanner.addIncludeFilter(new AssignableTypeFilter(SpringContextProvider.class));
|
||||
scanner.addIncludeFilter(new AssignableTypeFilter(AppraiserPluginManager.class));
|
||||
|
||||
// scan for appraiser plugins
|
||||
int registeredBeanCount = scanner.scan("hirs");
|
||||
System.out.println("Beans scanned " + registeredBeanCount);
|
||||
LOGGER.info("Beans scanned: " + registeredBeanCount);
|
||||
|
||||
// register the database configuration and refresh the context
|
||||
context.register(PersistenceConfiguration.class);
|
||||
context.refresh();
|
||||
|
||||
// obtain reference to hibernate session factory
|
||||
SessionFactory sessionFactory = context.getBean(LocalSessionFactoryBean.class).getObject();
|
||||
|
||||
// initialize the managers for this initialization process
|
||||
final DeviceGroupManager deviceGroupManager = new DBDeviceGroupManager(sessionFactory);
|
||||
final AppraiserManager appraiserManager = new DBAppraiserManager(sessionFactory);
|
||||
final PolicyManager policyManager = new DBPolicyManager(sessionFactory);
|
||||
|
||||
// save the default group
|
||||
LOGGER.info("Checking for default device group...");
|
||||
if (deviceGroupManager.getDeviceGroup(DeviceGroup.DEFAULT_GROUP) == null) {
|
||||
LOGGER.info("Default device group not found; creating...");
|
||||
deviceGroupManager.saveDeviceGroup(
|
||||
new DeviceGroup(DeviceGroup.DEFAULT_GROUP, "This is the default group")
|
||||
);
|
||||
LOGGER.info("Default device group saved.");
|
||||
} else {
|
||||
LOGGER.info("Default device group found.");
|
||||
}
|
||||
|
||||
// initiate all the appraisers
|
||||
LOGGER.info("Checking for HIRS appraiser...");
|
||||
HIRSAppraiser hirsApp = (HIRSAppraiser) appraiserManager.getAppraiser(HIRSAppraiser.NAME);
|
||||
if (hirsApp == null) {
|
||||
LOGGER.info("HIRS appraiser not found; creating...");
|
||||
hirsApp = (HIRSAppraiser) appraiserManager.saveAppraiser(new HIRSAppraiser());
|
||||
} else {
|
||||
LOGGER.info("HIRS appraiser found.");
|
||||
}
|
||||
|
||||
LOGGER.info("Checking for IMA appraiser...");
|
||||
IMAAppraiser imaApp = (IMAAppraiser) appraiserManager.getAppraiser(IMAAppraiser.NAME);
|
||||
if (imaApp == null) {
|
||||
LOGGER.info("IMA appraiser not found; creating...");
|
||||
// imaApp = (IMAAppraiser) appraiserManager.saveAppraiser(new IMAAppraiser());
|
||||
} else {
|
||||
LOGGER.info("IMA appraiser found.");
|
||||
}
|
||||
|
||||
LOGGER.info("Checking for TPM appraiser...");
|
||||
TPMAppraiser tpmApp = (TPMAppraiser) appraiserManager.getAppraiser(TPMAppraiser.NAME);
|
||||
if (tpmApp == null) {
|
||||
LOGGER.info("TPM appraiser not found; creating...");
|
||||
// tpmApp = (TPMAppraiser) appraiserManager.saveAppraiser(new TPMAppraiser());
|
||||
} else {
|
||||
LOGGER.info("TPM appraiser found.");
|
||||
}
|
||||
|
||||
LOGGER.info("Checking for DeviceInfo appraiser...");
|
||||
DeviceInfoAppraiser deviceInfoAppraiser = (DeviceInfoAppraiser)
|
||||
appraiserManager.getAppraiser(DeviceInfoAppraiser.NAME);
|
||||
if (deviceInfoAppraiser == null) {
|
||||
LOGGER.info("DeviceInfo appraiser not found; creating...");
|
||||
appraiserManager.saveAppraiser(new DeviceInfoAppraiser());
|
||||
} else {
|
||||
LOGGER.info("DeviceInfo appraiser found.");
|
||||
}
|
||||
|
||||
// build up required appraisers set
|
||||
Set<Class<? extends Appraiser>> requiredAppraisers = new HashSet<>();
|
||||
requiredAppraisers.add(DeviceInfoAppraiser.class);
|
||||
requiredAppraisers.add(TPMAppraiser.class);
|
||||
requiredAppraisers.add(IMAAppraiser.class);
|
||||
|
||||
// obtain plugins from the context
|
||||
Collection<AppraiserPlugin> appraiserPlugins =
|
||||
context.getBeansOfType(AppraiserPlugin.class).values();
|
||||
|
||||
LOGGER.info("Total Appraiser Plugins: " + appraiserPlugins.size());
|
||||
System.out.println("Total Appraiser Plugins: " + appraiserPlugins.size());
|
||||
|
||||
// merge the appraiser plugins with the hirs policy appraisers
|
||||
for (AppraiserPlugin appraiserPlugin : appraiserPlugins) {
|
||||
// add in appraiser plugin to required appraisers list
|
||||
requiredAppraisers.add(appraiserPlugin.getClass());
|
||||
|
||||
LOGGER.info("Checking for plugin appraiser {}...", appraiserPlugin);
|
||||
Appraiser storedAppraiser = appraiserManager.getAppraiser(appraiserPlugin.getName());
|
||||
if (storedAppraiser == null) {
|
||||
LOGGER.info("Saving plugin appraiser {}...", appraiserPlugin);
|
||||
storedAppraiser = appraiserManager.saveAppraiser(appraiserPlugin);
|
||||
} else {
|
||||
LOGGER.info("Found plugin appraiser {}.", appraiserPlugin);
|
||||
}
|
||||
|
||||
Policy policy = appraiserPlugin.getDefaultPolicy();
|
||||
if (policy != null) {
|
||||
LOGGER.info("Saving plugin appraiser's default policy: {}", policy);
|
||||
policy = policyManager.savePolicy(policy);
|
||||
policyManager.setDefaultPolicy(storedAppraiser, policy);
|
||||
}
|
||||
}
|
||||
|
||||
// create HIRS policy
|
||||
LOGGER.info("Checking for HIRS policy...");
|
||||
HIRSPolicy hirsPolicy = (HIRSPolicy) policyManager.getPolicy(
|
||||
HIRSPolicy.DEFAULT_HIRS_POLICY_NAME
|
||||
);
|
||||
if (hirsPolicy == null) {
|
||||
LOGGER.info(
|
||||
"HIRS policy not found; saving with required appraisers: {}",
|
||||
requiredAppraisers
|
||||
);
|
||||
hirsPolicy = new HIRSPolicy(HIRSPolicy.DEFAULT_HIRS_POLICY_NAME);
|
||||
hirsPolicy.setRequiredAppraisers(requiredAppraisers);
|
||||
|
||||
// initialize the default policy
|
||||
policyManager.savePolicy(hirsPolicy);
|
||||
policyManager.setDefaultPolicy(hirsApp, hirsPolicy);
|
||||
} else {
|
||||
LOGGER.info("HIRS policy found.");
|
||||
}
|
||||
|
||||
LOGGER.info("Complete.");
|
||||
}
|
||||
}
|
@ -15,7 +15,7 @@ public class TPMDeviceStateManagerException extends RuntimeException {
|
||||
* @param msg
|
||||
* exception message
|
||||
*/
|
||||
TPMDeviceStateManagerException(final String msg) {
|
||||
public TPMDeviceStateManagerException(final String msg) {
|
||||
super(msg);
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ public class TPMDeviceStateManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
TPMDeviceStateManagerException(final Throwable t) {
|
||||
public TPMDeviceStateManagerException(final Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ public class TPMDeviceStateManagerException extends RuntimeException {
|
||||
* @param t
|
||||
* root cause
|
||||
*/
|
||||
TPMDeviceStateManagerException(final String msg, final Throwable t) {
|
||||
public TPMDeviceStateManagerException(final String msg, final Throwable t) {
|
||||
super(msg, t);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package hirs.data.persist;
|
||||
|
||||
import hirs.persist.PersistenceConfiguration;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
@ -326,7 +326,7 @@ mkdir -p %{buildroot}/opt/hirs/default-properties/provisioner
|
||||
cp HIRS_Utils/src/main/resources/logging.properties %{buildroot}/opt/hirs/default-properties/provisioner/logging.properties
|
||||
|
||||
mkdir -p %{buildroot}/opt/hirs/default-properties/attestationca
|
||||
cp HIRS_Utils/src/main/resources/persistence.properties %{buildroot}/opt/hirs/default-properties/attestationca/
|
||||
cp HIRS_AttestationCA/src/main/resources/persistence.properties %{buildroot}/opt/hirs/default-properties/attestationca/
|
||||
cp HIRS_Utils/src/main/resources/logging.properties %{buildroot}/opt/hirs/default-properties/attestationca/
|
||||
cp HIRS_Utils/src/main/resources/banner.properties %{buildroot}/opt/hirs/default-properties/attestationca/
|
||||
cp HIRS_Utils/src/main/resources/component-class.json %{buildroot}/opt/hirs/default-properties/
|
||||
|
Loading…
x
Reference in New Issue
Block a user