Class AuthenticationServiceClient

java.lang.Object
org.saidone.unrest.client.AuthenticationServiceClient
All Implemented Interfaces:
TicketProvider

public class AuthenticationServiceClient extends Object implements TicketProvider
Client of the AuthenticationService of the gRPC module: exchanges user and password for an Alfresco ticket, gRPC only, no REST. Authenticate sends no ticket header: it is the only call that needs none.

Built with credentials it is also the TicketProvider shared by the repository service clients: it logs in lazily, on the first ticket(), caches the ticket and logs in again after invalidate(java.lang.String). Wrong credentials surface as the StatusRuntimeException of the server (UNAUTHENTICATED).


 val tickets = new AuthenticationServiceClient(channel, "mcp", "secret", Duration.ofSeconds(30));
 val client = new NodeServiceClient(channel, tickets, Duration.ofSeconds(30));
 
  • Constructor Details

    • AuthenticationServiceClient

      public AuthenticationServiceClient(io.grpc.Channel channel, Duration deadline)
      Creates this service client with shared authentication and a per-call deadline.

      The caller retains ownership of the channel; closing an application should close its shared channel once.

      Parameters:
      channel - shared gRPC channel; ownership remains with the caller
      deadline - per-call deadline applied to every RPC attempt
    • AuthenticationServiceClient

      public AuthenticationServiceClient(io.grpc.Channel channel, String user, String password, Duration deadline)
      Creates this service client with shared authentication and a per-call deadline.

      The caller retains ownership of the channel; closing an application should close its shared channel once.

      Parameters:
      channel - shared gRPC channel; ownership remains with the caller
      user - Alfresco username used for authentication
      password - password for the supplied username
      deadline - per-call deadline applied to every RPC attempt
    • AuthenticationServiceClient

      public AuthenticationServiceClient(org.saidone.unrest.api.AuthenticationServiceGrpc.AuthenticationServiceBlockingStub stub, Duration deadline)
      Creates this service client with shared authentication and a per-call deadline.

      The caller retains ownership of the channel; closing an application should close its shared channel once.

      Parameters:
      stub - preconfigured stub for this repository service
      deadline - per-call deadline applied to every RPC attempt
    • AuthenticationServiceClient

      public AuthenticationServiceClient(org.saidone.unrest.api.AuthenticationServiceGrpc.AuthenticationServiceBlockingStub stub, String user, String password, Duration deadline)
      Creates this service client with shared authentication and a per-call deadline.

      The caller retains ownership of the channel; closing an application should close its shared channel once.

      Parameters:
      stub - preconfigured stub for this repository service
      user - Alfresco username used for authentication
      password - password for the supplied username
      deadline - per-call deadline applied to every RPC attempt
  • Method Details

    • authenticate

      public String authenticate(String user, String password)
      Exchanges user and password for a new ticket. Wrong credentials are UNAUTHENTICATED.
      Parameters:
      user - Alfresco username used for authentication
      password - password for the supplied username
      Returns:
      the authenticated repository ticket
    • validateTicket

      public String validateTicket(String ticket)
      Validates the supplied Alfresco ticket and returns its identifier.
    • invalidateTicket

      public void invalidateTicket(String ticket)
      Revokes the supplied Alfresco ticket in the repository.
    • ticket

      public String ticket()
      Returns the cached ticket, logging in with the credentials of the constructor if there is none.
      Specified by:
      ticket in interface TicketProvider
      Returns:
      the authenticated repository ticket
    • invalidate

      public void invalidate(String expired)
      Drops expired so that the next ticket() call logs in again.
      Specified by:
      invalidate in interface TicketProvider
      Parameters:
      expired - ticket rejected by a server call; only the matching cached ticket is invalidated