Search in sources :

Example 1 with EzySimpleUserManagementSetting

use of com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting 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 2 with EzySimpleUserManagementSetting

use of com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting 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 3 with EzySimpleUserManagementSetting

use of com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting 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)

Example 4 with EzySimpleUserManagementSetting

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

the class EzyLoginControllerTest method processChangeSessionTest.

@Test
public void processChangeSessionTest() {
    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(true);
    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 EzySimpleUserManagementSetting

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

the class HelloEmbeddedServer3 method main.

public static void main(String[] args) throws Exception {
    EzySimplePluginSetting pluginSetting = new EzyPluginSettingBuilder().name(// plugin name
    "hello").addListenEvent(// listen able events USER_LOGIN, USER_ADDED, USER_REMOVED
    EzyEventType.USER_LOGIN).configFile("config.properties").entryLoader(HelloPluginEntryLoader.class).priority(// set priority, bigger number is lower, default 0
    1).threadPoolSize(// set thread pool size to create executor service for this plugin, default 0
    3).build();
    EzySimpleAppSetting appSetting = new EzyAppSettingBuilder().name(// app's name
    "hello").configFile("config.properties").entryLoader(HelloAppEntryLoader.class).maxUsers(// set max user in this app, default 999999
    9999).threadPoolSize(// set thread pool size to create executor service for this app, default 0
    3).build();
    EzySimpleUserManagementSetting userManagementSetting = new EzyUserManagementSettingBuilder().allowChangeSession(// allow change user's session, default true
    true).allowGuestLogin(// allow guest login, default false
    true).guestNamePrefix(// set name prefix for guest
    "Guest#").maxSessionPerUser(// set number of max sessions per user // default 5
    5).userMaxIdleTimeInSecond(// set max idle time of an user, default 0
    15).userNamePattern(// set username pattern, default ^[a-z0-9_.]{3,36}$
    "^[a-z0-9_.]{3,36}$").build();
    EzySimpleZoneSetting zoneSetting = new EzyZoneSettingBuilder().name(// zone's name
    "hello").plugin(// add a plug-in to zone
    pluginSetting).application(// add an app to zone
    appSetting).configFile(// set config file
    "config.properties").maxUsers(// set maximum user for zone
    999999).userManagement(// set user management settings
    userManagementSetting).addEventController(EzyEventType.SERVER_READY, HelloZoneServerReadyController.class).build();
    EzySimpleSocketSetting socketSetting = new EzySocketSettingBuilder().active(// active or not,  default true
    true).address(// loopback address, default 0.0.0.0
    "0.0.0.0").codecCreator(// encoder/decoder creator, default MsgPackCodecCreator
    MsgPackCodecCreator.class).maxRequestSize(// max request size, default 32768
    1024).port(// port, default 3005
    3005).tcpNoDelay(// tcp no delay, default false
    true).writerThreadPoolSize(// thread pool size for socket writer, default 8
    8).build();
    EzySimpleWebSocketSetting webSocketSetting = new EzyWebSocketSettingBuilder().active(// active or not,  default true
    true).address(// loopback address, default 0.0.0.0
    "0.0.0.0").codecCreator(// encoder/decoder creator, default JacksonCodecCreator
    JacksonCodecCreator.class).maxFrameSize(// max frame size, default 32768
    32678).port(// port, default 3005
    2208).writerThreadPoolSize(// thread pool size for socket writer, default 8
    8).build();
    EzySimpleMaxRequestPerSecond maxRequestPerSecond = new EzyMaxRequestPerSecondBuilder().value(// max request in a second
    15).action(// action when get max
    EzyMaxRequestPerSecondAction.DROP_REQUEST).build();
    EzySimpleSessionManagementSetting sessionManagementSetting = new EzySessionManagementSettingBuilder().sessionMaxIdleTimeInSecond(// set max idle time for session, default 30s
    30).sessionMaxWaitingTimeInSecond(// set max waiting time to login for session, default 30s
    30).sessionMaxRequestPerSecond(// set max request in a session for a session
    maxRequestPerSecond).build();
    EzySimpleUdpSetting udpSetting = new EzyUdpSettingBuilder().active(// active or not
    true).address(// set loopback IP
    "0.0.0.0").channelPoolSize(// set number of udp channel for socket writing, default 16
    16).codecCreator(// encoder/decoder creator, default MsgPackCodecCreator
    MsgPackCodecCreator.class).handlerThreadPoolSize(// set number of handler's thread, default 5
    5).maxRequestSize(// set max request's size
    1024).port(// set listen port
    2611).build();
    EzySimpleSettings settings = new EzySettingsBuilder().debug(// allow debug to print log or not, default false
    true).nodeName(// for convenient
    "hello").zone(// add a zone to server
    zoneSetting).socket(// set socket setting
    socketSetting).websocket(// set websocket setting
    webSocketSetting).udp(// set udp setting
    udpSetting).sessionManagement(// set session management setting
    sessionManagementSetting).addEventController(EzyEventType.SERVER_INITIALIZING, HelloServerInitializingReadyController.class).build();
    EzyEmbeddedServer server = EzyEmbeddedServer.builder().settings(settings).build();
    server.start();
}
Also used : EzySimpleMaxRequestPerSecond(com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond) MsgPackCodecCreator(com.tvd12.ezyfox.codec.MsgPackCodecCreator) EzyMaxRequestPerSecondBuilder(com.tvd12.ezyfoxserver.setting.EzySessionManagementSettingBuilder.EzyMaxRequestPerSecondBuilder) EzyEmbeddedServer(com.tvd12.ezyfoxserver.embedded.EzyEmbeddedServer)

Aggregations

Test (org.testng.annotations.Test)7 EzySimpleUserManagementSetting (com.tvd12.ezyfoxserver.setting.EzySimpleUserManagementSetting)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 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)5 EzyLoginController (com.tvd12.ezyfoxserver.controller.EzyLoginController)5 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)5 EzySimpleLoginRequest (com.tvd12.ezyfoxserver.request.EzySimpleLoginRequest)5 EzyZoneSetting (com.tvd12.ezyfoxserver.setting.EzyZoneSetting)5 MsgPackCodecCreator (com.tvd12.ezyfox.codec.MsgPackCodecCreator)1 EzyEmbeddedServer (com.tvd12.ezyfoxserver.embedded.EzyEmbeddedServer)1 EzyMaxRequestPerSecondBuilder (com.tvd12.ezyfoxserver.setting.EzySessionManagementSettingBuilder.EzyMaxRequestPerSecondBuilder)1 EzySimpleListenEvents (com.tvd12.ezyfoxserver.setting.EzySimplePluginSetting.EzySimpleListenEvents)1 EzySimpleMaxRequestPerSecond (com.tvd12.ezyfoxserver.setting.EzySimpleSessionManagementSetting.EzySimpleMaxRequestPerSecond)1 BaseTest (com.tvd12.test.base.BaseTest)1