public Optional<LDAPUser> searchUserByPrincipal(LDAPConnection connection,
                                                    UnboundLDAPConfig config,
                                                    String principal) throws LDAPException {
        final String filterString = new MessageFormat(config.userSearchPattern(), Locale.ENGLISH)
                .format(new Object[]{Filter.encodeValue(principal)});

        return searchUser(connection, config, Filter.create(filterString));
    }
@Test
    public void testUserLookup() throws Exception {
        final UnboundLDAPConfig searchConfig = UnboundLDAPConfig.builder()
                .userSearchBase("ou=users,dc=example,dc=com")
                .userSearchPattern("(&(objectClass=posixAccount)(uid={0}))")
                .userUniqueIdAttribute("entryUUID")
                .userNameAttribute("uid")
                .userFullNameAttribute("cn")
                .emailAttributes(new ArrayList<>())
                .build();
        final LDAPUser entry = connector.searchUserByPrincipal(connection, searchConfig, "john").orElse(null);

        assertThat(entry).isNotNull();
        assertThat(entry.dn())
                .isNotNull()
                .isEqualTo("cn=John Doe,ou=users,dc=example,dc=com");
        assertThat(new String(Base64.getDecoder().decode(entry.base64UniqueId()), StandardCharsets.UTF_8))
                .isNotBlank()
                .matches("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}");
    }