Search in sources :

Example 1 with User

use of com.djrapitops.plan.delivery.domain.auth.User in project Plan by plan-player-analytics.

the class BasicAuthentication method getUser.

@Override
public User getUser() {
    String decoded = Base64Util.decode(authenticationString);
    String[] userInfo = StringUtils.split(decoded, ':');
    if (userInfo.length != 2) {
        throw new WebUserAuthException(FailReason.USER_AND_PASS_NOT_SPECIFIED, Arrays.toString(userInfo));
    }
    String username = userInfo[0];
    String passwordRaw = userInfo[1];
    Database.State dbState = database.getState();
    if (dbState != Database.State.OPEN) {
        throw new WebUserAuthException(FailReason.DATABASE_NOT_OPEN, "State was: " + dbState.name());
    }
    try {
        User user = database.query(WebUserQueries.fetchUser(username)).orElseThrow(() -> new WebUserAuthException(FailReason.USER_DOES_NOT_EXIST, username));
        boolean correctPass = user.doesPasswordMatch(passwordRaw);
        if (!correctPass) {
            throw new WebUserAuthException(FailReason.USER_PASS_MISMATCH, username);
        }
        return user;
    } catch (DBOpException | PassEncryptException e) {
        throw new WebUserAuthException(e);
    }
}
Also used : DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) User(com.djrapitops.plan.delivery.domain.auth.User) PassEncryptException(com.djrapitops.plan.exceptions.PassEncryptException) Database(com.djrapitops.plan.storage.database.Database) WebUserAuthException(com.djrapitops.plan.exceptions.WebUserAuthException)

Example 2 with User

use of com.djrapitops.plan.delivery.domain.auth.User in project Plan by plan-player-analytics.

the class Pkcs12HttpsServerTest method setUpClass.

@BeforeAll
static void setUpClass(@TempDir Path tempDir) throws Exception {
    File file = tempDir.resolve("TestCert.p12").toFile();
    File testCert = TestResources.getTestResourceFile("TestCert.p12", ConfigUpdater.class);
    Files.copy(testCert.toPath(), file.toPath(), StandardCopyOption.REPLACE_EXISTING);
    String absolutePath = file.getAbsolutePath();
    PluginMockComponent component = new PluginMockComponent(tempDir);
    system = component.getPlanSystem();
    PlanConfig config = system.getConfigSystem().getConfig();
    config.set(WebserverSettings.CERTIFICATE_PATH, absolutePath);
    config.set(WebserverSettings.CERTIFICATE_KEYPASS, "test");
    config.set(WebserverSettings.CERTIFICATE_STOREPASS, "test");
    config.set(WebserverSettings.CERTIFICATE_ALIAS, "test");
    config.set(WebserverSettings.PORT, TEST_PORT_NUMBER);
    system.enable();
    User user = new User("test", "console", null, PassEncryptUtil.createHash("testPass"), 0, Collections.emptyList());
    system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(user));
}
Also used : User(com.djrapitops.plan.delivery.domain.auth.User) RegisterWebUserTransaction(com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction) PluginMockComponent(utilities.mocks.PluginMockComponent) File(java.io.File) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with User

use of com.djrapitops.plan.delivery.domain.auth.User in project Plan by plan-player-analytics.

the class JksHttpsServerTest method setUpClass.

@BeforeAll
static void setUpClass(@TempDir Path tempDir) throws Exception {
    File file = tempDir.resolve("PlanCert.jks").toFile();
    TestResources.copyResourceIntoFile(file, "/PlanCert.jks");
    String absolutePath = file.getAbsolutePath();
    PluginMockComponent component = new PluginMockComponent(tempDir);
    system = component.getPlanSystem();
    PlanConfig config = system.getConfigSystem().getConfig();
    config.set(WebserverSettings.CERTIFICATE_PATH, absolutePath);
    config.set(WebserverSettings.CERTIFICATE_KEYPASS, "MnD3bU5HpmPXag0e");
    config.set(WebserverSettings.CERTIFICATE_STOREPASS, "wDwwf663NLTm73gL");
    config.set(WebserverSettings.CERTIFICATE_ALIAS, "DefaultPlanCert");
    config.set(WebserverSettings.PORT, TEST_PORT_NUMBER);
    system.enable();
    User user = new User("test", "console", null, PassEncryptUtil.createHash("testPass"), 0, Collections.emptyList());
    system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(user));
}
Also used : User(com.djrapitops.plan.delivery.domain.auth.User) RegisterWebUserTransaction(com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction) PluginMockComponent(utilities.mocks.PluginMockComponent) File(java.io.File) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 4 with User

use of com.djrapitops.plan.delivery.domain.auth.User in project Plan by plan-player-analytics.

