spring boot api key authentication example

Solutions on MaxInterview for spring boot api key authentication example by the best coders in the world

showing results for - "spring boot api key authentication example"
Libby
25 Apr 2019
1import org.springframework.security.web.authentication.preauth.AbstractPreAuthenticatedProcessingFilter;
2
3public class APIKeyAuthFilter extends AbstractPreAuthenticatedProcessingFilter {
4
5    private String principalRequestHeader;
6
7    public APIKeyAuthFilter(String principalRequestHeader) {
8        this.principalRequestHeader = principalRequestHeader;
9    }
10
11    @Override
12    protected Object getPreAuthenticatedPrincipal(HttpServletRequest request) {
13        return request.getHeader(principalRequestHeader);
14    }
15
16    @Override
17    protected Object getPreAuthenticatedCredentials(HttpServletRequest request) {
18        return "N/A";
19    }
20
21}