1

I have a Spring Security Servlet Filter, I want to create a complete HATEOAS Link to it. Here is the result of my attempts (login). As you can see the protocol and host are missing. In production I need the protocol and host to be correctly handled (I've set server.use-forward-headers=true so that should be fine for everything if I use the right source)

"_links" : {
"self" : {
  "href" : "http://localhost/v0/public"
},
"registration" : {
  "href" : "http://localhost/v0/public/registration"
},
"login" : {
  "href" : "/v0/public/authentication/password"
}

I've tried this and writing my own builder, but they've both resulted in the above

new Link( "/v0/public/authentication/password", "login" )

How can I have this link created with all of the same info as the others.

xenoterracide
  • 16,274
  • 24
  • 118
  • 243

1 Answers1

1

TLDR

Here's what I came up with, but there are some other gotcha's

BasicLinkBuilder.linkToCurrentMapping()
   .slash( RouteConstants.PRIVATE )
   .withRel( "private" );

This was my original solution but I ran into problems

    @Override
    protected List<Link> undiscoverableLinks( final ServletServerHttpRequest request ) {
        UriComponentsBuilder uriBuilder = fromHttpRequest( request ).replacePath( RouteConstants.AUTH_PASS );
        return Collections.singletonList( new Builder( uriBuilder ).withRel( "login" ) );
    }

and the builder

static class Builder extends LinkBuilderSupport<Builder> {

    Builder( final UriComponentsBuilder builder ) {
        super( builder );
    }

    @Override
    protected Builder getThis() {
        return this;
    }

    @Override
    protected Builder createNewInstance( final UriComponentsBuilder builder ) {
        return new Builder( builder );
    }
}

Here's how I get the ServletServerHttpRequest

the problem I ran into was regarding https and my proxy, the only way I was able to https and my proxy to be recognized was to fix the proto header, and add cloudfront to internal proxies

server.tomcat.internal-proxies=\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}
server.tomcat.protocol-header=cloudfront-forwarded-proto
Community
  • 1
  • 1
xenoterracide
  • 16,274
  • 24
  • 118
  • 243