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);
}
}
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;
}
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);
}
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);
}
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());
}
}
Aggregations