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, TestConstants.VERSION)));
Caller caller = system.getExtensionService().register(new ExtensionsDatabaseTest.PlayerExtension()).orElseThrow(AssertionError::new);
caller.updatePlayerData(TestConstants.PLAYER_ONE_UUID, TestConstants.PLAYER_ONE_NAME);
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());
}
use of com.djrapitops.plan.delivery.domain.auth.User in project Plan by plan-player-analytics.
the class ActiveCookieStoreTest method createActiveCookieStore.
@BeforeEach
void createActiveCookieStore() {
DBSystem dbSystem = Mockito.mock(DBSystem.class);
Database db = Mockito.mock(Database.class);
when(dbSystem.getDatabase()).thenReturn(db);
underTest = new ActiveCookieStore(Mockito.mock(ActiveCookieExpiryCleanupTask.class), Mockito.mock(PlanConfig.class), dbSystem, Mockito.mock(Processing.class), new TestPluginLogger());
user = new User(TestConstants.PLAYER_ONE_NAME, "console", null, PassEncryptUtil.createHash("testPass"), 0, WebUser.getPermissionsForLevel(0));
}
use of com.djrapitops.plan.delivery.domain.auth.User in project Plan by plan-player-analytics.
the class LargeStoreQueries method storeAllPlanWebUsers.
public static Executable storeAllPlanWebUsers(Collection<User> users) {
if (users == null || users.isEmpty())
return Executable.empty();
return new ExecBatchStatement(SecurityTable.INSERT_STATEMENT) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
for (User user : users) {
statement.setString(1, user.getUsername());
if (user.getLinkedToUUID() == null) {
statement.setNull(2, Types.VARCHAR);
} else {
statement.setString(2, user.getLinkedToUUID().toString());
}
statement.setString(3, user.getPasswordHash());
statement.setInt(4, user.getPermissionLevel());
statement.addBatch();
}
}
};
}
use of com.djrapitops.plan.delivery.domain.auth.User in project Plan by plan-player-analytics.
the class RegistrationCommands method registerUsingCode.
public void registerUsingCode(CMDSender sender, String code) {
UUID linkedToUUID = sender.getUUID().orElse(null);
Optional<User> user = RegistrationBin.register(code, linkedToUUID);
if (user.isPresent()) {
registerUser(user.get(), sender, getPermissionLevel(sender));
} else {
throw new IllegalArgumentException(locale.getString(FailReason.USER_INFORMATION_NOT_FOUND));
}
}
use of com.djrapitops.plan.delivery.domain.auth.User in project Plan by plan-player-analytics.
the class RegistrationCommands method onUnregister.
public void onUnregister(String mainCommand, CMDSender sender, Arguments arguments) {
Optional<String> givenUsername = arguments.get(0).filter(arg -> sender.hasPermission(Permissions.UNREGISTER_OTHER));
Database database = dbSystem.getDatabase();
UUID playerUUID = sender.getUUID().orElse(null);
String username;
if (!givenUsername.isPresent() && playerUUID != null) {
Optional<User> found = database.query(WebUserQueries.fetchUser(playerUUID));
if (!found.isPresent()) {
throw new IllegalArgumentException(locale.getString(CommandLang.USER_NOT_LINKED));
}
username = found.get().getUsername();
} else if (!givenUsername.isPresent()) {
throw new IllegalArgumentException(locale.getString(CommandLang.FAIL_REQ_ONE_ARG, "<" + locale.getString(HelpLang.ARG_USERNAME) + ">"));
} else {
username = givenUsername.get();
}
Optional<User> found = database.query(WebUserQueries.fetchUser(username));
if (!found.isPresent()) {
throw new IllegalArgumentException(locale.getString(FailReason.USER_DOES_NOT_EXIST));
}
User presentUser = found.get();
boolean ownsTheUser = Objects.equals(playerUUID, presentUser.getLinkedToUUID());
if (!(ownsTheUser || sender.hasPermission(Permissions.UNREGISTER_OTHER.getPerm()))) {
throw new IllegalArgumentException(locale.getString(CommandLang.USER_NOT_LINKED));
}
if (sender.supportsChatEvents()) {
sender.buildMessage().addPart(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_UNREGISTER, presentUser.getUsername(), presentUser.getLinkedTo())).newLine().addPart(colors.getTertiaryColor() + locale.getString(CommandLang.CONFIRM)).addPart("§2§l[\u2714]").command("/" + mainCommand + " accept").hover(locale.getString(CommandLang.CONFIRM_ACCEPT)).addPart(" ").addPart("§4§l[\u2718]").command("/" + mainCommand + " cancel").hover(locale.getString(CommandLang.CONFIRM_DENY)).send();
} else {
sender.buildMessage().addPart(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_UNREGISTER, presentUser.getUsername(), presentUser.getLinkedTo())).newLine().addPart(colors.getTertiaryColor() + locale.getString(CommandLang.CONFIRM)).addPart("§a/" + mainCommand + " accept").addPart(" ").addPart("§c/" + mainCommand + " cancel").send();
}
confirmation.confirm(sender, choice -> {
if (Boolean.TRUE.equals(choice)) {
try {
sender.send(colors.getMainColor() + locale.getString(CommandLang.UNREGISTER, presentUser.getUsername()));
database.executeTransaction(new RemoveWebUserTransaction(username)).get();
ActiveCookieStore.removeUserCookie(username);
sender.send(locale.getString(CommandLang.PROGRESS_SUCCESS));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (ExecutionException e) {
errorLogger.warn(e, ErrorContext.builder().related("unregister command", sender, sender.getPlayerName().orElse("console"), arguments).build());
}
} else {
sender.send(colors.getMainColor() + locale.getString(CommandLang.CONFIRM_CANCELLED_UNREGISTER, presentUser.getUsername()));
}
});
}
Aggregations