Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sh1nj1/d1251f296fe79913d101ccdfa0e68b7f to your computer and use it in GitHub Desktop.
Save sh1nj1/d1251f296fe79913d101ccdfa0e68b7f to your computer and use it in GitHub Desktop.
Spring security auth configuration for simple api-key header (Kotlin)
.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