DefaultAuthentication.java 2.36 KB
Newer Older
KingRainbow44's avatar
KingRainbow44 committed
1
2
package emu.grasscutter.auth;

3
import emu.grasscutter.Grasscutter;
KingRainbow44's avatar
KingRainbow44 committed
4
import emu.grasscutter.auth.DefaultAuthenticators.*;
5
import emu.grasscutter.game.Account;
KingRainbow44's avatar
KingRainbow44 committed
6
7
8
import emu.grasscutter.server.http.objects.ComboTokenResJson;
import emu.grasscutter.server.http.objects.LoginResultJson;

9
import static emu.grasscutter.Configuration.ACCOUNT;
10
11
import static emu.grasscutter.utils.Language.translate;

KingRainbow44's avatar
KingRainbow44 committed
12
13
14
15
16
/**
 * The default Grasscutter authentication implementation.
 * Allows all users to access any account.
 */
public final class DefaultAuthentication implements AuthenticationSystem {
17
18
19
20
21
22
23
24
25
26
27
28
29
30
    private Authenticator<LoginResultJson> passwordAuthenticator;
    private Authenticator<LoginResultJson> tokenAuthenticator = new TokenAuthenticator();
    private Authenticator<ComboTokenResJson> sessionKeyAuthenticator = new SessionKeyAuthenticator();
    private ExternalAuthenticator externalAuthenticator = new ExternalAuthentication();
    private OAuthAuthenticator oAuthAuthenticator = new OAuthAuthentication();

    public DefaultAuthentication() {
        if(ACCOUNT.EXPERIMENTAL_RealPassword) {
            passwordAuthenticator = new ExperimentalPasswordAuthenticator();
        } else {
            passwordAuthenticator = new PasswordAuthenticator();
        }
    }

KingRainbow44's avatar
KingRainbow44 committed
31
32
33
34
35
36
37
38
39
    @Override
    public void createAccount(String username, String password) {
        // Unhandled. The default authenticator doesn't store passwords.
    }

    @Override
    public void resetPassword(String username) {
        // Unhandled. The default authenticator doesn't store passwords.
    }
40

41
    @Override
42
    public Account verifyUser(String details) {
Luke H-W's avatar
Luke H-W committed
43
        Grasscutter.getLogger().info(translate("messages.dispatch.authentication.default_unable_to_verify"));
44
        return null;
45
    }
KingRainbow44's avatar
KingRainbow44 committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60

    @Override
    public Authenticator<LoginResultJson> getPasswordAuthenticator() {
        return this.passwordAuthenticator;
    }

    @Override
    public Authenticator<LoginResultJson> getTokenAuthenticator() {
        return this.tokenAuthenticator;
    }

    @Override
    public Authenticator<ComboTokenResJson> getSessionKeyAuthenticator() {
        return this.sessionKeyAuthenticator;
    }
KingRainbow44's avatar
KingRainbow44 committed
61
62
63
64
65

    @Override
    public ExternalAuthenticator getExternalAuthenticator() {
        return this.externalAuthenticator;
    }
66
67
68
69
70

    @Override
    public OAuthAuthenticator getOAuthAuthenticator() {
        return this.oAuthAuthenticator;
    }
KingRainbow44's avatar
KingRainbow44 committed
71
}