protected Collection<Identity> filter(final Credentials credentials, final Collection<Identity> identities) {
        if(credentials.isPublicKeyAuthentication()) {
            final Local selected = credentials.getIdentity();
            for(Identity identity : identities) {
                if(identity.getComment() != null) {
                    final String candidate = new String(identity.getComment(), StandardCharsets.UTF_8);
                    if(selected.getAbsolute().equals(candidate)) {
                        if(log.isDebugEnabled()) {
                            log.debug(String.format("Matching identity %s found", candidate));
                        }
                        return Collections.singletonList(identity);
                    }
                }
            }
        }
        return identities;
    }
@Test
    public void filterIdentitiesMatch() {
        final SFTPAgentAuthentication authentication = new SFTPAgentAuthentication(new SSHClient(), new OpenSSHAgentAuthenticator(new AgentProxy(null)));
        final Credentials credentials = new Credentials("user").withIdentity(new Local("mykey") {
            @Override
            public boolean exists() {
                return true;
            }
        });

        final List<Identity> identities = new ArrayList<>();
        final Identity nomatch = mock(Identity.class);
        when(nomatch.getComment()).thenReturn(StringUtils.getBytes("mykey2", StandardCharsets.UTF_8));
        final Identity match = mock(Identity.class);
        when(match.getComment()).thenReturn(StringUtils.getBytes("mykey", StandardCharsets.UTF_8));

        identities.add(nomatch);
        identities.add(match);

        final Collection<Identity> filtered = authentication.filter(credentials, identities);
        assertEquals(1, filtered.size());
        assertArrayEquals(match.getComment(), filtered.iterator().next().getComment());
    }