public class AuthController extends SugarMessageProcessor
  • Field Details

    • usersRepository

      private final UsersRepositoryInterface usersRepository
    • dotenv

      private static final io.github.cdimascio.dotenv.Dotenv dotenv
    • hashedKey

      private static final String hashedKey
    • gamesManager

      public final GamesManager gamesManager
    • key

      private static final SecretKey key
  • Constructor Details

    • AuthController

      public AuthController(SugarServer gameServer)
  • Method Details

    • stringNotValid

      private static boolean stringNotValid(String s)
    • signUpMsg

      public SugarMessage signUpMsg(SugarMessage message, Peer peer)
    • loginMsg

      public SugarMessage loginMsg(SugarMessage message, Peer peer)
    • isLoggedIn

      private boolean isLoggedIn(String jwt)
      Returns true if the jwt is correctly configured, it is not expired It doesn't check if the body of the jwt is correct
      Parameters:
      jwt - of the logged user
    • getUsernameFromJWT

      public static String getUsernameFromJWT(String jwt)
      Get username from the jwt claims
      Parameters:
      jwt - String of the encoded jwt
      Returns:
      the username of the user logged in, null if there is no username claims
      Throws:
      IllegalArgumentException - when you provide a malformed JWT, an encrypted jwt with the wrong key
    • createFakeJWT

      public static String createFakeJWT(String username)
    • base

      public SugarMessage base(SugarMessage message, Peer peer)