Search in sources :

Example 6 with User

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

the class DatabaseBackupTest method saveDataForBackup.

default void saveDataForBackup() {
    db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
    db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1]));
    db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
    db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
    execute(DataStoreQueries.storeSession(session));
    db().executeTransaction(new NicknameStoreTransaction(playerUUID, RandomData.randomNickname(serverUUID()), (uuid, name) -> false));
    db().executeTransaction(new GeoInfoStoreTransaction(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime())));
    List<TPS> expected = RandomData.randomTPS();
    for (TPS tps : expected) {
        execute(DataStoreQueries.storeTPS(serverUUID(), tps));
    }
    db().executeTransaction(new PingStoreTransaction(playerUUID, serverUUID(), Collections.singletonList(new DateObj<>(System.currentTimeMillis(), RandomData.randomInt(-1, 40)))));
    User user = new User("test", "console", null, PassEncryptUtil.createHash("testPass"), 0, Collections.emptyList());
    db().executeTransaction(new RegisterWebUserTransaction(user));
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Files(java.nio.file.Files) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) File(java.io.File) Database(com.djrapitops.plan.storage.database.Database) Test(org.junit.jupiter.api.Test) List(java.util.List) SQLiteDB(com.djrapitops.plan.storage.database.SQLiteDB) RegisterWebUserTransaction(com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction) DateObj(com.djrapitops.plan.delivery.domain.DateObj) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) BackupCopyTransaction(com.djrapitops.plan.storage.database.transactions.BackupCopyTransaction) User(com.djrapitops.plan.delivery.domain.auth.User) DatabaseTestPreparer(com.djrapitops.plan.storage.database.DatabaseTestPreparer) TPS(com.djrapitops.plan.gathering.domain.TPS) PassEncryptUtil(com.djrapitops.plan.utilities.PassEncryptUtil) RandomData(utilities.RandomData) com.djrapitops.plan.storage.database.queries.objects(com.djrapitops.plan.storage.database.queries.objects) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TestConstants(utilities.TestConstants) Collections(java.util.Collections) User(com.djrapitops.plan.delivery.domain.auth.User) RegisterWebUserTransaction(com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) TPS(com.djrapitops.plan.gathering.domain.TPS)

Example 7 with User

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

the class WebUserQueries method matchUsers.

public static Query<List<User>> matchUsers(String partOfUsername) {
    String sql = SELECT + '*' + FROM + SecurityTable.TABLE_NAME + LEFT_JOIN + UsersTable.TABLE_NAME + " on " + SecurityTable.LINKED_TO + "=" + UsersTable.USER_UUID + WHERE + "LOWER(" + SecurityTable.USERNAME + ") LIKE LOWER(?)";
    return new QueryStatement<List<User>>(sql) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setString(1, '%' + partOfUsername + '%');
        }

        @Override
        public List<User> processResults(ResultSet set) throws SQLException {
            List<User> users = new ArrayList<>();
            while (set.next()) {
                String username = set.getString(SecurityTable.USERNAME);
                String linkedTo = set.getString(UsersTable.USER_NAME);
                UUID linkedToUUID = linkedTo != null ? UUID.fromString(set.getString(SecurityTable.LINKED_TO)) : null;
                String passwordHash = set.getString(SecurityTable.SALT_PASSWORD_HASH);
                int permissionLevel = set.getInt(SecurityTable.PERMISSION_LEVEL);
                List<String> permissions = WebUser.getPermissionsForLevel(permissionLevel);
                users.add(new User(username, linkedTo != null ? linkedTo : "console", linkedToUUID, passwordHash, permissionLevel, permissions));
            }
            return users;
        }
    };
}
Also used : User(com.djrapitops.plan.delivery.domain.auth.User) WebUser(com.djrapitops.plan.delivery.domain.WebUser) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 8 with User

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

the class WebUserQueries method fetchAllUsers.

