Search in sources :

Example 1 with FossologyHostFingerPrint

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);
    }
}
Also used : TException(org.apache.thrift.TException) FossologyService(org.eclipse.sw360.datahandler.thrift.fossology.FossologyService) FossologyHostFingerPrint(org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint) UsedAsLiferayAction(org.eclipse.sw360.portal.common.UsedAsLiferayAction)

Example 2 with FossologyHostFingerPrint

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));
}
Also used : FossologyFingerPrintRepository(org.eclipse.sw360.fossology.db.FossologyFingerPrintRepository) InvocationOnMock(org.mockito.invocation.InvocationOnMock) FossologyHostFingerPrint(org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint)

Example 3 with FossologyHostFingerPrint

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));
}
Also used : HostKey(com.jcraft.jsch.HostKey) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) FossologyHostFingerPrint(org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint) Test(org.junit.Test)

Example 4 with FossologyHostFingerPrint

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;
}
Also used : HostKey(com.jcraft.jsch.HostKey) FossologyHostFingerPrint(org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint)

Example 5 with FossologyHostFingerPrint

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);
}
Also used : FossologyHostFingerPrint(org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint) RequestStatus(org.eclipse.sw360.datahandler.thrift.RequestStatus) Test(org.junit.Test)

Aggregations

FossologyHostFingerPrint (org.eclipse.sw360.datahandler.thrift.fossology.FossologyHostFingerPrint)7 HostKey (com.jcraft.jsch.HostKey)4 Test (org.junit.Test)4 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 TException (org.apache.thrift.TException)1 RequestStatus (org.eclipse.sw360.datahandler.thrift.RequestStatus)1 FossologyService (org.eclipse.sw360.datahandler.thrift.fossology.FossologyService)1 FossologyFingerPrintRepository (org.eclipse.sw360.fossology.db.FossologyFingerPrintRepository)1 UsedAsLiferayAction (org.eclipse.sw360.portal.common.UsedAsLiferayAction)1 Answer (org.mockito.stubbing.Answer)1