the class ActiveCookieStoreTest method cookiesAreStored.

@Test
void cookiesAreStored() {
    String cookie = underTest.generateNewCookie(user);
    User matchingUser = underTest.checkCookie(cookie).orElseThrow(AssertionError::new);
    assertEquals(user, matchingUser);
}
Also used : User(com.djrapitops.plan.delivery.domain.auth.User) WebUser(com.djrapitops.plan.delivery.domain.WebUser) Test(org.junit.jupiter.api.Test)

Example 5 with User

use of com.djrapitops.plan.delivery.domain.auth.User in project Plan by plan-player-analytics.

the class RegistrationCommands method registerUsingLegacy.

public void registerUsingLegacy(CMDSender sender, Arguments arguments) {
    String password = arguments.get(0).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 1, "<password>")));
    String passwordHash = PassEncryptUtil.createHash(password);
    int permissionLevel = arguments.getInteger(2).filter(// argument only allowed with register other permission
    arg -> sender.hasPermission(Permissions.REGISTER_OTHER)).orElseGet(() -> getPermissionLevel(sender));
    Optional<UUID> senderUUID = sender.getUUID();
    Optional<String> senderName = sender.getPlayerName();
    if (senderUUID.isPresent() && senderName.isPresent()) {
        String playerName = senderName.get();
        UUID linkedToUUID = senderUUID.get();
        String username = arguments.get(1).orElse(playerName);
        registerUser(new User(username, playerName, linkedToUUID, passwordHash, permissionLevel, Collections.emptyList()), sender, permissionLevel);
    } else {
        String username = arguments.get(1).orElseThrow(() -> new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ARGS, 3, "<password> <name> <level>")));
        registerUser(new User(username, "console", null, passwordHash, permissionLevel, Collections.emptyList()), sender, permissionLevel);
    }
}
Also used : CommandLang(com.djrapitops.plan.settings.locale.lang.CommandLang) PluginLogger(net.playeranalytics.plugin.server.PluginLogger) Singleton(javax.inject.Singleton) Database(com.djrapitops.plan.storage.database.Database) FailReason(com.djrapitops.plan.delivery.webserver.auth.FailReason) HelpLang(com.djrapitops.plan.settings.locale.lang.HelpLang) DBSystem(com.djrapitops.plan.storage.database.DBSystem) Inject(javax.inject.Inject) RegisterWebUserTransaction(com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction) RemoveWebUserTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveWebUserTransaction) ColorScheme(com.djrapitops.plan.commands.use.ColorScheme) User(com.djrapitops.plan.delivery.domain.auth.User) ErrorContext(com.djrapitops.plan.utilities.logging.ErrorContext) ActiveCookieStore(com.djrapitops.plan.delivery.webserver.auth.ActiveCookieStore) Permissions(com.djrapitops.plan.settings.Permissions) CMDSender(com.djrapitops.plan.commands.use.CMDSender) UUID(java.util.UUID) Objects(java.util.Objects) ExecutionException(java.util.concurrent.ExecutionException) DBOpException(com.djrapitops.plan.exceptions.database.DBOpException) WebUserQueries(com.djrapitops.plan.storage.database.queries.objects.WebUserQueries) ErrorLogger(com.djrapitops.plan.utilities.logging.ErrorLogger) Locale(com.djrapitops.plan.settings.locale.Locale) PassEncryptUtil(com.djrapitops.plan.utilities.PassEncryptUtil) Optional(java.util.Optional) Arguments(com.djrapitops.plan.commands.use.Arguments) Collections(java.util.Collections) RegistrationBin(com.djrapitops.plan.delivery.webserver.auth.RegistrationBin) User(com.djrapitops.plan.delivery.domain.auth.User) UUID(java.util.UUID)

Aggregations

User (com.djrapitops.plan.delivery.domain.auth.User)18 WebUser (com.djrapitops.plan.delivery.domain.WebUser)8 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 Database (com.djrapitops.plan.storage.database.Database)5 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)5 RegisterWebUserTransaction (com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction)5 File (java.io.File)4 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)3 BeforeAll (org.junit.jupiter.api.BeforeAll)3 PluginMockComponent (utilities.mocks.PluginMockComponent)3 WebUserAuthException (com.djrapitops.plan.exceptions.WebUserAuthException)2 DBOpException (com.djrapitops.plan.exceptions.database.DBOpException)2 DBSystem (com.djrapitops.plan.storage.database.DBSystem)2 RemoveWebUserTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveWebUserTransaction)2 PassEncryptUtil (com.djrapitops.plan.utilities.PassEncryptUtil)2 Collections (java.util.Collections)2 UUID (java.util.UUID)2 Test (org.junit.jupiter.api.Test)2 Arguments (com.djrapitops.plan.commands.use.Arguments)1