use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.
the class EzyRequestPluginController method handle.
@Override
public void handle(EzyServerContext ctx, EzyRequestPluginRequest request) {
EzyRequestPluginParams params = request.getParams();
EzyUser user = request.getUser();
EzyZoneContext zoneCtx = ctx.getZoneContext(user.getZoneId());
EzyPluginContext pluginCtx = getPluginContext(zoneCtx, params);
EzyPlugin plugin = pluginCtx.getPlugin();
EzyPluginRequestController requestController = plugin.getRequestController();
EzyUserRequestPluginEvent event = newRequestPluginEvent(request);
requestController.handle(pluginCtx, event);
}
use of com.tvd12.ezyfoxserver.context.EzyServerContext 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.context.EzyServerContext in project ezyfox-server by youngmonkeys.
the class EzyExitAppController method handle.
@Override
public void handle(EzyServerContext ctx, EzyExitAppRequest request) {
int appId = request.getParams().getAppId();
EzyAppContext appContext = ctx.getAppContext(appId);
EzyApplication app = appContext.getApp();
EzyAppUserManager userManager = app.getUserManager();
userManager.removeUser(request.getUser(), EzyUserRemoveReason.EXIT_APP);
}
use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.
the class EzyHandshakeController method handleSocketSSL.
@SuppressWarnings("AbbreviationAsWordInName")
protected void handleSocketSSL(EzyServerContext ctx, EzyHandshakeEvent event) {
EzySession session = event.getSession();
if (session.getConnectionType() == EzyConnectionType.WEBSOCKET) {
return;
}
boolean enableSSL = ctx.getServer().getSettings().getSocket().isSslActive();
if (!enableSSL) {
return;
}
if (!event.isEnableEncryption()) {
return;
}
byte[] clientKey = event.getClientKey();
byte[] sessionKey = event.getSessionKey();
if (sessionKey == null) {
sessionKey = EzyAesCrypt.randomKey();
event.setSessionKey(sessionKey);
}
byte[] encryptedSessionKey = event.getEncryptedSessionKey();
if (encryptedSessionKey == null) {
encryptedSessionKey = sessionKey;
try {
if (clientKey.length > 0) {
encryptedSessionKey = EzyAsyCrypt.builder().publicKey(clientKey).build().encrypt(sessionKey);
}
} catch (Exception e) {
logger.debug("cannot encrypt session key for session: {}", session, e);
}
event.setEncryptedSessionKey(encryptedSessionKey);
}
}
use of com.tvd12.ezyfoxserver.context.EzyServerContext in project ezyfox-server by youngmonkeys.
the class BaseCoreTest method newServerContext.
protected EzyServerContext newServerContext() {
EzyServerContext serverContext = newServerContextBuilder().build();
for (EzyZoneContext zoneContext : serverContext.getZoneContexts()) {
((EzyInitable) zoneContext).init();
}
for (EzyAppContext appContext : serverContext.getAppContexts()) {
((EzyInitable) appContext).init();
}
EzySimpleServerContext ctx = (EzySimpleServerContext) serverContext;
EzySimpleServer server = (EzySimpleServer) ctx.getServer();
server.setResponseApi(mock(EzyResponseApi.class));
return ctx;
}
Aggregations