Created
March 24, 2021 09:21
-
-
Save sh1nj1/d1251f296fe79913d101ccdfa0e68b7f to your computer and use it in GitHub Desktop.
Spring security auth configuration for simple api-key header (Kotlin)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.addFilter(object: AbstractPreAuthenticatedProcessingFilter() { | |
override fun getPreAuthenticatedPrincipal(req: HttpServletRequest) = req.getHeader("X-API-KEY") ?: "" | |
override fun getPreAuthenticatedCredentials(req: HttpServletRequest) = "" | |
}.apply { | |
setAuthenticationManager { | |
it.isAuthenticated = it.principal == "{your-api-key}" | |
it | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment