@Configuration @ConditionalOnBean(value=org.springframework.security.authentication.AuthenticationManager.class) @AutoConfigureAfter(value=org.springframework.boot.autoconfigure.security.servlet.WebSecurityEnablerConfiguration.class) public class GrpcServerSecurityAutoConfiguration extends Object
To enable security add both an AuthenticationManager
and a GrpcAuthenticationReader
to the
application context. The authentication reader obtains the credentials from the requests which then will be validated
by the authentication manager. After that, you can decide how you want to secure your application. Currently these
options are available:
@EnableGlobalMethodSecurity(proxyTargetClass = true, ...)
.AccessDecisionManager
and a GrpcSecurityMetadataSource
in the application context.
Note: The order of the beans is important! First the exception translating interceptor, then the authenticating interceptor and finally the authorization checking interceptor. That is necessary because they are executed in the same order as their order.
Constructor and Description |
---|
GrpcServerSecurityAutoConfiguration() |
Modifier and Type | Method and Description |
---|---|
AuthenticatingServerInterceptor |
authenticatingServerInterceptor(AuthenticationManager authenticationManager,
GrpcAuthenticationReader authenticationReader)
The security interceptor that handles the authentication of requests.
|
AuthorizationCheckingServerInterceptor |
authorizationCheckingServerInterceptor(AccessDecisionManager accessDecisionManager,
GrpcSecurityMetadataSource securityMetadataSource)
The security interceptor that handles the authorization of requests.
|
ExceptionTranslatingServerInterceptor |
exceptionTranslatingServerInterceptor()
The interceptor for handling security related exceptions such as
AuthenticationException and
AccessDeniedException . |
@Bean @ConditionalOnMissingBean public ExceptionTranslatingServerInterceptor exceptionTranslatingServerInterceptor()
AuthenticationException
and
AccessDeniedException
.@Bean @ConditionalOnMissingBean public AuthenticatingServerInterceptor authenticatingServerInterceptor(AuthenticationManager authenticationManager, GrpcAuthenticationReader authenticationReader)
authenticationManager
- The authentication manager used to verify the credentials.authenticationReader
- The authentication reader used to extract the credentials from the call.@Bean @ConditionalOnMissingBean @ConditionalOnBean(value={org.springframework.security.access.AccessDecisionManager.class,GrpcSecurityMetadataSource.class}) public AuthorizationCheckingServerInterceptor authorizationCheckingServerInterceptor(AccessDecisionManager accessDecisionManager, GrpcSecurityMetadataSource securityMetadataSource)
accessDecisionManager
- The access decision manager used to check the requesting user.securityMetadataSource
- The source for the security metadata (access constraints).