use of org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint in project sw360portal by sw360.
the class FossologyAdminPortlet method setFingerPrints.
@UsedAsLiferayAction
public void setFingerPrints(ActionRequest request, ActionResponse response) throws PortletException, IOException {
List<FossologyHostFingerPrint> fingerPrints;
FossologyService.Iface client;
try {
client = thriftClients.makeFossologyClient();
fingerPrints = client.getFingerPrints();
} catch (TException e) {
log.error("Error retrieving fingerprints when setting", e);
return;
}
for (FossologyHostFingerPrint fingerPrint : fingerPrints) {
String bool = request.getParameter(fingerPrint.fingerPrint);
fingerPrint.trusted = "on".equals(bool);
}
try {
client.setFingerPrints(fingerPrints);
} catch (TException e) {
log.error("Problems setting finger prints", e);
}
}
use of org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint in project sw360portal by sw360.
the class FossologyUploaderFunctionalTest method setUpAutoTrustOnSecondTry.
private void setUpAutoTrustOnSecondTry() {
final FossologyFingerPrintRepository fossologyFingerPrintRepository = appContext.getBean(FossologyFingerPrintRepository.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
final FossologyHostFingerPrint finger = (FossologyHostFingerPrint) invocation.getArguments()[0];
FossologyHostFingerPrint trustedFingerPrint = finger.deepCopy().setTrusted(true);
doReturn(ImmutableList.of(trustedFingerPrint)).when(fossologyFingerPrintRepository).getAll();
return null;
}
}).when(fossologyFingerPrintRepository).add(any(FossologyHostFingerPrint.class));
}
use of org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint in project sw360portal by sw360.
the class FossologyHostKeyRepositoryTest method testCheckAValidKnownTrustedKeyIsTrusted.
@Test
public void testCheckAValidKnownTrustedKeyIsTrusted() throws Exception {
String host = "host";
byte[] key = GOOD_KEY.getBytes();
final String expectedFingerPrint = new HostKey(host, key).getFingerPrint(jSch);
assertThat(expectedFingerPrint, not(isEmptyOrNullString()));
when(connector.getAll()).thenReturn(ImmutableList.of(new FossologyHostFingerPrint().setFingerPrint(expectedFingerPrint).setTrusted(true)));
assertThat(repo.check(host, key), is(HostKeyRepository.OK));
verify(connector).getAll();
verify(connector, never()).add(any(FossologyHostFingerPrint.class));
}
use of org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint in project sw360portal by sw360.
the class FossologyHostKeyRepository method check.
@Override
public int check(String host, byte[] key) {
String fingerPrint;
try {
fingerPrint = new HostKey(host, key).getFingerPrint(J_SHC);
for (FossologyHostFingerPrint savedFingerPrint : hostKeyDb.getAll()) {
if (fingerPrint.equals(savedFingerPrint.getFingerPrint())) {
if (savedFingerPrint.isTrusted()) {
return OK;
} else {
log.error("attempting connection to untrusted Host");
return NOT_INCLUDED;
}
}
}
} catch (Exception e) {
log.error(format("exception while verifying host '%s'", host), e);
return NOT_INCLUDED;
}
log.error(format("cannot verify host '%s', fingerprint = '%s'", host, fingerPrint));
final FossologyHostFingerPrint newFossologyHostFingerPrint = new FossologyHostFingerPrint().setFingerPrint(fingerPrint).setTrusted(false);
hostKeyDb.add(newFossologyHostFingerPrint);
return NOT_INCLUDED;
}
use of org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint in project sw360portal by sw360.
the class FossologyHandlerTest method testSetFingerPrints.
@Test
public void testSetFingerPrints() throws Exception {
@SuppressWarnings("unchecked") final List<FossologyHostFingerPrint> newFingerPrints = mock(List.class);
final RequestStatus requestStatus = RequestStatus.FAILURE;
doReturn(requestStatus).when(fossologyHostKeyHandler).setFingerPrints(newFingerPrints);
assertThat(fossologyHandler.setFingerPrints(newFingerPrints), sameInstance(requestStatus));
verify(fossologyHostKeyHandler).setFingerPrints(newFingerPrints);
}
Aggregations