use of com.tvd12.ezyfoxserver.exception.EzyLoginErrorException in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method test1.
@Test(expectedExceptions = { EzyLoginErrorException.class })
public void test1() {
EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
EzySimpleServer server = (EzySimpleServer) ctx.getServer();
server.setResponseApi(mock(EzyResponseApi.class));
EzySession session = newSession();
session.setToken("abcdef");
EzyArray data = newLoginData1();
EzyLoginController controller = new EzyLoginController() {
@Override
protected void process(EzyServerContext ctx, EzyZoneContext zoneContext, EzyUserLoginEvent event) {
throw new EzyLoginErrorException();
}
};
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
controller.handle(ctx, request);
}
use of com.tvd12.ezyfoxserver.exception.EzyLoginErrorException in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method test2.
@Test(expectedExceptions = { EzyLoginErrorException.class })
public void test2() {
EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
EzySimpleServer server = (EzySimpleServer) ctx.getServer();
server.setResponseApi(mock(EzyResponseApi.class));
EzySession session = newSession();
session.setToken("abcdef");
EzyArray data = newLoginData();
EzyLoginController controller = new EzyLoginController() {
@Override
protected void firePluginEvent(EzyZoneContext zoneContext, EzyUserLoginEvent event) {
throw new EzyLoginErrorException();
}
};
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
controller.handle(ctx, request);
}
use of com.tvd12.ezyfoxserver.exception.EzyLoginErrorException in project ezyfox-server-example by tvd12.
the class UserLoginController method handle.
@Override
public void handle(EzyPluginContext ctx, EzyUserLoginEvent event) {
logger.info("{} login in", event.getUsername());
String username = event.getUsername();
String password = encodePassword(event.getPassword());
User user = userService.getUser(username);
if (user == null) {
logger.info("User doesn't exist in db, create a new one!");
user = userService.createUser(username, password);
userService.saveUser(user);
}
if (!user.getPassword().equals(password)) {
throw new EzyLoginErrorException(EzyLoginError.INVALID_PASSWORD);
}
logger.info("user and password match, accept user: {}", username);
}
use of com.tvd12.ezyfoxserver.exception.EzyLoginErrorException in project ezyfox-server-example by tvd12.
the class UserLoginController method loginWithToken.
private void loginWithToken(EzyUserLoginEvent event, String token) {
logger.info("handle user login in with token");
try {
byte[] usernameBytes = EzyAesCrypt.getDefault().decrypt(EzyBase64.decode(token), CommonConstants.TOKEN_ENCRYPTION_KEY.getBytes());
String username = new String(usernameBytes);
event.setUsername(username);
} catch (Exception e) {
throw new EzyLoginErrorException(EzyLoginError.INVALID_TOKEN);
}
}
use of com.tvd12.ezyfoxserver.exception.EzyLoginErrorException in project ezyfox-server by youngmonkeys.
the class EzyLoginController method handle.
@Override
public void handle(EzyServerContext ctx, EzyLoginRequest request) {
try {
EzySession session = request.getSession();
EzyLoginParams params = request.getParams();
EzyZoneContext zoneContext = ctx.getZoneContext(params.getZoneName());
EzyUserLoginEvent loginEvent = newLoginEvent(session, params);
try {
control(ctx, zoneContext, loginEvent);
} finally {
loginEvent.release();
}
} catch (EzyLoginErrorException e) {
processException(ctx, request.getSession(), e);
throw e;
} catch (EzyMaxUserException e) {
processException(ctx, request.getSession(), maximumUsers(e));
throw e;
} catch (EzyZoneNotFoundException e) {
processException(ctx, request.getSession(), zoneNotFound(e));
throw e;
} catch (Exception e) {
processException(ctx, request.getSession(), serverError(e));
throw e;
}
}
Aggregations