Search in sources :

Example 6 with TestUserSessionSource

use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.

the class NonEntityQueryTest method testInMemoryAndSeveralConstraints.

@Test
public void testInMemoryAndSeveralConstraints() throws Exception {
    ConfigStorageService configStorageService = AppBeans.get(ConfigStorageService.class);
    configStorageService.setDbProperty("cuba.disableLoadValuesIfConstraints", "false");
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    UserSession userSession = lw.login(USER_NAME_2, passwordEncryption.getPlainHash(USER_PASSWORD), Locale.getDefault());
    assertNotNull(userSession);
    UserSessionSource uss = AppBeans.get(UserSessionSource.class);
    UserSession savedUserSession = uss.getUserSession();
    ((TestUserSessionSource) uss).setUserSession(userSession);
    try {
        ValueLoadContext context = ValueLoadContext.create();
        context.setQueryString("select s.viewXml from sys$EntitySnapshot s");
        context.addProperty("viewXml");
        List<KeyValueEntity> list = dataManager.secure().loadValues(context);
        assertEquals(1, list.size());
        context = ValueLoadContext.create();
        context.setQueryString("select s.name, sn.viewXml from sys$Server s, sys$EntitySnapshot sn");
        context.addProperty("name");
        context.addProperty("viewXml");
        list = dataManager.secure().loadValues(context);
        assertEquals(0, list.size());
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) ConfigStorageService(com.haulmont.cuba.core.app.ConfigStorageService) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) KeyValueEntity(com.haulmont.cuba.core.entity.KeyValueEntity) Test(org.junit.Test)

Example 7 with TestUserSessionSource

use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.

the class DataManagerCommitConstraintTest method testDeleteConstraintNotPassed.

@Test
public void testDeleteConstraintNotPassed() 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(testUserDelete1.getId()).setView(View.LOCAL));
        dataManager.remove(user);
        fail();
    } catch (RowLevelSecurityException e) {
        User user = dataManager.load(new LoadContext<>(User.class).setId(testUserDelete1.getId()).setView(View.LOCAL));
        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 8 with TestUserSessionSource

use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.

the class DataManagerCommitConstraintTest method testCreateConstraintNotPassed.

@Test
public void testCreateConstraintNotPassed() throws LoginException {
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    DataManager dataManager = AppBeans.get(DataManager.NAME);
    UserSession userSession = lw.login("constraintusercreate", 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(testUserUpdate1.getId()).setView(View.LOCAL));
        Role loadedRole = dataManager.load(new LoadContext<>(Role.class).setId(role.getId()).setView(View.MINIMAL));
        UserRole userRole = new UserRole();
        userRole.setUser(user);
        userRole.setRole(loadedRole);
        dataManager.commit(userRole);
        fail();
    } catch (RowLevelSecurityException e) {
    // Do nothing
    } 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 9 with TestUserSessionSource

use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.

the class DataManagerSecurityTest method test.

@Test
public void test() throws Exception {
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    UserSession userSession = lw.login(USER_NAME, 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<Server> loadContext = LoadContext.create(Server.class).setQuery(new LoadContext.Query("select s from sys$Server s"));
        List<Server> list = dm.loadList(loadContext);
        assertFalse("Permission took effect when calling DataManager inside middleware", list.isEmpty());
        DataService ds = AppBeans.get(DataService.NAME);
        loadContext = LoadContext.create(Server.class).setQuery(new LoadContext.Query("select s from sys$Server s"));
        list = ds.loadList(loadContext);
        assertTrue("Permission did not take effect when calling DataService", list.isEmpty());
    } finally {
        ((TestUserSessionSource) uss).setUserSession(savedUserSession);
    }
}
Also used : LoginWorker(com.haulmont.cuba.security.app.LoginWorker) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) Server(com.haulmont.cuba.core.entity.Server) TestUserSessionSource(com.haulmont.cuba.testsupport.TestUserSessionSource) UserSession(com.haulmont.cuba.security.global.UserSession) DataService(com.haulmont.cuba.core.app.DataService) Test(org.junit.Test)

Example 10 with TestUserSessionSource

use of com.haulmont.cuba.testsupport.TestUserSessionSource in project cuba by cuba-platform.

the class InMemoryConstraintTest method testConstraintsOnEnd.

@Test
public void testConstraintsOnEnd() throws LoginException {
    LoginWorker lw = AppBeans.get(LoginWorker.NAME);
    UserSession userSession = lw.login("constraintUser2", 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(9, resultList.size());
        assertEquals(9, 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

TestUserSessionSource (com.haulmont.cuba.testsupport.TestUserSessionSource)24 LoginWorker (com.haulmont.cuba.security.app.LoginWorker)23 UserSession (com.haulmont.cuba.security.global.UserSession)23 Test (org.junit.Test)15 List (java.util.List)8 ArrayList (java.util.ArrayList)7 ConfigStorageService (com.haulmont.cuba.core.app.ConfigStorageService)4 KeyValueEntity (com.haulmont.cuba.core.entity.KeyValueEntity)3 Server (com.haulmont.cuba.core.entity.Server)2 DataService (com.haulmont.cuba.core.app.DataService)1 Executions (com.haulmont.cuba.core.app.execution.Executions)1 UserSessionSource (com.haulmont.cuba.core.global.UserSessionSource)1 ConstraintData (com.haulmont.cuba.security.global.ConstraintData)1