Search in sources :

Example 21 with UserSession

use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.

the class UserSessionServiceBean method killSession.

@Override
public void killSession(UUID id) {
    UserSession userSession = userSessions.get(id);
    if (userSession != null && !userSession.isSystem()) {
        userSessionLog.updateSessionLogRecord(userSession, SessionAction.TERMINATION);
        userSessions.killSession(id);
    }
}
Also used : UserSession(com.haulmont.cuba.security.global.UserSession)

Example 22 with UserSession

use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.

the class UserSessionServiceBean method getMessages.

@Override
@Nullable
public String getMessages() {
    UserSession userSession = userSessionSource.getUserSession();
    try {
        Map<String, String> messages = new TreeMap<>();
        for (String name : userSession.getAttributeNames()) {
            if (name.startsWith(MESSAGE_ATTR_PREFIX)) {
                Object message = userSession.getAttribute(name);
                if (message instanceof String)
                    messages.put(name, (String) message);
            }
        }
        if (!messages.isEmpty()) {
            Datatype<Date> datatype = Datatypes.getNN(Date.class);
            StringBuilder sb = new StringBuilder();
            for (Map.Entry<String, String> entry : messages.entrySet()) {
                if (sb.length() != 0)
                    sb.append("\n\n");
                String name = entry.getKey();
                String dateTimeMillis = name.substring(MESSAGE_ATTR_PREFIX.length());
                Date dateTime = new Date(Long.parseLong(dateTimeMillis));
                sb.append(datatype.format(dateTime, userSession.getLocale())).append("\n");
                sb.append(entry.getValue());
                userSession.removeAttribute(name);
            }
            userSessions.propagate(userSession.getId());
            return sb.toString();
        }
    } catch (Throwable e) {
        log.warn("Error getting messages for session " + userSession, e);
    }
    return null;
}
Also used : UserSession(com.haulmont.cuba.security.global.UserSession) Nullable(javax.annotation.Nullable)

Example 23 with UserSession

use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.

the class UserSessionServiceBean method setSessionTimeZone.

@Override
public void setSessionTimeZone(UUID sessionId, TimeZone timeZone) {
    UserSession userSession = userSessions.getNN(sessionId);
    checkSession(userSession);
    userSession.setTimeZone(timeZone);
    userSessions.propagate(sessionId);
}
Also used : UserSession(com.haulmont.cuba.security.global.UserSession)

Example 24 with UserSession

use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.

the class UserSessionServiceBean method setSessionAddress.

@Override
public void setSessionAddress(UUID sessionId, String address) {
    UserSession userSession = userSessions.getNN(sessionId);
    checkSession(userSession);
    userSession.setAddress(address);
    userSessions.propagate(sessionId);
}
Also used : UserSession(com.haulmont.cuba.security.global.UserSession)

Example 25 with UserSession

use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.

the class AuthenticationServiceBean method logout.

@Override
public void logout() {
    try {
        UserSession session = userSessionSource.getUserSession();
        if (session != null && session.isSystem()) {
            throw new RuntimeException("Logout of system session from client is not permitted");
        }
        userSessionLog.updateSessionLogRecord(session, SessionAction.LOGOUT);
        authenticationManager.logout();
        userSessionLog.updateSessionLogRecord(session, SessionAction.LOGOUT);
    } catch (Throwable e) {
        log.error("Logout error", e);
        throw new RuntimeException("Logout error: " + e.toString());
    }
}
Also used : UserSession(com.haulmont.cuba.security.global.UserSession)

Aggregations

UserSession (com.haulmont.cuba.security.global.UserSession)127 SecurityContext (com.haulmont.cuba.core.sys.SecurityContext)29 LoginWorker (com.haulmont.cuba.security.app.LoginWorker)25 TestUserSessionSource (com.haulmont.cuba.testsupport.TestUserSessionSource)24 LoginException (com.haulmont.cuba.security.global.LoginException)23 Test (org.junit.Test)19 User (com.haulmont.cuba.security.entity.User)17 UUID (java.util.UUID)16 IOException (java.io.IOException)14 NoUserSessionException (com.haulmont.cuba.security.global.NoUserSessionException)12 ArrayList (java.util.ArrayList)11 Locale (java.util.Locale)11 List (java.util.List)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 FileStorageException (com.haulmont.cuba.core.global.FileStorageException)7 LogFileNotFoundException (com.haulmont.cuba.core.sys.logging.LogFileNotFoundException)6 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)5 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)4