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);
}
}
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));
}
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));
}
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);
}
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);
}
}
Aggregations