use of com.tvd12.ezyfoxserver.client.entity.EzyUser in project ezyfox-server by youngmonkeys.
the class EzySimpleUserDelegate method onUserRemoved.
@Override
public void onUserRemoved(EzyUser user, EzyConstant reason) {
EzyZoneContext zoneContext = serverContext.getZoneContext(user.getZoneId());
EzySocketUserRemoval removal = new EzySimpleSocketUserRemoval(zoneContext, user, reason);
userRemovalQueue.add(removal);
}
use of com.tvd12.ezyfoxserver.client.entity.EzyUser in project ezyfox-server by youngmonkeys.
the class EzySynchronizedUserManager method addUser.
@Override
public EzyUser addUser(EzyUser user) {
EzyUser answer;
synchronized (synchronizedLock) {
answer = doAddUser(user);
}
logger.info("{} add user: {}, locks.size = {}, usersById.size = {}, usersByName.size = {}", getMessagePrefix(), user, locks.size(), usersById.size(), usersByName.size());
return answer;
}
use of com.tvd12.ezyfoxserver.client.entity.EzyUser in project ezyfox-server by youngmonkeys.
the class EzyLoginControllerTest method testSetUserProperties.
@Test
public void testSetUserProperties() {
EzySimpleServerContext ctx = (EzySimpleServerContext) newServerContext();
EzySimpleServer server = (EzySimpleServer) ctx.getServer();
server.setResponseApi(mock(EzyResponseApi.class));
EzySession session = newSession();
session.setToken("abcdef");
EzyArray data = newLoginData();
EzySimpleLoginRequest request = new EzySimpleLoginRequest();
request.deserializeParams(data);
request.setSession(session);
EzyLoginProcessor processor = new EzyLoginProcessor(ctx);
EzyZoneContext zoneContext = ctx.getZoneContext("example");
EzyLoginParams params = request.getParams();
EzySimpleUserLoginEvent event = new EzySimpleUserLoginEvent(session, params.getZoneName(), params.getUsername(), params.getPassword(), params.getData());
event.setUserProperty("dataId", 123L);
processor.apply(zoneContext, event);
event.release();
EzyZoneUserManager userManager = zoneContext.getZone().getUserManager();
EzyUser user = userManager.getUser("dungtv");
assert user.getProperty("dataId").equals(123L);
}
use of com.tvd12.ezyfoxserver.client.entity.EzyUser in project ezyfox-server by youngmonkeys.
the class EzyLoginProcessorTest method processUserSessionsMaxSessionPerUser.
@SuppressWarnings("rawtypes")
@Test
public void processUserSessionsMaxSessionPerUser() {
// given
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
zoneSetting.getUserManagement().setMaxSessionPerUser(1);
EzySimpleZone zone = new EzySimpleZone();
zone.setSetting(zoneSetting);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(zoneContext.getZone()).thenReturn(zone);
EzySimpleServer server = new EzySimpleServer();
EzySessionManager sessionManager = mock(EzySessionManager.class);
server.setSessionManager(sessionManager);
EzyZoneUserManager userManager = EzyZoneUserManagerImpl.builder().build();
EzyUser user = mock(EzyUser.class);
when(user.getName()).thenReturn("monkey");
when(user.getSessionCount()).thenReturn(2);
userManager.addUser(user);
zone.setUserManager(userManager);
EzyStatistics statistics = mock(EzyStatistics.class);
EzyUserStatistics userStatistics = mock(EzyUserStatistics.class);
when(statistics.getUserStats()).thenReturn(userStatistics);
server.setStatistics(statistics);
EzyServerContext serverContext = mock(EzyServerContext.class);
when(serverContext.getServer()).thenReturn(server);
EzyLoginProcessor sut = new EzyLoginProcessor(serverContext);
EzySessionDelegate sessionDelegate = mock(EzySessionDelegate.class);
EzyAbstractSession session = spy(EzyAbstractSession.class);
session.setDelegate(sessionDelegate);
EzyUserLoginEvent event = mock(EzyUserLoginEvent.class);
when(event.getUsername()).thenReturn("monkey");
when(event.getSession()).thenReturn(session);
// when
Throwable e = Asserts.assertThrows(() -> sut.apply(zoneContext, event));
// then
Asserts.assertEquals(EzyLoginErrorException.class, e.getClass());
}
use of com.tvd12.ezyfoxserver.client.entity.EzyUser in project ezyfox-server by youngmonkeys.
the class EzyLoginProcessorTest method processUserSessionsMaxSessionPerUserGreaterThan1.
@SuppressWarnings("rawtypes")
@Test
public void processUserSessionsMaxSessionPerUserGreaterThan1() {
// given
EzySimpleZoneSetting zoneSetting = new EzySimpleZoneSetting();
zoneSetting.getUserManagement().setMaxSessionPerUser(2);
EzySimpleZone zone = new EzySimpleZone();
zone.setSetting(zoneSetting);
EzyZoneContext zoneContext = mock(EzyZoneContext.class);
when(zoneContext.getZone()).thenReturn(zone);
EzySimpleServer server = new EzySimpleServer();
EzySessionManager sessionManager = mock(EzySessionManager.class);
server.setSessionManager(sessionManager);
EzyZoneUserManager userManager = EzyZoneUserManagerImpl.builder().build();
EzyUser user = mock(EzyUser.class);
when(user.getName()).thenReturn("monkey");
when(user.getSessionCount()).thenReturn(2);
userManager.addUser(user);
zone.setUserManager(userManager);
EzyStatistics statistics = mock(EzyStatistics.class);
EzyUserStatistics userStatistics = mock(EzyUserStatistics.class);
when(statistics.getUserStats()).thenReturn(userStatistics);
server.setStatistics(statistics);
EzyServerContext serverContext = mock(EzyServerContext.class);
when(serverContext.getServer()).thenReturn(server);
EzyLoginProcessor sut = new EzyLoginProcessor(serverContext);
EzySessionDelegate sessionDelegate = mock(EzySessionDelegate.class);
EzyAbstractSession session = spy(EzyAbstractSession.class);
session.setDelegate(sessionDelegate);
EzyUserLoginEvent event = mock(EzyUserLoginEvent.class);
when(event.getUsername()).thenReturn("monkey");
when(event.getSession()).thenReturn(session);
// when
Throwable e = Asserts.assertThrows(() -> sut.apply(zoneContext, event));
// then
Asserts.assertEquals(EzyLoginErrorException.class, e.getClass());
}
Aggregations