Search in sources :

Example 76 with EzyServerContext

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);
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyPluginContext(com.tvd12.ezyfoxserver.context.EzyPluginContext) EzyPluginRequestController(com.tvd12.ezyfoxserver.plugin.EzyPluginRequestController) EzyPlugin(com.tvd12.ezyfoxserver.EzyPlugin) EzyRequestPluginParams(com.tvd12.ezyfoxserver.request.EzyRequestPluginParams) EzyUserRequestPluginEvent(com.tvd12.ezyfoxserver.event.EzyUserRequestPluginEvent)

Example 77 with EzyServerContext

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);
    }
}
Also used : EzyUser(com.tvd12.ezyfoxserver.entity.EzyUser) EzyAccessAppParams(com.tvd12.ezyfoxserver.request.EzyAccessAppParams) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzySimpleUserAccessedAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessedAppEvent) EzyResponse(com.tvd12.ezyfoxserver.response.EzyResponse) EzySession(com.tvd12.ezyfoxserver.entity.EzySession) Lock(java.util.concurrent.locks.Lock) EzyAppSetting(com.tvd12.ezyfoxserver.setting.EzyAppSetting) EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyUserAccessedAppEvent(com.tvd12.ezyfoxserver.event.EzyUserAccessedAppEvent) EzyArray(com.tvd12.ezyfox.entity.EzyArray) EzyUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzyUserAccessAppEvent) EzySimpleUserAccessAppEvent(com.tvd12.ezyfoxserver.event.EzySimpleUserAccessAppEvent)

Example 78 with EzyServerContext

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);
}
Also used : EzyApplication(com.tvd12.ezyfoxserver.EzyApplication) EzyAppUserManager(com.tvd12.ezyfoxserver.wrapper.EzyAppUserManager) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext)

Example 79 with EzyServerContext

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);
    }
}
Also used : EzySession(com.tvd12.ezyfoxserver.entity.EzySession)

Example 80 with EzyServerContext

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;
}
Also used : EzyInitable(com.tvd12.ezyfox.util.EzyInitable) EzyZoneContext(com.tvd12.ezyfoxserver.context.EzyZoneContext) EzySimpleServer(com.tvd12.ezyfoxserver.EzySimpleServer) EzyServerContext(com.tvd12.ezyfoxserver.context.EzyServerContext) EzySimpleServerContext(com.tvd12.ezyfoxserver.context.EzySimpleServerContext) EzyAppContext(com.tvd12.ezyfoxserver.context.EzyAppContext) EzyResponseApi(com.tvd12.ezyfoxserver.api.EzyResponseApi)

Aggregations

EzyServerContext (com.tvd12.ezyfoxserver.context.EzyServerContext)72 Test (org.testng.annotations.Test)67 EzyZoneContext (com.tvd12.ezyfoxserver.context.EzyZoneContext)46 EzyAbstractSession (com.tvd12.ezyfoxserver.entity.EzyAbstractSession)25 EzySession (com.tvd12.ezyfoxserver.entity.EzySession)25 BaseTest (com.tvd12.test.base.BaseTest)23 EzySessionManager (com.tvd12.ezyfoxserver.wrapper.EzySessionManager)22 EzyZoneUserManager (com.tvd12.ezyfoxserver.wrapper.EzyZoneUserManager)21 EzySimpleServer (com.tvd12.ezyfoxserver.EzySimpleServer)20 EzyServer (com.tvd12.ezyfoxserver.EzyServer)17 EzySettings (com.tvd12.ezyfoxserver.setting.EzySettings)16 EzyArray (com.tvd12.ezyfox.entity.EzyArray)14 EzyAppContext (com.tvd12.ezyfoxserver.context.EzyAppContext)14 EzyResponse (com.tvd12.ezyfoxserver.response.EzyResponse)13 BaseCoreTest (com.tvd12.ezyfoxserver.testing.BaseCoreTest)13 EzySimpleZone (com.tvd12.ezyfoxserver.EzySimpleZone)12 EzyChannel (com.tvd12.ezyfoxserver.socket.EzyChannel)12 EzyZone (com.tvd12.ezyfoxserver.EzyZone)11 EzyController (com.tvd12.ezyfoxserver.controller.EzyController)11 EzyLoggerSetting (com.tvd12.ezyfoxserver.setting.EzyLoggerSetting)11