Class BearerAuthenticationReader
java.lang.Object
net.devh.boot.grpc.server.security.authentication.BearerAuthenticationReader
- All Implemented Interfaces:
GrpcAuthenticationReader
Spring-Security has several token-based
AuthenticationProvider
implementations (e.g. in
spring-security-web/oauth2 or spring-security-oauth2-resource-server), so you need to provide a Function
that
wraps the extracted token in a Authentication
object supported by your AuthenticationProvider.-
Constructor Summary
ConstructorsConstructorDescriptionBearerAuthenticationReader
(Function<String, Authentication> tokenWrapper) Creates a new BearerAuthenticationReader with the given wrapper function. -
Method Summary
Modifier and TypeMethodDescriptionreadAuthentication
(ServerCall<?, ?> call, Metadata headers) Tries to read theAuthentication
information from the given call and metadata.
-
Constructor Details
-
BearerAuthenticationReader
Creates a new BearerAuthenticationReader with the given wrapper function.Example-Usage:
For spring-security-web:new BearerAuthenticationReader(token -> new PreAuthenticatedAuthenticationToken(token, null))
new BearerAuthenticationReader(token -> new BearerTokenAuthenticationToken(token))
- Parameters:
tokenWrapper
- The function used to convert the token (without bearer prefix) into anAuthentication
object.
-
-
Method Details
-
readAuthentication
Description copied from interface:GrpcAuthenticationReader
Tries to read theAuthentication
information from the given call and metadata.Note: Implementations are free to throw an
AuthenticationException
if no credentials could be found in the call. If an exception is thrown by an implementation then the authentication attempt should be considered as failed and no subsequentGrpcAuthenticationReader
s should be called. Additionally, the call will fail asStatus.UNAUTHENTICATED
. If the call instead returnsnull
, then the call processing will proceed unauthenticated.- Specified by:
readAuthentication
in interfaceGrpcAuthenticationReader
- Parameters:
call
- The call to get that send the request.headers
- The metadata/headers as sent by the client.- Returns:
- The authentication object or null if no authentication is present.
-