Spring-boot-admin: Document/Example using JWT Header

Created on 27 Apr 2017  路  5Comments  路  Source: codecentric/spring-boot-admin

Here is a sample of what we have to do to wire up a JWT auth scheme to call our client services. Simply by defining this bean in the admin service project, all outbound calls have the token applied and should pass the remote services JWT auth requirement.

It might be prudent to add this to the security section or examples on how to do this in addition to the basic auth example already provided.

package com.foo.bar;

import de.codecentric.boot.admin.model.Application;
import de.codecentric.boot.admin.web.client.HttpHeadersProvider;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Component;

@Component
public class JwtHeaderProvider implements HttpHeadersProvider {

    @Override
    public HttpHeaders getHeaders(Application application) {
        HttpHeaders headers = new HttpHeaders();
        headers.add("X-Authn-JWT", "[MY TOKEN PROBABLY GENERATED WITH KEY]");
        return headers;
    }
}

This above works because of the @ConditionalOnMissingBean in your AdminServerCoreConfiguration class.

@Bean
@ConditionalOnMissingBean
public HttpHeadersProvider httpHeadersProvider() {
    return new BasicAuthHttpHeaderProvider();
}

Most helpful comment

Although I think it is trivial too , but for people who are new to Spring Boot and Auto Configuration magic , this could be a useful addition.

All 5 comments

Yeah that's exactly what's intended. Do you really think it should be in the docs - I don't. Isn't this trivial?

@joshiste I think this example should be added to the docs.

@joshiste I also think it should be added to the docs.
If more explaination could be added on this part It would be nice too.

Thanks

Although I think it is trivial too , but for people who are new to Spring Boot and Auto Configuration magic , this could be a useful addition.

hi can someone can someoane explain to me how to have a valid tooken all the time ?

Was this page helpful?
0 / 5 - 0 ratings