Launcher/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthException.java

40 lines
1.1 KiB
Java
Raw Normal View History

package pro.gravit.launchserver.auth;
2018-09-17 10:07:32 +03:00
2021-11-05 18:19:00 +03:00
import pro.gravit.launcher.events.request.AuthRequestEvent;
2018-09-17 10:07:32 +03:00
import java.io.IOException;
2021-11-05 18:19:00 +03:00
import java.util.List;
import java.util.stream.Collectors;
2018-09-17 10:07:32 +03:00
public final class AuthException extends IOException {
private static final long serialVersionUID = -2586107832847245863L;
2018-10-13 11:01:10 +03:00
2018-09-17 10:07:32 +03:00
public AuthException(String message) {
super(message);
}
2021-11-05 18:19:00 +03:00
public static AuthException need2FA() {
return new AuthException(AuthRequestEvent.TWO_FACTOR_NEED_ERROR_MESSAGE);
}
public static AuthException needMFA(List<Integer> factors) {
String message = AuthRequestEvent.ONE_FACTOR_NEED_ERROR_MESSAGE_PREFIX
.concat(factors.stream().map(String::valueOf).collect(Collectors.joining(".")));
return new AuthException(message);
}
public static AuthException wrongPassword() {
return new AuthException(AuthRequestEvent.WRONG_PASSWORD_ERROR_MESSAGE);
}
public static AuthException userNotFound() {
return new AuthException(AuthRequestEvent.USER_NOT_FOUND_ERROR_MESSAGE);
}
2018-09-17 10:07:32 +03:00
@Override
public String toString() {
return getMessage();
}
}