Search in sources :

Example 1 with EzyZoneSetting

use of com.tvd12.ezyfoxserver.setting.EzyZoneSetting in project ezyfox-server by youngmonkeys.

the class EzyLoginProcessor method apply.

public void apply(EzyZoneContext zoneContext, EzyUserLoginEvent event) {
    EzyZone zone = zoneContext.getZone();
    EzyZoneSetting zoneSetting = zone.getSetting();
    EzyUserManagementSetting userManagementSetting = zoneSetting.getUserManagement();
    String username = checkUsername(event.getUsername(), userManagementSetting.getUserNamePattern(), userManagementSetting.isAllowGuestLogin(), userManagementSetting.getGuestNamePrefix());
    String password = event.getPassword();
    EzyZoneUserManager userManager = zone.getUserManager();
    EzyUser user;
    EzySession session = event.getSession();
    boolean alreadyLoggedIn;
    Lock lock = userManager.getLock(username);
    lock.lock();
    try {
        alreadyLoggedIn = userManager.containsUser(username);
        if (alreadyLoggedIn) {
            user = userManager.getUser(username);
        } else {
            user = newUser(zoneSetting, userManagementSetting, username, password, event.getUserProperties());
        }
        int maxSessionPerUser = userManagementSetting.getMaxSessionPerUser();
        boolean allowChangeSession = userManagementSetting.isAllowChangeSession();
        EzyStreamingSetting streamingSetting = zoneSetting.getStreaming();
        boolean streamingEnable = streamingSetting.isEnable() && event.isStreamingEnable();
        processUserSessions(user, session, maxSessionPerUser, allowChangeSession, streamingEnable);
        addUserToManager(userManager, user, session, alreadyLoggedIn);
    } finally {
        lock.unlock();
        userManager.removeLock(username);
    }
    fireUserAddedEvent(zoneContext, user, session, event.getData(), alreadyLoggedIn);
    EzyResponse response = newLoginResponse(zoneContext, user, event.getOutput());
    serverContext.send(response, session, false);
}
Also used : EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyStreamingSetting(com.tvd12.ezyfoxserver.setting.EzyStreamingSetting) EzyUserManagementSetting(com.tvd12.ezyfoxserver.setting.EzyUserManagementSetting) EzyZoneSetting(com.tvd12.ezyfoxserver.setting.EzyZoneSetting) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyZoneUserManager(com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager) Lock(java.util.concurrent.locks.Lock)

Example 2 with EzyZoneSetting

use of com.tvd12.ezyfoxserver.setting.EzyZoneSetting in project ezyfox-server by youngmonkeys.

the class EzyLoginProcessor method newUser.

protected EzyUser newUser(EzyZoneSetting zoneSetting, EzyUserManagementSetting userManagementSetting, String newUserName, String password, Map<Object, Object> properties) {
    EzySimpleUser user = new EzySimpleUser();
    user.setName(newUserName);
    user.setPassword(password);
    user.setZoneId(zoneSetting.getId());
    user.setMaxIdleTime(userManagementSetting.getUserMaxIdleTime());
    user.setMaxSessions(userManagementSetting.getMaxSessionPerUser());
    user.setProperties(properties);
    return user;
}
Also used : EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser)

Example 3 with EzyZoneSetting

use of com.tvd12.ezyfoxserver.setting.EzyZoneSetting in project ezyfox-server by youngmonkeys.

the class EzyLoginControllerTest method maximumSession1Test.

