Search in sources :

Example 1 with WebAuthConfig

use of com.haulmont.cuba.web.auth.WebAuthConfig in project cuba by cuba-platform.

the class ControllerUtils method getUserSession.

public static UserSession getUserSession(HttpServletRequest req) {
    String s = req.getParameter("s");
    if (s != null) {
        try {
            UUID id = UUID.fromString(s);
            WebAuthConfig webAuthConfig = AppBeans.get(Configuration.class).getConfig(WebAuthConfig.class);
            TrustedClientService trustedClientService = AppBeans.get(TrustedClientService.NAME);
            UserSession session = trustedClientService.findSession(webAuthConfig.getTrustedClientPassword(), id);
            if (session != null) {
                req.getSession().setAttribute(App.USER_SESSION_ATTR, session);
                return session;
            } else {
                return null;
            }
        } catch (Exception e) {
            log.warn("Unable to get session from Login Service", e);
            return null;
        }
    } else {
        // noinspection UnnecessaryLocalVariable
        UserSession userSession = (UserSession) req.getSession().getAttribute(App.USER_SESSION_ATTR);
        return userSession;
    }
}
Also used : TrustedClientService(com.haulmont.cuba.security.app.TrustedClientService) Configuration(com.haulmont.cuba.core.global.Configuration) WebAuthConfig(com.haulmont.cuba.web.auth.WebAuthConfig) UserSession(com.haulmont.cuba.security.global.UserSession) UUID(java.util.UUID) MalformedURLException(java.net.MalformedURLException)

Aggregations

Configuration (com.haulmont.cuba.core.global.Configuration)1 TrustedClientService (com.haulmont.cuba.security.app.TrustedClientService)1 UserSession (com.haulmont.cuba.security.global.UserSession)1 WebAuthConfig (com.haulmont.cuba.web.auth.WebAuthConfig)1 MalformedURLException (java.net.MalformedURLException)1 UUID (java.util.UUID)1