Search in sources :

Example 1 with EzyLoginErrorException

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);
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyLoginErrorException(com.tvd12.ezyfoxserver.exception.EzyLoginErrorException) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzyUserLoginEvent(com.tvd12.ezyfoxserver.event.EzyUserLoginEvent) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginController(com.tvd12.ezyfoxserver.controller.EzyLoginController) Test(org.testng.annotations.Test)

Example 2 with EzyLoginErrorException

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);
}
Also used : EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyLoginErrorException(com.tvd12.ezyfoxserver.exception.EzyLoginErrorException) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzyUserLoginEvent(com.tvd12.ezyfoxserver.event.EzyUserLoginEvent) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginController(com.tvd12.ezyfoxserver.controller.EzyLoginController) Test(org.testng.annotations.Test)

Example 3 with EzyLoginErrorException

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);
}
Also used : User(com.tvd12.example.lucky_wheel.entity.User) EzyLoginErrorException(com.tvd12.ezyfoxserver.exception.EzyLoginErrorException)

Example 4 with EzyLoginErrorException

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);
    }
}
Also used : EzyLoginErrorException(com.tvd12.ezyfoxserver.exception.EzyLoginErrorException) EzyLoginErrorException(com.tvd12.ezyfoxserver.exception.EzyLoginErrorException)

Example 5 with EzyLoginErrorException

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;
    }
}
Also used : EzyMaxUserException(com.tvd12.ezyfoxserver.exception.EzyMaxUserException) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyZoneNotFoundException(com.tvd12.ezyfoxserver.exception.EzyZoneNotFoundException) EzyLoginParams(com.tvd12.ezyfoxserver.request.EzyLoginParams) EzyLoginErrorException(com.tvd12.ezyfoxserver.exception.EzyLoginErrorException) EzyUserLoginEvent(com.tvd12.ezyfoxserver.event.EzyUserLoginEvent) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginErrorException(com.tvd12.ezyfoxserver.exception.EzyLoginErrorException) EzyMaxUserException(com.tvd12.ezyfoxserver.exception.EzyMaxUserException) EzyZoneNotFoundException(com.tvd12.ezyfoxserver.exception.EzyZoneNotFoundException)

Aggregations

EzyLoginErrorException (com.tvd12.ezyfoxserver.exception.EzyLoginErrorException)5 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)3 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)3 EzyUserLoginEvent (com.tvd12.ezyfoxserver.event.EzyUserLoginEvent)3 EzyArray (com.tvd12.ezyfox.entity.EzyArray)2 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)2 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)2 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)2 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)2 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)2 Test (org.testng.annotations.Test)2 User (com.tvd12.example.lucky_wheel.entity.User)1 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)1 EzyMaxUserException (com.tvd12.ezyfoxserver.exception.EzyMaxUserException)1 EzyZoneNotFoundException (com.tvd12.ezyfoxserver.exception.EzyZoneNotFoundException)1 EzyLoginParams (com.tvd12.ezyfoxserver.request.EzyLoginParams)1