Class AnonymousAuthenticationReader

java.lang.Object
net.devh.boot.grpc.server.security.authentication.AnonymousAuthenticationReader
All Implemented Interfaces:
GrpcAuthenticationReader

public class AnonymousAuthenticationReader extends Object implements GrpcAuthenticationReader
The AnonymousAuthenticationReader allows users without credentials to get an anonymous identity.
  • Constructor Details

    • AnonymousAuthenticationReader

      public AnonymousAuthenticationReader(String key)
      Creates a new AnonymousAuthenticationReader with the given key and "anonymousUser" as principal with the ROLE_ANONYMOUS.
      Parameters:
      key - The key to used to identify tokens that were created by this instance.
    • AnonymousAuthenticationReader

      public AnonymousAuthenticationReader(String key, Object principal, Collection<? extends GrantedAuthority> authorities)
      Creates a new AnonymousAuthenticationReader with the given key,principal and authorities.
      Parameters:
      key - The key to used to identify tokens that were created by this instance.
      principal - The principal which will be used to represent anonymous users.
      authorities - The authority list for anonymous users.
  • Method Details

    • readAuthentication

      public Authentication readAuthentication(ServerCall<?,?> call, Metadata headers)
      Description copied from interface: GrpcAuthenticationReader
      Tries to read the Authentication 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 subsequent GrpcAuthenticationReaders should be called. Additionally, the call will fail as Status.UNAUTHENTICATED. If the call instead returns null, then the call processing will proceed unauthenticated.

      Specified by:
      readAuthentication in interface GrpcAuthenticationReader
      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.