类 YggdrasilAuthenticator
- 所有已实现的接口:
Serializable,org.to2mbn.jmccc.auth.Authenticator,SessionCredential
- 另请参阅:
-
嵌套类概要
嵌套类修饰符和类型类说明static interfaceProvides username and password for yggdrasil authentication. -
构造器概要
构造器构造器说明Constructs a YggdrasilAuthenticator with a random client token.YggdrasilAuthenticator(AuthenticationService sessionService) Constructs a YggdrasilAuthenticator with a customizedAuthenticationService. -
方法概要
修饰符和类型方法说明org.to2mbn.jmccc.auth.AuthInfoauth()Tries to get an available session, and export it as aAuthInfo.voidClears the current session.protected AuthenticationServiceCreates anAuthenticationService.createPasswordProvider(String username, String password, CharacterSelector characterSelector) Gets theYggdrasilAuthenticator'sAuthenticationService.Gets the current session.static YggdrasilAuthenticatorCreates aYggdrasilAuthenticator, and initializes it with password.static YggdrasilAuthenticatorpassword(String username, String password, CharacterSelector characterSelector) Creates aYggdrasilAuthenticator, and initializes it with password.static YggdrasilAuthenticatorpassword(String username, String password, CharacterSelector characterSelector, String clientToken) Creates aYggdrasilAuthenticatorwith the given client token, and initializes it with password.static YggdrasilAuthenticatorpassword(String username, String password, CharacterSelector characterSelector, String clientToken, AuthenticationService service) Creates aYggdrasilAuthenticatorwith a customizedAuthenticationServiceand the given client token, and initializes it with password.static YggdrasilAuthenticatorpassword(AuthenticationService service, YggdrasilAuthenticator.PasswordProvider passwordProvider, String clientToken) Creates aYggdrasilAuthenticatorwith a customizedAuthenticationServiceand the given client token, and initializes it with password.voidrefresh()Tries refreshing the current session.voidrefreshWithPassword(String username, String password) Refreshes the current session manually using password.voidrefreshWithPassword(String username, String password, CharacterSelector characterSelector) Refreshes the current session manually using password.voidrefreshWithPassword(YggdrasilAuthenticator.PasswordProvider passwordProvider) Refreshes the current session manually using password.voidrefreshWithPassword(YggdrasilAuthenticator.PasswordProvider passwordProvider, String clientToken) Refreshes the current session manually using password.voidrefreshWithToken(String clientToken, String accessToken) Refreshes the current session manually using token.session()Tries to get an available session.voidsetCurrentSession(Session session) Sets the current session.static YggdrasilAuthenticatorCreates aYggdrasilAuthenticatorand initializes it with a token.static YggdrasilAuthenticatortoken(String clientToken, String accessToken, AuthenticationService service) Creates aYggdrasilAuthenticatorwith a customizedAuthenticationServiceand initializes it with a token.protected YggdrasilAuthenticator.PasswordProviderProvides the username and the password so thatYggdrasilAuthenticatorcan authenticate using password.
-
构造器详细资料
-
YggdrasilAuthenticator
public YggdrasilAuthenticator()Constructs a YggdrasilAuthenticator with a random client token. -
YggdrasilAuthenticator
Constructs a YggdrasilAuthenticator with a customizedAuthenticationService.- 参数:
sessionService- the customizedAuthenticationService
-
-
方法详细资料
-
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 aYggdrasilAuthenticatorand initializes it with a token.- 参数:
clientToken- the client tokenaccessToken- 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 aYggdrasilAuthenticatorwith a customizedAuthenticationServiceand initializes it with a token.- 参数:
clientToken- the client tokenaccessToken- the access tokenservice- the customizedAuthenticationService- 返回:
- 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 aYggdrasilAuthenticator, and initializes it with password.- 参数:
username- the usernamepassword- 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 aYggdrasilAuthenticator, and initializes it with password.- 参数:
username- the usernamepassword- the passwordcharacterSelector- 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 aYggdrasilAuthenticatorwith the given client token, and initializes it with password.- 参数:
username- the usernamepassword- the passwordcharacterSelector- the character selectorclientToken- 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 aYggdrasilAuthenticatorwith a customizedAuthenticationServiceand the given client token, and initializes it with password.- 参数:
username- the usernamepassword- the passwordcharacterSelector- the character selectorclientToken- the client tokenservice- the customizedAuthenticationService- 返回:
- 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 aYggdrasilAuthenticatorwith a customizedAuthenticationServiceand the given client token, and initializes it with password.- 参数:
service- the customizedAuthenticationServicepasswordProvider- the password providerclientToken- 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.AuthenticationExceptionTries to get an available session, and export it as aAuthInfo. If no profile is available, anAuthenticationExceptionwill be thrown.尝试获得一个有效的 session ,并以
AuthInfo的形式返回。 假如没有角色可以选择,则会抛出一个AuthenticationException。- 指定者:
auth在接口中org.to2mbn.jmccc.auth.Authenticator- 抛出:
org.to2mbn.jmccc.auth.AuthenticationException- 另请参阅:
-
session
Tries to get an available session.The method will validate the current token first. If the current token is not available,
YggdrasilAuthenticatorwill try refreshing the session. (seerefresh()).这个方法首先检查当前的 session 是否有效,假若无效则会试着刷新 session (见
refresh())。- 指定者:
session在接口中SessionCredential- 返回:
- an available session
- 抛出:
org.to2mbn.jmccc.auth.AuthenticationException- ifYggdrasilAuthenticatorcouldn't get an available session- 另请参阅:
-
refresh
public void refresh() throws org.to2mbn.jmccc.auth.AuthenticationExceptionTries 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,anAuthenticationExceptionwill be thrown.尝试刷新当前的 session 。这个方法首先尝试使用 token 来刷新 session 。如果失败了, 则调用
tryPasswordLogin()来要求提供密码,使用密码进行登录。如果又失败了,则抛出一个AuthenticationException。- 抛出:
org.to2mbn.jmccc.auth.AuthenticationException- ifYggdrasilAuthenticatorcouldn'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 usernamepassword- 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 usernamepassword- the passwordcharacterSelector- 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 providerclientToken- 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 tokenaccessToken- the access token- 抛出:
org.to2mbn.jmccc.auth.AuthenticationException- If an exception occurs during the authentication
-
clearToken
public void clearToken()Clears the current session. -
getCurrentSession
Gets the current session.- 返回:
- the current session,
nullif the current session is unavailable
-
setCurrentSession
Sets the current session.- 参数:
session- the session to set
-
getAuthenticationService
Gets theYggdrasilAuthenticator'sAuthenticationService.- 返回:
- the
AuthenticationService
-
tryPasswordLogin
protected YggdrasilAuthenticator.PasswordProvider tryPasswordLogin() throws org.to2mbn.jmccc.auth.AuthenticationExceptionProvides the username and the password so thatYggdrasilAuthenticatorcan 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 returnsnull.当使用 token 登录失败时,就会调用此方法来要求提供用户名和密码,以便使用密码进行登录。 如果该方法返回
null,那么密码登录也将失败。该方法的默认实现返回null。- 返回:
- the username and the password, can be null
- 抛出:
org.to2mbn.jmccc.auth.AuthenticationException- If an exception occurs during the authentication
-
createAuthenticationServiceForDeserialization
Creates anAuthenticationService.This method is called during the deserialization to recreate an
AuthenticationService, becauseYggdrasilAuthenticatordoesn't persistAuthenticationServiceduring the serialization. The default implementation usesYggdrasilAuthenticationServiceBuilder.buildDefault().YggdrasilAuthenticator在序列化的时候不保存AuthenticationService, 所以需要在反序列化的时候调用这个方法来重建一个AuthenticationService。 该方法的默认实现使用YggdrasilAuthenticationServiceBuilder.buildDefault()。- 返回:
- an
AuthenticationService
-