Search in sources :

Example 1 with UIEESecurityUser

use of org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIEESecurityUser in project pentaho-kettle by pentaho.

the class UIEESecurityUserTest method testAddUser.

@Test
public void testAddUser() throws Exception {
    try {
        UIEESecurityUser user = new UIEESecurityUser(sm);
        List<IUIRole> rroles = new ArrayList<IUIRole>();
        for (IRole EERoleInfo : roles) {
            rroles.add(new UIRepositoryRole(EERoleInfo));
        }
        user.clear();
        user.setAvailableRoles(rroles);
        user.setMode(Mode.ADD);
        user.setName("newuser");
        user.setPassword("newpassword");
        user.setDescription("new description");
        List<Object> rolesToAssign = new ArrayList<Object>();
        rolesToAssign.add(new UIRepositoryRole(ctoRole));
        rolesToAssign.add(new UIRepositoryRole(isRole));
        rolesToAssign.add(new UIRepositoryRole(adminRole));
        rolesToAssign.add(new UIRepositoryRole(authenticatedRole));
        user.assignRoles(rolesToAssign);
        assertEquals(user.getMode(), Mode.ADD);
        // $NON-NLS-1$
        assertEquals(user.getName(), "newuser");
        // $NON-NLS-1$
        assertEquals(user.getPassword(), "newpassword");
        // $NON-NLS-1$
        assertEquals(user.getDescription(), "new description");
        Assert.assertTrue(contains(user.getAssignedRoles(), new UIRepositoryRole(adminRole)));
        Assert.assertTrue(contains(user.getAssignedRoles(), new UIRepositoryRole(authenticatedRole)));
        Assert.assertTrue(contains(user.getAssignedRoles(), new UIRepositoryRole(ctoRole)));
        Assert.assertTrue(contains(user.getAssignedRoles(), new UIRepositoryRole(isRole)));
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : IUIRole(org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIRole) IRole(org.pentaho.di.repository.pur.model.IRole) UIRepositoryRole(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryRole) ArrayList(java.util.ArrayList) IUIRole(org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIRole) UIEESecurityUser(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIEESecurityUser) Test(org.junit.Test)

Example 2 with UIEESecurityUser

use of org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIEESecurityUser in project pentaho-kettle by pentaho.

the class UIEESecurityUserTest method testEditUser.

@Test
public void testEditUser() throws Exception {
    try {
        UIEESecurityUser user = new UIEESecurityUser(sm);
        List<IUIRole> rroles = new ArrayList<IUIRole>();
        for (IRole EERoleInfo : roles) {
            rroles.add(new UIRepositoryRole(EERoleInfo));
        }
        user.setUser(new UIRepositoryUser(joeUser), rroles);
        user.setMode(Mode.EDIT);
        user.setPassword("newpassword");
        user.setDescription("new description");
        List<Object> rolesToAssign1 = new ArrayList<Object>();
        rolesToAssign1.add(new UIRepositoryRole(adminRole));
        rolesToAssign1.add(new UIRepositoryRole(authenticatedRole));
        user.assignRoles(rolesToAssign1);
        List<Object> rolesToAssign = new ArrayList<Object>();
        rolesToAssign.add(new UIRepositoryRole(ctoRole));
        rolesToAssign.add(new UIRepositoryRole(isRole));
        List<Object> rolesToUnAssign = new ArrayList<Object>();
        rolesToUnAssign.add(new UIRepositoryRole(adminRole));
        rolesToUnAssign.add(new UIRepositoryRole(authenticatedRole));
        user.assignRoles(rolesToAssign);
        user.unassignRoles(rolesToUnAssign);
        // Should have exactly 7 roles
        assertEquals(user.getMode(), Mode.EDIT);
        // $NON-NLS-1$
        assertEquals(user.getPassword(), "newpassword");
        // $NON-NLS-1$
        assertEquals(user.getDescription(), "new description");
        Assert.assertFalse(contains(user.getAssignedRoles(), new UIRepositoryRole(adminRole)));
        Assert.assertFalse(contains(user.getAssignedRoles(), new UIRepositoryRole(authenticatedRole)));
        Assert.assertTrue(contains(user.getAssignedRoles(), new UIRepositoryRole(ctoRole)));
        Assert.assertTrue(contains(user.getAssignedRoles(), new UIRepositoryRole(isRole)));
    } catch (Exception e) {
        Assert.fail();
    }
}
Also used : IUIRole(org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIRole) IRole(org.pentaho.di.repository.pur.model.IRole) UIRepositoryRole(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryRole) ArrayList(java.util.ArrayList) UIRepositoryUser(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryUser) IUIRole(org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIRole) UIEESecurityUser(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIEESecurityUser) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 IRole (org.pentaho.di.repository.pur.model.IRole)2 IUIRole (org.pentaho.di.ui.repository.pur.repositoryexplorer.IUIRole)2 UIEESecurityUser (org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIEESecurityUser)2 UIRepositoryRole (org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIRepositoryRole)2 UIRepositoryUser (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryUser)1