class CredentialsCacheBean {

    @GET
    @Path("/listMatching")
    @Produces({"text/plain", "application/xml", "text/xml", "application/json", "text/html"})
    @JmxManaged
    public DnList listDNsMatching(@QueryParam("substring") final String substr) {
        DnList result;
        if (!cachedDatawaveUserServiceInstance.isUnsatisfied()) {
            result = new DnList(cachedDatawaveUserServiceInstance.get().listMatching(substr));
        } else {
            Set<Principal> principals = authManager.getCachedKeys();
            // @formatter:off
            Set<DatawaveUserInfo> userList = principals.parallelStream()
                    .filter(p -> p instanceof DatawavePrincipal)
                    .flatMap(p -> ((DatawavePrincipal) p).getProxiedUsers().stream())
                    .filter(u -> u.getName().contains(substr))
                    .map(DatawaveUserInfo::new)
                    .collect(Collectors.toSet());
            // @formatter:on
            result = new DnList(userList);
        }
        return result;
    }

}