Class McpApiKeyConfigurer
java.lang.Object
org.springframework.security.config.annotation.SecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,B>
org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer<McpApiKeyConfigurer,org.springframework.security.config.annotation.web.builders.HttpSecurity>
org.springaicommunity.mcp.security.server.config.McpApiKeyConfigurer
- All Implemented Interfaces:
org.springframework.security.config.annotation.SecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,org.springframework.security.config.annotation.web.builders.HttpSecurity>
public class McpApiKeyConfigurer
extends org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer<McpApiKeyConfigurer,org.springframework.security.config.annotation.web.builders.HttpSecurity>
- Author:
- Daniel Garnier-Moiroux
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapiKeyRepository(ApiKeyEntityRepository<?> apiKeyEntityRepository) REQUIRED: The repository for storing API keys.authenticationConverter(org.springframework.security.web.authentication.AuthenticationConverter authenticationConverter) Method for extracting an API key from an HTTP request.voidconfigure(org.springframework.security.config.annotation.web.builders.HttpSecurity http) headerName(String headerName) The name of the header from which to extract the API key.voidinit(org.springframework.security.config.annotation.web.builders.HttpSecurity http) static McpApiKeyConfigurerMethods inherited from class org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer
disable, getRequestMatcherBuilder, getSecurityContextHolderStrategy, withObjectPostProcessorMethods inherited from class org.springframework.security.config.annotation.SecurityConfigurerAdapter
addObjectPostProcessor, getBuilder, postProcess, setBuilder
-
Constructor Details
-
McpApiKeyConfigurer
public McpApiKeyConfigurer()
-
-
Method Details
-
init
public void init(org.springframework.security.config.annotation.web.builders.HttpSecurity http) - Specified by:
initin interfaceorg.springframework.security.config.annotation.SecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,org.springframework.security.config.annotation.web.builders.HttpSecurity> - Overrides:
initin classorg.springframework.security.config.annotation.SecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,org.springframework.security.config.annotation.web.builders.HttpSecurity>
-
configure
public void configure(org.springframework.security.config.annotation.web.builders.HttpSecurity http) - Specified by:
configurein interfaceorg.springframework.security.config.annotation.SecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,org.springframework.security.config.annotation.web.builders.HttpSecurity> - Overrides:
configurein classorg.springframework.security.config.annotation.SecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,org.springframework.security.config.annotation.web.builders.HttpSecurity>
-
apiKeyRepository
REQUIRED: The repository for storing API keys. -
headerName
The name of the header from which to extract the API key. Defaults toApiKeyAuthenticationFilter.DEFAULT_API_KEY_HEADER.If
authenticationConverter(AuthenticationConverter)is set, then this is ignored. -
authenticationConverter
public McpApiKeyConfigurer authenticationConverter(org.springframework.security.web.authentication.AuthenticationConverter authenticationConverter) Method for extracting an API key from an HTTP request.For example:
request -> { var headerValue = request.getHeader("Authorization"); if (!StringUtils.hasText(headerValue) || !headerValue.contains("Bearer ")) { return null; } var tokenValue = headerValue.replace("Bearer ", ""); var apiKey = ApiKeyImpl.from(tokenValue); return ApiKeyAuthenticationToken.unauthenticated(apiKey); };Overrides the value from
headerName(String). -
mcpServerApiKey
-