mirror of
https://github.com/nsacyber/HIRS.git
synced 2024-12-21 22:07:57 +00:00
Additional bug fixes
This commit is contained in:
parent
8a8fca726c
commit
977e4c6576
@ -1,6 +1,5 @@
|
||||
package hirs.data.persist;
|
||||
|
||||
import lombok.Data;
|
||||
import org.bouncycastle.util.Arrays;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
@ -20,7 +19,6 @@ import java.util.UUID;
|
||||
* Digest Value, Event Type, index, RIM Tagid
|
||||
*/
|
||||
@Entity
|
||||
@Data
|
||||
@Table(name = "ReferenceDigestValue")
|
||||
@XmlRootElement(name = "ReferenceDigestValue")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
|
@ -20,20 +20,16 @@ import org.springframework.stereotype.Service;
|
||||
public class DeviceRegisterImpl implements DeviceRegister {
|
||||
|
||||
private DeviceManager deviceManager;
|
||||
private DeviceGroupManager deviceGroupManager;
|
||||
|
||||
private static final Logger LOGGER = LogManager.getLogger(DeviceRegisterImpl.class);
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* @param deviceManager the device manager
|
||||
* @param deviceGroupManager the device group manager
|
||||
*/
|
||||
@Autowired
|
||||
public DeviceRegisterImpl(final DeviceManager deviceManager,
|
||||
final DeviceGroupManager deviceGroupManager) {
|
||||
public DeviceRegisterImpl(final DeviceManager deviceManager) {
|
||||
this.deviceManager = deviceManager;
|
||||
this.deviceGroupManager = deviceGroupManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -59,8 +55,6 @@ public class DeviceRegisterImpl implements DeviceRegister {
|
||||
|
||||
LOGGER.debug("device not found, saving new device");
|
||||
Device newDevice = new Device(deviceName, report);
|
||||
DeviceGroup group = deviceGroupManager.getDeviceGroup(DeviceGroup.DEFAULT_GROUP);
|
||||
newDevice.setDeviceGroup(group);
|
||||
deviceManager.saveDevice(newDevice);
|
||||
return newDevice;
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
package hirs.persist;
|
||||
|
||||
import static org.apache.logging.log4j.LogManager.getLogger;
|
||||
import hirs.appraiser.Appraiser;
|
||||
import hirs.data.persist.policy.Policy;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
@ -14,7 +14,7 @@ import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import static org.apache.logging.log4j.LogManager.getLogger;
|
||||
|
||||
/**
|
||||
* Maps an <code>Appraiser</code> to its default <code>Policy</code>. This class
|
||||
@ -37,9 +37,6 @@ public final class PolicyMapper {
|
||||
@ManyToOne
|
||||
@JoinColumn(nullable = true, name = "Policy_ID")
|
||||
private Policy policy;
|
||||
@ManyToOne
|
||||
@JoinColumn(nullable = true, name = "Device_Group_ID")
|
||||
private DeviceGroup deviceGroup;
|
||||
|
||||
/**
|
||||
* Creates a new <code>DefaultPolicyMapper</code>. This maps the default
|
||||
@ -57,29 +54,6 @@ public final class PolicyMapper {
|
||||
setPolicy(policy);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new <code>PolicyMapper</code>. This maps the policy
|
||||
* <code>policy</code> to the <code>Appraiser</code> and
|
||||
* <code>DeviceGroup</code>.
|
||||
*
|
||||
* @param appraiser
|
||||
* appraiser
|
||||
* @param policy
|
||||
* policy
|
||||
* @param deviceGroup
|
||||
* deviceGroup
|
||||
*/
|
||||
public PolicyMapper(final Appraiser appraiser, final Policy policy,
|
||||
final DeviceGroup deviceGroup) {
|
||||
if (appraiser == null) {
|
||||
LOGGER.error("creating default policy mapper with null appraiser");
|
||||
throw new NullPointerException("appraiser");
|
||||
}
|
||||
this.appraiser = appraiser;
|
||||
setPolicy(policy);
|
||||
this.deviceGroup = deviceGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default constructor needed by Hibernate.
|
||||
*/
|
||||
@ -118,24 +92,4 @@ public final class PolicyMapper {
|
||||
}
|
||||
this.policy = policy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the device group associated with this mapping.
|
||||
*
|
||||
* @param deviceGroup
|
||||
* device group
|
||||
*/
|
||||
public void setDeviceGroup(final DeviceGroup deviceGroup) {
|
||||
this.deviceGroup = deviceGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the device group associated with this mapping.
|
||||
*
|
||||
* @return deviceGroup
|
||||
*/
|
||||
public DeviceGroup getDeviceGroup() {
|
||||
return this.deviceGroup;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,19 +33,12 @@ public class DeviceRegisterImplTest {
|
||||
@Test
|
||||
public void registerNonStoredDeviceByReport() {
|
||||
final DeviceManager deviceManager = mock(DeviceManager.class);
|
||||
final DeviceGroupManager deviceGroupManager = mock(DeviceGroupManager.class);
|
||||
final InetAddress ipAddress = getTestIpAddress();
|
||||
final NetworkInfo networkInfo = new NetworkInfo(HOSTNAME, ipAddress, MAC_ADDRESS);
|
||||
|
||||
final DeviceInfoReport report = new DeviceInfoReport(networkInfo, new OSInfo(),
|
||||
new FirmwareInfo(), new HardwareInfo(), new TPMInfo());
|
||||
|
||||
final DeviceGroup group = new DeviceGroup("test");
|
||||
when(deviceGroupManager.getDeviceGroup(DeviceGroup.DEFAULT_GROUP)).thenReturn(group);
|
||||
DeviceRegisterImpl register = new DeviceRegisterImpl(deviceManager, deviceGroupManager);
|
||||
|
||||
register.saveOrUpdateDevice(report);
|
||||
|
||||
verify(deviceManager).saveDevice(any(Device.class));
|
||||
}
|
||||
|
||||
@ -55,13 +48,6 @@ public class DeviceRegisterImplTest {
|
||||
@Test
|
||||
public void registerNonStoredDeviceByName() {
|
||||
final DeviceManager deviceManager = mock(DeviceManager.class);
|
||||
final DeviceGroupManager deviceGroupManager = mock(DeviceGroupManager.class);
|
||||
final DeviceGroup group = new DeviceGroup("test");
|
||||
|
||||
when(deviceGroupManager.getDeviceGroup(DeviceGroup.DEFAULT_GROUP)).thenReturn(group);
|
||||
DeviceRegisterImpl register = new DeviceRegisterImpl(deviceManager, deviceGroupManager);
|
||||
|
||||
register.saveOrUpdateDevice(HOSTNAME);
|
||||
|
||||
verify(deviceManager).saveDevice(any(Device.class));
|
||||
}
|
||||
@ -72,7 +58,6 @@ public class DeviceRegisterImplTest {
|
||||
@Test
|
||||
public void registerExistingDeviceByReport() {
|
||||
final DeviceManager deviceManager = mock(DeviceManager.class);
|
||||
final DeviceGroupManager deviceGroupManager = mock(DeviceGroupManager.class);
|
||||
final InetAddress ipAddress = getTestIpAddress();
|
||||
final NetworkInfo networkInfo = new NetworkInfo(HOSTNAME, ipAddress, MAC_ADDRESS);
|
||||
final DeviceInfoReport report = new DeviceInfoReport(networkInfo, new OSInfo(),
|
||||
@ -80,10 +65,6 @@ public class DeviceRegisterImplTest {
|
||||
final Device device = new Device(HOSTNAME);
|
||||
|
||||
when(deviceManager.getDevice(HOSTNAME)).thenReturn(device);
|
||||
|
||||
DeviceRegisterImpl register = new DeviceRegisterImpl(deviceManager, deviceGroupManager);
|
||||
register.saveOrUpdateDevice(report);
|
||||
|
||||
verify(deviceManager).updateDevice(any(Device.class));
|
||||
}
|
||||
|
||||
@ -93,11 +74,10 @@ public class DeviceRegisterImplTest {
|
||||
@Test
|
||||
public void registerExistingDeviceByName() {
|
||||
final DeviceManager deviceManager = mock(DeviceManager.class);
|
||||
final DeviceGroupManager deviceGroupManager = mock(DeviceGroupManager.class);
|
||||
final Device device = new Device(HOSTNAME);
|
||||
when(deviceManager.getDevice(HOSTNAME)).thenReturn(device);
|
||||
|
||||
DeviceRegisterImpl register = new DeviceRegisterImpl(deviceManager, deviceGroupManager);
|
||||
DeviceRegisterImpl register = new DeviceRegisterImpl(deviceManager);
|
||||
register.saveOrUpdateDevice(HOSTNAME);
|
||||
|
||||
verify(deviceManager).updateDevice(any(Device.class));
|
||||
|
Loading…
Reference in New Issue
Block a user