Class TokenAuthentication

java.lang.Object
org.springframework.security.authentication.AbstractAuthenticationToken
ai.yda.framework.channel.shared.TokenAuthentication
All Implemented Interfaces:
Serializable, Principal, org.springframework.security.core.Authentication, org.springframework.security.core.CredentialsContainer

public class TokenAuthentication extends org.springframework.security.authentication.AbstractAuthenticationToken implements Serializable
Represents a bearer token based Authentication.
Since:
0.1.0
See Also:
  • Constructor Details

    • TokenAuthentication

      public TokenAuthentication(String key)
      Constructs a new TokenAuthentication instance with the specified key. The token itself is not stored in this instance; instead, only its hash is stored. The principal is set to "anonymousUser" and the authorities are set to "ROLE_ANONYMOUS".
      Parameters:
      key - the authentication key.
    • TokenAuthentication

      public TokenAuthentication(String key, Object principal, Collection<? extends org.springframework.security.core.GrantedAuthority> authorities)
      Constructs new TokenAuthentication instance with the specified key, principal, and authorities.
      Parameters:
      key - the authentication key.
      principal - the principal (e.g., username).
      authorities - the authorities granted to the principal.
  • Method Details

    • equals

      public boolean equals(Object obj)
      Specified by:
      equals in interface Principal
      Overrides:
      equals in class org.springframework.security.authentication.AbstractAuthenticationToken
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Principal
      Overrides:
      hashCode in class org.springframework.security.authentication.AbstractAuthenticationToken
    • getCredentials

      public Object getCredentials()
      Specified by:
      getCredentials in interface org.springframework.security.core.Authentication
    • extractKeyHash

      public static Integer extractKeyHash(String key)
      Extracts the hash code of the specified key.
      Parameters:
      key - the key for which to extract the hash code.
      Returns:
      the hash code of the key.