These changes cleaned up the settings code and runs with out error for

changing policy settings.
This commit is contained in:
Cyrus 2023-02-14 15:22:37 -05:00
parent 72aa426018
commit b4328e1288
11 changed files with 58 additions and 51 deletions

View File

@ -1,6 +1,5 @@
package hirs.attestationca.portal;
import hirs.attestationca.portal.entity.userdefined.SupplyChainSettings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@ -77,11 +76,11 @@ public class PersistenceJPAConfig {
return hibernateProperties;
}
@Bean(name="default-settings")
public SupplyChainSettings supplyChainSettings() {
SupplyChainSettings scSettings = new SupplyChainSettings("Default", "Settings are configured for no validation flags set.");
return scSettings;
}
//
// @Bean(name="default-settings")
// public SupplyChainSettings supplyChainSettings() {
// SupplyChainSettings scSettings = new SupplyChainSettings("Default", "Settings are configured for no validation flags set.");
//
// return scSettings;
// }
}

View File

@ -47,6 +47,17 @@ public abstract class AbstractEntity implements Serializable {
super();
}
/**
* Setter for the UUID that can not be null
* and can not be overridden.
* @param id - primary able key
*/
public void setId(UUID id) {
if (id != null) {
this.id = id;
}
}
/**
* Returns the creation time of this entity.
*

View File

@ -60,10 +60,10 @@ public abstract class Policy extends UserDefinedEntity {
}
/**
* When {@link hirs.attestationca.portal.entity.Policy} are serialized to be sent to the browser, this can be used
* to determine the type of {@link hirs.attestationca.portal.entity.Policy}.
* When {@link Policy} are serialized to be sent to the browser, this can be used
* to determine the type of {@link Policy}.
*
* @return The class name for the {@link hirs.attestationca.portal.entity.Policy}
* @return The class name for the {@link Policy}
*/
public String getType() {
return this.getClass().getSimpleName();

View File

@ -8,8 +8,6 @@ import java.util.List;
import java.util.UUID;
@Repository
public interface DeviceRepository extends CrudRepository<Device, UUID> {
public interface DeviceRepository extends JpaRepository<Device, UUID> {
List<Device> findByName(String deviceName);
}

View File

@ -6,6 +6,7 @@ import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
/**
* Class represents Supply Chain policy. Supply Chain Policy identifies the methods in
@ -16,6 +17,7 @@ import lombok.Setter;
@Getter
@Setter
@Entity
@ToString(callSuper = true)
public class SupplyChainSettings extends UserDefinedEntity {
/**
* Name of the default Supply Chain Policy.

View File

@ -116,7 +116,7 @@ public abstract class PageController<P extends PageParams> {
* @param model The model data to pass to the page.
* @param attr The request's RedirectAttributes to hold the model data.
* @return RedirectView back to the page with the specified parameters.
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
protected final RedirectView redirectToSelf(
final P params,
@ -134,7 +134,7 @@ public abstract class PageController<P extends PageParams> {
* @param model The model data to pass to the page.
* @param attr The request's RedirectAttributes to hold the model data.
* @return RedirectView back to the page with the specified parameters.
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
protected final RedirectView redirectTo(
final Page newPage,
@ -145,7 +145,7 @@ public abstract class PageController<P extends PageParams> {
String defaultUri = "../" + newPage.getViewName();
// create uri with specified parameters
URIBuilder uri = new URIBuilder("../" + newPage.getViewName());
LOGGER.error(uri.toString());
LOGGER.debug("Redirection URI = " + uri.toString());
if (params != null) {
for (Map.Entry<String, ?> e : params.asMap().entrySet()) {

View File

@ -13,7 +13,6 @@ import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@ -86,6 +85,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
ModelAndView mav = getBaseModelAndView();
SupplyChainSettings policy = getDefaultPolicy();
LOGGER.debug(policy);
PolicyPageModel pageModel = new PolicyPageModel(policy);
mav.addObject(INITIAL_DATA, pageModel);
@ -102,9 +102,8 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @param attr RedirectAttributes used to forward data back to the original
* page.
* @return View containing the url and parameters
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
@GetMapping
@RequestMapping(value = "update-pc-validation", method = RequestMethod.POST)
public RedirectView updatePcVal(@ModelAttribute final PolicyPageModel ppModel,
final RedirectAttributes attr) throws URISyntaxException {
@ -154,9 +153,8 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @param attr RedirectAttributes used to forward data back to the original
* page.
* @return View containing the url and parameters
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
@GetMapping
@RequestMapping(value = "update-pc-attribute-validation", method = RequestMethod.POST)
public RedirectView updatePcAttributeVal(@ModelAttribute final PolicyPageModel ppModel,
final RedirectAttributes attr)
@ -204,7 +202,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @param ppModel The data posted by the form mapped into an object.
* @param attr RedirectAttributes used to forward data back to the original page.
* @return View containing the url and parameters
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
@RequestMapping(value = "update-issue-attestation", method = RequestMethod.POST)
public RedirectView updateAttestationVal(@ModelAttribute final PolicyPageModel ppModel,
@ -248,7 +246,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @param ppModel The data posted by the form mapped into an object.
* @param attr RedirectAttributes used to forward data back to the original page.
* @return View containing the url and parameters
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
@RequestMapping(value = "update-issue-devid", method = RequestMethod.POST)
public RedirectView updateDevIdVal(@ModelAttribute final PolicyPageModel ppModel,
@ -293,7 +291,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @param ppModel The data posted by the form mapped into an object.
* @param attr RedirectAttributes used to forward data back to the original page.
* @return View containing the url and parameters
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
@RequestMapping(value = "update-expire-on", method = RequestMethod.POST)
public RedirectView updateExpireOnVal(@ModelAttribute final PolicyPageModel ppModel,
@ -363,7 +361,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @param ppModel The data posted by the form mapped into an object.
* @param attr RedirectAttributes used to forward data back to the original page.
* @return View containing the url and parameters
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
@RequestMapping(value = "update-devid-expire-on", method = RequestMethod.POST)
public RedirectView updateDevIdExpireOnVal(@ModelAttribute final PolicyPageModel ppModel,
@ -433,7 +431,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @param ppModel The data posted by the form mapped into an object.
* @param attr RedirectAttributes used to forward data back to the original page.
* @return View containing the url and parameters
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
@RequestMapping(value = "update-threshold", method = RequestMethod.POST)
public RedirectView updateThresholdVal(@ModelAttribute final PolicyPageModel ppModel,
@ -504,7 +502,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @param ppModel The data posted by the form mapped into an object.
* @param attr RedirectAttributes used to forward data back to the original page.
* @return View containing the url and parameters
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
@RequestMapping(value = "update-devid-threshold", method = RequestMethod.POST)
public RedirectView updateDevIdThresholdVal(@ModelAttribute final PolicyPageModel ppModel,
@ -574,7 +572,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @param attr RedirectAttributes used to forward data back to the original
* page.
* @return View containing the url and parameters
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
@RequestMapping(value = "update-ec-validation", method = RequestMethod.POST)
public RedirectView updateEcVal(@ModelAttribute final PolicyPageModel ppModel,
@ -626,7 +624,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @param attr RedirectAttributes used to forward data back to the original
* page.
* @return View containing the url and parameters
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
@RequestMapping(value = "update-firmware-validation", method = RequestMethod.POST)
public RedirectView updateFirmwareVal(@ModelAttribute final PolicyPageModel ppModel,
@ -683,7 +681,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @param attr RedirectAttributes used to forward data back to the original
* page.
* @return View containing the url and parameters
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
@RequestMapping(value = "update-ima-ignore", method = RequestMethod.POST)
public RedirectView updateIgnoreIma(@ModelAttribute final PolicyPageModel ppModel,
@ -734,7 +732,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @param attr RedirectAttributes used to forward data back to the original
* page.
* @return View containing the url and parameters
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
@RequestMapping(value = "update-tboot-ignore", method = RequestMethod.POST)
public RedirectView updateIgnoreTboot(@ModelAttribute final PolicyPageModel ppModel,
@ -785,7 +783,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @param attr RedirectAttributes used to forward data back to the original
* page.
* @return View containing the url and parameters
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
@RequestMapping(value = "update-gpt-ignore", method = RequestMethod.POST)
public RedirectView updateIgnoreGptEvents(@ModelAttribute final PolicyPageModel ppModel,
@ -836,7 +834,7 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @param attr RedirectAttributes used to forward data back to the original
* page.
* @return View containing the url and parameters
* @throws java.net.URISyntaxException if malformed URI
* @throws URISyntaxException if malformed URI
*/
@RequestMapping(value = "update-os-evt-ignore", method = RequestMethod.POST)
public RedirectView updateIgnoreOsEvents(
@ -923,11 +921,12 @@ public class PolicyPageController extends PageController<NoPageParams> {
* @return The default Supply Chain Policy
*/
private SupplyChainSettings getDefaultPolicy() {
// final Appraiser supplyChainAppraiser = appraiserService.getAppraiser(
// SupplyChainAppraiser.NAME);
return new SupplyChainSettings("Default");
// return (SupplyChainSettings) policyService.getDefaultPolicy(
// supplyChainAppraiser);
SupplyChainSettings defaultSettings = this.settingsService.getByName("Default");
if (defaultSettings == null) {
defaultSettings = new SupplyChainSettings("Default", "Settings are configured for no validation flags set.");
}
return defaultSettings;
}
/**

View File

@ -1,5 +1,6 @@
package hirs.attestationca.portal.service;
import hirs.attestationca.portal.entity.manager.DeviceRepository;
import hirs.attestationca.portal.entity.userdefined.Device;
import hirs.attestationca.portal.enums.AppraisalStatus;
import hirs.attestationca.portal.enums.HealthStatus;
@ -21,6 +22,8 @@ public class DeviceServiceImpl {
@Autowired(required = false)
private EntityManager entityManager;
@Autowired
private DeviceRepository deviceRepository;
private static List<Device> devices = new ArrayList<>(Arrays.asList(
new Device("Dell", HealthStatus.TRUSTED,

View File

@ -6,8 +6,6 @@ import jakarta.persistence.EntityManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.UUID;
@Service
public class SettingsServiceImpl {
@ -17,15 +15,12 @@ public class SettingsServiceImpl {
@Autowired
private SettingsRepository repository;
public SupplyChainSettings updateSettings(SupplyChainSettings settings, UUID uuid) {
if (repository.existsById(uuid)) {
// already in DB
}
return updateSettings(settings);
}
public SupplyChainSettings updateSettings(SupplyChainSettings settings) {
SupplyChainSettings existing = repository.findByName(settings.getName());
if (existing != null) {
settings.setId(existing.getId());
}
return repository.save(settings);
}

View File

@ -43,7 +43,7 @@ public class BannerConfiguration {
* Verify if the file exist, if it does it will get all the
* properties values and save them on the class.
*
* @throws java.io.IOException the banner level for the web site.
* @throws IOException the banner level for the web site.
*/
public BannerConfiguration() throws IOException {
if (!Files.exists(BANNER_PROPERTIES_PATH)) {

View File

@ -47,7 +47,7 @@ public final class VersionHelper {
* Read the symbolic link to VERSION in the top level HIRS directory.
* @param filename "VERSION"
* @return the version number from the file
* @throws java.io.IOException
* @throws IOException
*/
private static String getFileContents(final String filename) throws IOException {
URL url = Resources.getResource(filename);