Class SaslRoleToken

java.lang.Object
org.apache.pulsar.broker.authentication.SaslRoleToken
All Implemented Interfaces:
Principal

public class SaslRoleToken extends Object implements Principal
  • Field Details

    • ANONYMOUS

      public static final SaslRoleToken ANONYMOUS
      Constant that identifies an anonymous request.
  • Constructor Details

    • SaslRoleToken

      public SaslRoleToken(String userRole, String session)
      Creates an authentication token.
      Parameters:
      userRole - user name.
      session - the sessionId. (System.currentTimeMillis() + validityPeriod).
    • SaslRoleToken

      public SaslRoleToken(String userRole, String session, long expires)
  • Method Details

    • setExpires

      public void setExpires(long expires)
      Sets the expiration of the token.
      Parameters:
      expires - expiration time of the token in milliseconds since the epoch.
    • getUserRole

      public String getUserRole()
      Returns the user name.
      Returns:
      the user name.
    • getName

      public String getName()
      Returns the principal name (this method name comes from the JDK Principal interface).
      Specified by:
      getName in interface Principal
      Returns:
      the principal name.
    • getSession

      public String getSession()
      Returns the authentication mechanism of the token.
      Returns:
      the authentication mechanism of the token.
    • getExpires

      public long getExpires()
      Returns the expiration time of the token.
      Returns:
      the expiration time of the token, in milliseconds since Epoc.
    • isExpired

      public boolean isExpired()
      Returns if the token has expired.
      Returns:
      if the token has expired.
    • toString

      public String toString()
      Returns the string representation of the token.

      This string representation is parseable by the parse(java.lang.String) method.

      Specified by:
      toString in interface Principal
      Overrides:
      toString in class Object
      Returns:
      the string representation of the token.
    • parse

      public static SaslRoleToken parse(String tokenStr) throws AuthenticationException
      Parses a string into an authentication token.
      Parameters:
      tokenStr - string representation of a token.
      Returns:
      the parsed authentication token.
      Throws:
      AuthenticationException - thrown if the string representation could not be parsed into an authentication token.