Search in sources :

Example 91 with UserSession

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

the class DataManagerCommitConstraintTest method testDeleteConstraintPassed.

@Test
public void testDeleteConstraintPassed() throws LoginException {
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    DataManager dataManager = AppBeans.get(DataManager.NAME);
    UserSession userSession = lw.login("constraintuserupdate", passwordEncryption.getPlainHash(PASSWORD), Locale.getDefault());
    assertNotNull(userSession);
    UserSessionSource uss = AppBeans.get(UserSessionSource.class);
    UserSession savedUserSession = uss.getUserSession();
    ((TestUserSessionSource) uss).setUserSession(userSession);
    try {
        dataManager = dataManager.secure();
        User user = dataManager.load(new LoadContext<>(User.class).setId(testUserDelete2.getId()).setView(View.LOCAL));
        dataManager.remove(user);
        user = dataManager.load(new LoadContext<>(User.class).setId(testUserDelete2.getId()).setView(View.LOCAL));
        assertNull(user);
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) Test(org.junit.Test)

Example 92 with UserSession

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

the class DistinctConstraintTest method test.

@Test
public void test() throws LoginException {
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    UserSession userSession = lw.login(USER_LOGIN, passwordEncryption.getPlainHash(USER_PASSW), Locale.getDefault());
    assertNotNull(userSession);
    UserSessionSource uss = AppBeans.get(UserSessionSource.class);
    UserSession savedUserSession = uss.getUserSession();
    ((TestUserSessionSource) uss).setUserSession(userSession);
    try {
        DataManager dm = AppBeans.get(DataManager.NAME);
        LoadContext<User> loadContext = new LoadContext<>(User.class).setId(user2Id).setView(View.LOCAL);
        User user = dm.load(loadContext);
        assertNotNull(user);
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) Test(org.junit.Test)

Example 93 with UserSession

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

the class InMemoryConstraintTest method testConstraintByAttributeNotInView.

@Test
public void testConstraintByAttributeNotInView() throws LoginException {
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    UserSession userSession = lw.login("constraintUser4", passwordEncryption.getPlainHash(PASSWORD), Locale.getDefault());
    assertNotNull(userSession);
    UserSessionSource uss = AppBeans.get(UserSessionSource.class);
    UserSession savedUserSession = uss.getUserSession();
    ((TestUserSessionSource) uss).setUserSession(userSession);
    try {
        DataManager dataManager = AppBeans.get(DataManager.NAME);
        dataManager = dataManager.secure();
        LoadContext loadContext = new LoadContext(User.class).setView(View.MINIMAL);
        loadContext.setQuery(new LoadContext.Query("select u from sec$User u where u.login = 'constraintUser4' order by u.login desc"));
        loadContext.getQuery().setMaxResults(30);
        loadContext.getQuery().setFirstResult(0);
        List<User> resultList = dataManager.loadList(loadContext);
        assertEquals(1, resultList.size());
        assertEquals("constraintUser4", resultList.get(0).getLogin());
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession)

Example 94 with UserSession

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

the class InMemoryConstraintTest method testConstraintsOnMiddlePage.

@Test
public void testConstraintsOnMiddlePage() throws LoginException {
    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 dataManager = AppBeans.get(DataManager.NAME);
        dataManager = dataManager.secure();
        LoadContext loadContext = new LoadContext(User.class).setView(View.LOCAL);
        loadContext.setQuery(new LoadContext.Query("select u from sec$User u where (u.login like 'user%' or u.login like 'constraintUser%') order by u.login asc"));
        loadContext.getQuery().setMaxResults(30);
        loadContext.getQuery().setFirstResult(0);
        List resultList = dataManager.loadList(loadContext);
        assertEquals(11, resultList.size());
        assertEquals(11, dataManager.getCount(loadContext));
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) ArrayList(java.util.ArrayList) List(java.util.List)

Example 95 with UserSession

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

the class InMemoryConstraintTest method testConstraintsOnMoreThanOnePage.

@Test
public void testConstraintsOnMoreThanOnePage() throws LoginException {
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    UserSession userSession = lw.login("constraintUser3", passwordEncryption.getPlainHash(PASSWORD), Locale.getDefault());
    assertNotNull(userSession);
    UserSessionSource uss = AppBeans.get(UserSessionSource.class);
    UserSession savedUserSession = uss.getUserSession();
    ((TestUserSessionSource) uss).setUserSession(userSession);
    try {
        DataManager dataManager = AppBeans.get(DataManager.NAME);
        dataManager = dataManager.secure();
        LoadContext loadContext = new LoadContext(User.class).setView(View.LOCAL);
        loadContext.setQuery(new LoadContext.Query("select u from sec$User u where (u.login like 'user%' or u.login like 'constraintUser%') order by u.login desc"));
        loadContext.getQuery().setMaxResults(30);
        loadContext.getQuery().setFirstResult(0);
        List resultList = dataManager.loadList(loadContext);
        assertEquals(30, resultList.size());
        assertEquals(38, dataManager.getCount(loadContext));
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) ArrayList(java.util.ArrayList) List(java.util.List)

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