public String webfinger(@RequestParam("resource") String resource, Model model) {
if (!resource.equals(config.getIssuer())) {
// it's not the issuer directly, need to check other methods
UriComponents resourceUri = WebfingerURLNormalizer.normalizeResource(resource);
if (resourceUri != null
&& resourceUri.getScheme() != null
&& resourceUri.getScheme().equals("acct")) {
// acct: URI
UserInfo user = userService.getByUsername(resourceUri.getUserInfo()); // first part is the username
if (user == null) {
logger.info("User not found: " + resource);
model.addAttribute("code", HttpStatus.NOT_FOUND);
return HttpCodeView.VIEWNAME;
}
UriComponents issuerComponents = UriComponentsBuilder.fromHttpUrl(config.getIssuer()).build();
if (!Strings.nullToEmpty(issuerComponents.getHost())
.equals(Strings.nullToEmpty(resourceUri.getHost()))) {
logger.info("Host mismatch, expected " + issuerComponents.getHost() + " got " + resourceUri.getHost());
model.addAttribute("code", HttpStatus.NOT_FOUND);
return HttpCodeView.VIEWNAME;
}