Search in sources :

Example 1 with PassEncryptException

use of com.djrapitops.plan.exceptions.PassEncryptException 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)

Aggregations

User (com.djrapitops.plan.delivery.domain.auth.User)1 PassEncryptException (com.djrapitops.plan.exceptions.PassEncryptException)1 WebUserAuthException (com.djrapitops.plan.exceptions.WebUserAuthException)1 DBOpException (com.djrapitops.plan.exceptions.database.DBOpException)1 Database (com.djrapitops.plan.storage.database.Database)1