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