use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.
the class EzySocketResponseApiTest method secureResponseTest.
@Test
public void secureResponseTest() throws Exception {
// given
EzyArray data = EzyEntityFactory.EMPTY_ARRAY;
byte[] bytes = RandomUtil.randomShortByteArray();
EzyObjectToByteEncoder encoder = mock(EzyObjectToByteEncoder.class);
when(encoder.toMessageContent(data)).thenReturn(bytes);
EzySocketResponseApi sut = new EzySocketResponseApi(encoder);
EzySimplePackage pack = new EzySimplePackage();
pack.setData(data);
pack.setEncrypted(true);
pack.setTransportType(EzyTransportType.TCP);
int sessionCount = RandomUtil.randomSmallInt() + 1;
List<EzySession> sessions = RandomUtil.randomList(sessionCount, () -> {
EzySession session = mock(EzySession.class);
when(session.getConnectionType()).thenReturn(EzyConnectionType.SOCKET);
return session;
});
pack.addRecipients(sessions);
// when
sut.response(pack);
// then
verify(encoder, times(1)).toMessageContent(data);
verify(encoder, times(sessionCount)).encryptMessageContent(any(byte[].class), any(byte[].class));
}
use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.
the class EzyAccessAppController method doHandle.
protected void doHandle(EzyServerContext ctx, EzyAccessAppRequest request) {
EzyUser user = request.getUser();
int zoneId = user.getZoneId();
EzyAccessAppParams params = request.getParams();
EzyZoneContext zoneContext = ctx.getZoneContext(zoneId);
EzyAppContext appContext = zoneContext.getAppContext(params.getAppName());
EzyApplication app = appContext.getApp();
EzyAppSetting appSetting = app.getSetting();
EzyAppUserManager appUserManger = app.getUserManager();
EzySession session = request.getSession();
String username = user.getName();
Lock lock = appUserManger.getLock(username);
lock.lock();
try {
boolean hasNotAccessed = !appUserManger.containsUser(user);
if (hasNotAccessed) {
checkAppUserMangerAvailable(appUserManger);
}
EzyUserAccessAppEvent accessAppEvent = new EzySimpleUserAccessAppEvent(user);
appContext.handleEvent(EzyEventType.USER_ACCESS_APP, accessAppEvent);
if (hasNotAccessed) {
addUser(appUserManger, user, appSetting);
EzyUserAccessedAppEvent accessedAppEvent = new EzySimpleUserAccessedAppEvent(user);
appContext.handleEvent(EzyEventType.USER_ACCESSED_APP, accessedAppEvent);
}
EzyArray output = accessAppEvent.getOutput();
EzyResponse accessAppResponse = newAccessAppResponse(appSetting, output);
ctx.send(accessAppResponse, session, false);
} finally {
lock.unlock();
appUserManger.removeLock(username);
}
}
use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.
the class EzySimpleDataHandler method handleReceivedData.
protected void handleReceivedData(EzyConstant cmd, EzyArray msg) {
EzyArray data = msg.get(1, EzyArray.class);
debugLogReceivedData(cmd, data);
updateSessionBeforeHandleRequest();
handleRequest(cmd, data);
}
use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.
the class EzyUserDataHandler method newRequest.
@SuppressWarnings({ "rawtypes" })
protected EzyRequest newRequest(EzyConstant cmd, EzyArray data) {
EzySimpleRequest request = requestFactory.newRequest(cmd);
request.setSession(session);
request.setUser(user);
request.deserializeParams(data);
return request;
}
use of com.tvd12.ezyfoxserver.client.entity.EzyArray in project ezyfox-server by youngmonkeys.
the class EzyPongResponse method newData.
private EzyArray newData() {
EzyArray array = EzyEntityFactory.newArray();
array.add(getCommand().getId());
return array;
}
Aggregations