use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class ParentClassConstraintTest method testConstraintsOnParentClass.
@Test
public void testConstraintsOnParentClass() throws LoginException {
DataManager dataManager = AppBeans.get(DataManager.NAME);
LoadContext<SearchFolder> loadContext = new LoadContext<>(SearchFolder.class).setView(View.LOCAL);
loadContext.setQueryString("select f from sec$SearchFolder f");
List resultList = dataManager.loadList(loadContext);
assertEquals(2, resultList.size());
LoginWorker lw = AppBeans.get(LoginWorker.NAME);
UserSession userSession = lw.login("constraintUser1", passwordEncryption.getPlainHash(PASSWORD), Locale.getDefault());
assertNotNull(userSession);
UserSessionSource uss = AppBeans.get(UserSessionSource.class);
UserSession savedUserSession = uss.getUserSession();
((TestUserSessionSource) uss).setUserSession(userSession);
try {
dataManager = AppBeans.get(DataManager.NAME);
dataManager = dataManager.secure();
loadContext = new LoadContext<>(SearchFolder.class).setView(View.LOCAL);
loadContext.setQueryString("select f from sec$SearchFolder f");
resultList = dataManager.loadList(loadContext);
assertEquals(1, resultList.size());
} finally {
((TestUserSessionSource) uss).setUserSession(savedUserSession);
}
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class ExecutionsImpl method cancelExecution.
public void cancelExecution(UUID userSessionId, String group, String key) {
UserSession userSession = userSessionsAPI.getAndRefresh(userSessionId, false);
if (userSession == null) {
log.warn("User session {} not found, execution context: group={}, key={}", userSessionId, group, key);
throw new IllegalStateException(String.format("User session {%s} not found", userSessionId));
}
log.debug("Try to cancel resources for execution context: group={}, key={} and user session {}", group, key, userSessionId);
cancelLocally(userSession, group, key);
if (clusterManager.isStarted()) {
log.debug("Send cancel message in cluster for execution context: group={}, key={}", group, key);
clusterManager.send(new CancelExecutionMessage(userSessionId, group, key));
}
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class QueryResultsManager method deleteForInactiveSessions.
@Override
public void deleteForInactiveSessions() {
if (!AppContext.isStarted() || !clusterManager.isMaster() || !configuration.getConfig(GlobalConfig.class).getAllowQueryFromSelected())
return;
log.debug("Delete query results for inactive user sessions");
StringBuilder sb = new StringBuilder("delete from SYS_QUERY_RESULT");
Collection<UserSession> userSessionEntities = userSessions.getUserSessionsStream().collect(Collectors.toList());
DbTypeConverter converter = persistence.getDbTypeConverter();
if (!userSessionEntities.isEmpty()) {
sb.append(" where SESSION_ID not in (");
for (Iterator<UserSession> it = userSessionEntities.iterator(); it.hasNext(); ) {
UserSession userSession = it.next();
UUID userSessionId = userSession.getId();
String userSessionIdStr = converter.getSqlObject(userSessionId).toString();
sb.append("'").append(userSessionIdStr).append("'");
if (it.hasNext())
sb.append(",");
}
sb.append(")");
}
QueryRunner runner = new QueryRunner(persistence.getDataSource());
try {
runner.update(sb.toString());
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class AppLoginWindow method setRememberMeCookies.
protected void setRememberMeCookies() {
if (connection.isAuthenticated()) {
if (webConfig.getRememberMeEnabled()) {
if (Boolean.TRUE.equals(rememberMeCheckBox.getValue())) {
if (!loginByRememberMe) {
app.addCookie(COOKIE_REMEMBER_ME, Boolean.TRUE.toString());
String login = loginField.getValue();
String encodedLogin = URLEncodeUtils.encodeUtf8(login);
app.addCookie(COOKIE_LOGIN, StringEscapeUtils.escapeJava(encodedLogin));
UserSession session = connection.getSession();
if (session == null) {
throw new IllegalStateException("Unable to get session after login");
}
User user = session.getUser();
String rememberMeToken = userManagementService.generateRememberMeToken(user.getId());
app.addCookie(COOKIE_PASSWORD, rememberMeToken);
}
} else {
app.removeCookie(COOKIE_REMEMBER_ME);
app.removeCookie(COOKIE_LOGIN);
app.removeCookie(COOKIE_PASSWORD);
}
}
}
}
use of com.haulmont.cuba.security.global.UserSession in project cuba by cuba-platform.
the class ScreenHistoryDatasource method loadData.
@Override
protected void loadData(Map<String, Object> params) {
UserSession userSession = AppBeans.get(UserSessionSource.class).getUserSession();
User user;
if (userSession.getSubstitutedUser() != null) {
user = userSession.getSubstitutedUser();
} else {
user = userSession.getUser();
}
Map<String, Object> modifiedParams = new HashMap<>();
modifiedParams.putAll(params);
modifiedParams.put("userId", user);
super.loadData(modifiedParams);
}
Aggregations