Search in sources :

Example 6 with User

use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.

the class EzyDisconnectUserImplTest method test2.

@Test
public void test2() {
    MyTestUser user = new MyTestUser();
    user.setName("dungtv");
    EzySession session = newSession();
    session.setToken("abc");
    user.addSession(session);
}
Also used : MyTestUser(com.tvd12.ezyfoxserver.testing.MyTestUser) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) BaseCoreTest(com.tvd12.ezyfoxserver.testing.BaseCoreTest) Test(org.testng.annotations.Test)

Example 7 with User

use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.

the class EzyBroadcastAppsEventImplTest method newAppContext.

private EzyAppContext newAppContext(String appName, EzyEvent event2) {
    EzyAppContext appContext = mock(EzyAppContext.class);
    EzyApplication app = mock(EzyApplication.class);
    when(appContext.getApp()).thenReturn(app);
    EzySimpleAppSetting setting = new EzySimpleAppSetting();
    setting.setName(appName);
    when(app.getSetting()).thenReturn(setting);
    EzyAppUserManager appUserManager = EzyAppUserManagerImpl.builder().appName(appName).maxUsers(99).build();
    when(app.getUserManager()).thenReturn(appUserManager);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("user" + appName);
    appUserManager.addUser(user);
    doThrow(new IllegalStateException()).when(appContext).handleEvent(EzyEventType.SERVER_INITIALIZING, event2);
    return appContext;
}
Also used : EzySimpleAppSetting(com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext)

Example 8 with User

use of com.tvd12.example.lucky_wheel.entity.User in project ezyfox-server by youngmonkeys.

the class EzyBroadcastAppsEventImplTest method test.

@Test
public void test() {
    EzyEvent event2 = new EzySimpleServerInitializingEvent();
    EzyZoneContext zoneContext = mock(EzyZoneContext.class);
    List<EzyAppContext> appContexts = Lists.newArrayList(newAppContext("1", event2), newAppContext("2", event2), newAppContext("3", event2));
    when(zoneContext.getAppContexts()).thenReturn(appContexts);
    EzyZone zone = mock(EzyZone.class);
    EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
    zoneSetting.setName("test");
    when(zone.getSetting()).thenReturn(zoneSetting);
    when(zoneContext.getZone()).thenReturn(zone);
    EzyBroadcastAppsEventImpl cmd = new EzyBroadcastAppsEventImpl(zoneContext);
    EzyEvent event = new EzySimpleServerInitializingEvent();
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, false);
    EzySimpleUser user = new EzySimpleUser();
    user.setName("user1");
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, user, true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event, "user1", true);
    cmd.fire(EzyEventType.SERVER_INITIALIZING, event2, true);
}
Also used : EzySimpleServerInitializingEvent(com.tvd12.ezyfoxserver.event.EzySimpleServerInitializingEvent) EzyZone(com.tvd12.ezyfoxserver.EzyZone) EzyEvent(com.tvd12.ezyfoxserver.event.EzyEvent) EzySimpleUser(com.tvd12.ezyfoxserver.entity.EzySimpleUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyBroadcastAppsEventImpl(com.tvd12.ezyfoxserver.command.impl.EzyBroadcastAppsEventImpl) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzySimpleZoneSetting(com.tvd12.ezyfoxserver.setting.EzySimpleZoneSetting) Test(org.testng.annotations.Test) BaseTest(com.tvd12.test.base.BaseTest)

Example 9 with User

use of com.tvd12.example.lucky_wheel.entity.User 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 10 with User

use of com.tvd12.example.lucky_wheel.entity.User 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)

Aggregations

Test (org.testng.annotations.Test)42 EzySimpleUser (com.tvd12.ezyfoxserver.entity.EzySimpleUser)33 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)28 EzyUser (com.tvd12.ezyfoxserver.entity.EzyUser)25 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)20 EzyArray (com.tvd12.ezyfox.entity.EzyArray)16 EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)16 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)15 BaseTest (com.tvd12.test.base.BaseTest)14 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)13 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)12 EzyApplication (com.tvd12.ezyfoxserver.EzyApplication)10 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)10 EzySimpleAppSetting (com.tvd12.ezyfoxserver.setting.EzySimpleAppSetting)8 GreetResponse (com.tvd12.ezyfoxserver.support.test.data.GreetResponse)8 EzyAppUserManager (com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager)8 EzyDoHandle (com.tvd12.ezyfox.core.annotation.EzyDoHandle)7 EzySimpleApplication (com.tvd12.ezyfoxserver.EzySimpleApplication)7 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)7 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)7