@Test(expectedExceptions = EzyLoginErrorException.class)
public void maximumSession1Test() {
    EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
    EzySimpleServer server = (EzySimpleServer) ctx.getServer();
    EzyZoneContext zoneContext = ctx.getZoneContext("example");
    EzyZoneSetting zoneSetting = zoneContext.getZone().getSetting();
    EzySimpleUserManagementSetting userManagementSetting = (EzySimpleUserManagementSetting) zoneSetting.getUserManagement();
    userManagementSetting.setMaxSessionPerUser(0);
    server.setResponseApi(mock(EzyResponseApi.class));
    EzySession session = newSession();
    session.setToken("abcdef");
    EzyArray data = newLoginData();
    data.set(1, "");
    EzyLoginController controller = new EzyLoginController();
    EzySimpleLoginRequest request = new EzySimpleLoginRequest();
    request.deserializeParams(data);
    request.setSession(session);
    controller.handle(ctx, request);
}
Also used : EzySimpleUserManagementSetting(com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyZoneSetting(com.tvd12.ezyfoxserver.setting.EzyZoneSetting) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginController(com.tvd12.ezyfoxserver.controller.EzyLoginController) Test(org.testng.annotations.Test)

Example 4 with EzyZoneSetting

use of com.tvd12.ezyfoxserver.setting.EzyZoneSetting in project ezyfox-server by youngmonkeys.

the class EzyLoginControllerTest method maximumSession3Test.

@Test(expectedExceptions = EzyLoginErrorException.class)
public void maximumSession3Test() {
    EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
    EzySimpleServer server = (EzySimpleServer) ctx.getServer();
    EzyZoneContext zoneContext = ctx.getZoneContext("example");
    EzyZoneSetting zoneSetting = zoneContext.getZone().getSetting();
    EzySimpleUserManagementSetting userManagementSetting = (EzySimpleUserManagementSetting) zoneSetting.getUserManagement();
    userManagementSetting.setMaxSessionPerUser(1);
    userManagementSetting.setAllowChangeSession(false);
    server.setResponseApi(mock(EzyResponseApi.class));
    EzySession session = newSession();
    session.setToken("abcdef");
    EzyArray data = newLoginData();
    data.set(1, "helloworld");
    EzyLoginController controller = new EzyLoginController();
    EzySimpleLoginRequest request = new EzySimpleLoginRequest();
    request.deserializeParams(data);
    request.setSession(session);
    controller.handle(ctx, request);
    controller.handle(ctx, request);
}
Also used : EzySimpleUserManagementSetting(com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyZoneSetting(com.tvd12.ezyfoxserver.setting.EzyZoneSetting) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginController(com.tvd12.ezyfoxserver.controller.EzyLoginController) Test(org.testng.annotations.Test)

Example 5 with EzyZoneSetting

use of com.tvd12.ezyfoxserver.setting.EzyZoneSetting in project ezyfox-server by youngmonkeys.

the class EzyLoginControllerTest method maximumSession2Test.

@Test(expectedExceptions = EzyLoginErrorException.class)
public void maximumSession2Test() {
    EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
    EzySimpleServer server = (EzySimpleServer) ctx.getServer();
    EzyZoneContext zoneContext = ctx.getZoneContext("example");
    EzyZoneSetting zoneSetting = zoneContext.getZone().getSetting();
    EzySimpleUserManagementSetting userManagementSetting = (EzySimpleUserManagementSetting) zoneSetting.getUserManagement();
    userManagementSetting.setMaxSessionPerUser(2);
    userManagementSetting.setAllowChangeSession(false);
    server.setResponseApi(mock(EzyResponseApi.class));
    EzySession session = newSession(1);
    session.setToken("abcdef");
    EzyArray data = newLoginData();
    data.set(1, "helloworld");
    EzyLoginController controller = new EzyLoginController();
    EzySimpleLoginRequest request = new EzySimpleLoginRequest();
    request.deserializeParams(data);
    request.setSession(session);
    controller.handle(ctx, request);
    request.setSession(newSession(2));
    controller.handle(ctx, request);
    request.setSession(newSession(3));
    controller.handle(ctx, request);
}
Also used : EzySimpleUserManagementSetting(com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyZoneSetting(com.tvd12.ezyfoxserver.setting.EzyZoneSetting) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzySimpleLoginRequest(com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) EzyLoginController(com.tvd12.ezyfoxserver.controller.EzyLoginController) Test(org.testng.annotations.Test)

Aggregations

EzyZoneSetting (com.tvd12.ezyfoxserver.setting.EzyZoneSetting)8 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)6 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)6 Test (org.testng.annotations.Test)6 EzyArray (com.tvd12.ezyfox.entity.EzyArray)5 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)5 EzyResponseApi (com.tvd12.ezyfoxserver.api.EzyResponseApi)5 EzySimpleServerContext (com.tvd12.ezyfoxserver.context.EzySimpleServerContext)5 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)5 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)5 EzySimpleUserManagementSetting (com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting)5 EzyZone (com.tvd12.ezyfoxserver.EzyZone)2 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)2 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)2 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)2 EzyConstant (com.tvd12.ezyfox.constant.EzyConstant)1 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)1 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)1 EzyUserDelegate (com.tvd12.ezyfoxserver.delegate.EzyUserDelegate)1 EzyUserEvent (com.tvd12.ezyfoxserver.event.EzyUserEvent)1