use of com.haulmont.cuba.core.sys.UserSessionFinder in project cuba by cuba-platform.
the class LogMdc method setup.
public static void setup(SecurityContext securityContext) {
String userProp = AppContext.getProperty("cuba.logUserName");
if (userProp == null || Boolean.valueOf(userProp)) {
if (securityContext != null) {
String user = securityContext.getUser();
if (user == null) {
UserSession session = securityContext.getSession();
if (session != null)
user = session.getUser().getLogin();
else if (securityContext.getSessionId() != null) {
ApplicationContext applicationContext = AppContext.getApplicationContext();
if (applicationContext.containsBean("cuba_UserSessions")) {
UserSessionFinder sessionFinder = (UserSessionFinder) applicationContext.getBean("cuba_UserSessions");
session = sessionFinder.get(securityContext.getSessionId());
if (session != null) {
user = session.getUser().getLogin();
}
}
}
}
if (user != null) {
MDC.put(USER, "/" + user);
}
} else {
MDC.remove(USER);
}
}
String applicationProp = AppContext.getProperty("cuba.logAppName");
if (applicationProp == null || Boolean.valueOf(applicationProp)) {
if (securityContext != null) {
MDC.put(APPLICATION, "/" + AppContext.getProperty("cuba.webContextName"));
} else {
MDC.remove(APPLICATION);
}
}
}
Aggregations