public static Query<List<User>> fetchAllUsers() {
    String sql = SELECT + '*' + FROM + SecurityTable.TABLE_NAME + LEFT_JOIN + UsersTable.TABLE_NAME + " on " + SecurityTable.LINKED_TO + "=" + UsersTable.USER_UUID;
    return new QueryAllStatement<List<User>>(sql) {

        @Override
        public List<User> processResults(ResultSet set) throws SQLException {
            List<User> users = new ArrayList<>();
            while (set.next()) {
                String username = set.getString(SecurityTable.USERNAME);
                String linkedTo = set.getString(UsersTable.USER_NAME);
                UUID linkedToUUID = linkedTo != null ? UUID.fromString(set.getString(SecurityTable.LINKED_TO)) : null;
                String passwordHash = set.getString(SecurityTable.SALT_PASSWORD_HASH);
                int permissionLevel = set.getInt(SecurityTable.PERMISSION_LEVEL);
                List<String> permissions = WebUser.getPermissionsForLevel(permissionLevel);
                users.add(new User(username, linkedTo != null ? linkedTo : "console", linkedToUUID, passwordHash, permissionLevel, permissions));
            }
            return users;
        }
    };
}
Also used : QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) User(com.djrapitops.plan.delivery.domain.auth.User) WebUser(com.djrapitops.plan.delivery.domain.WebUser) ResultSet(java.sql.ResultSet)

Example 9 with User

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

the class WebUserQueries method fetchUserLinkedTo.

public static Query<Optional<User>> fetchUserLinkedTo(String playerName) {
    String sql = SELECT + '*' + FROM + SecurityTable.TABLE_NAME + LEFT_JOIN + UsersTable.TABLE_NAME + " on " + SecurityTable.LINKED_TO + "=" + UsersTable.USER_UUID + WHERE + UsersTable.USER_NAME + "=? LIMIT 1";
    return new QueryStatement<Optional<User>>(sql) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setString(1, playerName);
        }

        @Override
        public Optional<User> processResults(ResultSet set) throws SQLException {
            if (set.next()) {
                String linkedTo = set.getString(UsersTable.USER_NAME);
                UUID linkedToUUID = linkedTo != null ? UUID.fromString(set.getString(SecurityTable.LINKED_TO)) : null;
                String passwordHash = set.getString(SecurityTable.SALT_PASSWORD_HASH);
                int permissionLevel = set.getInt(SecurityTable.PERMISSION_LEVEL);
                List<String> permissions = WebUser.getPermissionsForLevel(permissionLevel);
                return Optional.of(new User(playerName, linkedTo != null ? linkedTo : "console", linkedToUUID, passwordHash, permissionLevel, permissions));
            }
            return Optional.empty();
        }
    };
}
Also used : User(com.djrapitops.plan.delivery.domain.auth.User) WebUser(com.djrapitops.plan.delivery.domain.WebUser) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement)

Example 10 with User

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

the class AccessControlTest 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 userLevel0 = new User("test0", "console", null, PassEncryptUtil.createHash("testPass"), 0, Collections.emptyList());
    User userLevel1 = new User("test1", "console", null, PassEncryptUtil.createHash("testPass"), 1, Collections.emptyList());
    User userLevel2 = new User("test2", TestConstants.PLAYER_ONE_NAME, TestConstants.PLAYER_ONE_UUID, PassEncryptUtil.createHash("testPass"), 2, Collections.emptyList());
    User userLevel100 = new User("test100", "console", null, PassEncryptUtil.createHash("testPass"), 100, Collections.emptyList());
    system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(userLevel0));
    system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(userLevel1));
    system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(userLevel2));
    system.getDatabaseSystem().getDatabase().executeTransaction(new RegisterWebUserTransaction(userLevel100));
    system.getDatabaseSystem().getDatabase().executeTransaction(new PlayerRegisterTransaction(TestConstants.PLAYER_ONE_UUID, () -> 0L, TestConstants.PLAYER_ONE_NAME));
    system.getDatabaseSystem().getDatabase().executeTransaction(new StoreServerInformationTransaction(new Server(TestConstants.SERVER_UUID, TestConstants.SERVER_NAME, address)));
    address = "https://localhost:" + TEST_PORT_NUMBER;
    cookieLevel0 = login(address, userLevel0.getUsername());
    cookieLevel1 = login(address, userLevel1.getUsername());
    cookieLevel2 = login(address, userLevel2.getUsername());
    cookieLevel100 = login(address, userLevel100.getUsername());
}
Also used : User(com.djrapitops.plan.delivery.domain.auth.User) RegisterWebUserTransaction(com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction) Server(com.djrapitops.plan.identification.Server) StoreServerInformationTransaction(com.djrapitops.plan.storage.database.transactions.StoreServerInformationTransaction) PlayerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction) PluginMockComponent(utilities.mocks.PluginMockComponent) File(java.io.File) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) BeforeAll(org.junit.jupiter.api.BeforeAll)

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