类 YggdrasilAuthenticator

java.lang.Object
org.to2mbn.jmccc.auth.yggdrasil.YggdrasilAuthenticator
所有已实现的接口:
Serializable, org.to2mbn.jmccc.auth.Authenticator, SessionCredential

public class YggdrasilAuthenticator extends Object implements org.to2mbn.jmccc.auth.Authenticator, SessionCredential, Serializable
Provides yggdrasil authentication feature.
另请参阅:
  • 构造器详细资料

    • YggdrasilAuthenticator

      public YggdrasilAuthenticator()
      Constructs a YggdrasilAuthenticator with a random client token.
    • YggdrasilAuthenticator

      public YggdrasilAuthenticator(AuthenticationService sessionService)
      Constructs a YggdrasilAuthenticator with a customized AuthenticationService.
      参数:
      sessionService - the customized AuthenticationService
  • 方法详细资料

    • createPasswordProvider

      public static YggdrasilAuthenticator.PasswordProvider createPasswordProvider(String username, String password, CharacterSelector characterSelector)
    • token

      public static YggdrasilAuthenticator token(String clientToken, String accessToken) throws org.to2mbn.jmccc.auth.AuthenticationException
      Creates a YggdrasilAuthenticator and initializes it with a token.
      参数:
      clientToken - the client token
      accessToken - the access token
      返回:
      a YggdrasilAuthenticator
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - If an exception occurs during the authentication
    • token

      public static YggdrasilAuthenticator token(String clientToken, String accessToken, AuthenticationService service) throws org.to2mbn.jmccc.auth.AuthenticationException
      Creates a YggdrasilAuthenticator with a customized AuthenticationService and initializes it with a token.
      参数:
      clientToken - the client token
      accessToken - the access token
      service - the customized AuthenticationService
      返回:
      a YggdrasilAuthenticator
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - If an exception occurs during the authentication
    • password

      public static YggdrasilAuthenticator password(String username, String password) throws org.to2mbn.jmccc.auth.AuthenticationException
      Creates a YggdrasilAuthenticator, and initializes it with password.
      参数:
      username - the username
      password - the password
      返回:
      a YggdrasilAuthenticator
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - If an exception occurs during the authentication
    • password

      public static YggdrasilAuthenticator password(String username, String password, CharacterSelector characterSelector) throws org.to2mbn.jmccc.auth.AuthenticationException
      Creates a YggdrasilAuthenticator, and initializes it with password.
      参数:
      username - the username
      password - the password
      characterSelector - the character selector
      返回:
      a YggdrasilAuthenticator
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - If an exception occurs during the authentication
    • password

      public static YggdrasilAuthenticator password(String username, String password, CharacterSelector characterSelector, String clientToken) throws org.to2mbn.jmccc.auth.AuthenticationException
      Creates a YggdrasilAuthenticator with the given client token, and initializes it with password.
      参数:
      username - the username
      password - the password
      characterSelector - the character selector
      clientToken - the client token
      返回:
      a YggdrasilAuthenticator
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - If an exception occurs during the authentication
    • password

      public static YggdrasilAuthenticator password(String username, String password, CharacterSelector characterSelector, String clientToken, AuthenticationService service) throws org.to2mbn.jmccc.auth.AuthenticationException
      Creates a YggdrasilAuthenticator with a customized AuthenticationService and the given client token, and initializes it with password.
      参数:
      username - the username
      password - the password
      characterSelector - the character selector
      clientToken - the client token
      service - the customized AuthenticationService
      返回:
      a YggdrasilAuthenticator
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - If an exception occurs during the authentication
    • password

      public static YggdrasilAuthenticator password(AuthenticationService service, YggdrasilAuthenticator.PasswordProvider passwordProvider, String clientToken) throws org.to2mbn.jmccc.auth.AuthenticationException
      Creates a YggdrasilAuthenticator with a customized AuthenticationService and the given client token, and initializes it with password.
      参数:
      service - the customized AuthenticationService
      passwordProvider - the password provider
      clientToken - the client token
      返回:
      a YggdrasilAuthenticator
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - If an exception occurs during the authentication
    • auth

      public org.to2mbn.jmccc.auth.AuthInfo auth() throws org.to2mbn.jmccc.auth.AuthenticationException
      Tries to get an available session, and export it as a AuthInfo. If no profile is available, an AuthenticationException will be thrown.

      尝试获得一个有效的 session ,并以 AuthInfo 的形式返回。 假如没有角色可以选择,则会抛出一个 AuthenticationException

      指定者:
      auth 在接口中 org.to2mbn.jmccc.auth.Authenticator
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException
      另请参阅:
    • session

      public Session session() throws org.to2mbn.jmccc.auth.AuthenticationException
      Tries to get an available session.

      The method will validate the current token first. If the current token is not available, YggdrasilAuthenticator will try refreshing the session. (see refresh()).

      这个方法首先检查当前的 session 是否有效,假若无效则会试着刷新 session (见 refresh() )。

      指定者:
      session 在接口中 SessionCredential
      返回:
      an available session
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - if YggdrasilAuthenticator couldn't get an available session
      另请参阅:
    • refresh

      public void refresh() throws org.to2mbn.jmccc.auth.AuthenticationException
      Tries refreshing the current session.

      This method will try refreshing the token. If YggdrasilAuthenticator failed to refresh, it will call tryPasswordLogin() to ask the password for authentication. If no password is available,an AuthenticationException will be thrown.

      尝试刷新当前的 session 。这个方法首先尝试使用 token 来刷新 session 。如果失败了, 则调用 tryPasswordLogin() 来要求提供密码,使用密码进行登录。如果又失败了,则抛出一个 AuthenticationException

      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - if YggdrasilAuthenticator couldn't refresh the current session
    • refreshWithPassword

      public void refreshWithPassword(String username, String password) throws org.to2mbn.jmccc.auth.AuthenticationException
      Refreshes the current session manually using password.
      参数:
      username - the username
      password - the password
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - If an exception occurs during the authentication
    • refreshWithPassword

      public void refreshWithPassword(String username, String password, CharacterSelector characterSelector) throws org.to2mbn.jmccc.auth.AuthenticationException
      Refreshes the current session manually using password.
      参数:
      username - the username
      password - the password
      characterSelector - the character selector
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - If an exception occurs during the authentication
    • refreshWithPassword

      public void refreshWithPassword(YggdrasilAuthenticator.PasswordProvider passwordProvider) throws org.to2mbn.jmccc.auth.AuthenticationException
      Refreshes the current session manually using password.
      参数:
      passwordProvider - the password provider
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - If an exception occurs during the authentication
    • refreshWithPassword

      public void refreshWithPassword(YggdrasilAuthenticator.PasswordProvider passwordProvider, String clientToken) throws org.to2mbn.jmccc.auth.AuthenticationException
      Refreshes the current session manually using password.
      参数:
      passwordProvider - the password provider
      clientToken - the client token
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - If an exception occurs during the authentication
    • refreshWithToken

      public void refreshWithToken(String clientToken, String accessToken) throws org.to2mbn.jmccc.auth.AuthenticationException
      Refreshes the current session manually using token.
      参数:
      clientToken - the client token
      accessToken - the access token
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - If an exception occurs during the authentication
    • clearToken

      public void clearToken()
      Clears the current session.
    • getCurrentSession

      public Session getCurrentSession()
      Gets the current session.
      返回:
      the current session, null if the current session is unavailable
    • setCurrentSession

      public void setCurrentSession(Session session)
      Sets the current session.
      参数:
      session - the session to set
    • getAuthenticationService

      public AuthenticationService getAuthenticationService()
      Gets the YggdrasilAuthenticator's AuthenticationService.
      返回:
      the AuthenticationService
    • tryPasswordLogin

      protected YggdrasilAuthenticator.PasswordProvider tryPasswordLogin() throws org.to2mbn.jmccc.auth.AuthenticationException
      Provides the username and the password so that YggdrasilAuthenticator can authenticate using password.

      This method is usually called when the current token is invalid. If this method returns null, the password authentication won't be performed. The default implementation of the method returns null.

      当使用 token 登录失败时,就会调用此方法来要求提供用户名和密码,以便使用密码进行登录。 如果该方法返回 null ,那么密码登录也将失败。该方法的默认实现返回 null

      返回:
      the username and the password, can be null
      抛出:
      org.to2mbn.jmccc.auth.AuthenticationException - If an exception occurs during the authentication
    • createAuthenticationServiceForDeserialization

      protected AuthenticationService createAuthenticationServiceForDeserialization()
      Creates an AuthenticationService.

      This method is called during the deserialization to recreate an AuthenticationService, because YggdrasilAuthenticator doesn't persist AuthenticationService during the serialization. The default implementation uses YggdrasilAuthenticationServiceBuilder.buildDefault().

      YggdrasilAuthenticator 在序列化的时候不保存 AuthenticationService , 所以需要在反序列化的时候调用这个方法来重建一个 AuthenticationService 。 该方法的默认实现使用 YggdrasilAuthenticationServiceBuilder.buildDefault()

      返回:
      an AuthenticationService