Search in sources :

Example 6 with UserExport

use of org.pentaho.platform.plugin.services.importexport.UserExport in project pentaho-platform by pentaho.

the class SolutionImportHandlerTest method testImportUsers_oneUserManyRoles.

@Test
public void testImportUsers_oneUserManyRoles() throws Exception {
    List<UserExport> users = new ArrayList<>();
    UserExport user = new UserExport();
    user.setUsername("scrum master");
    user.setRole("coder");
    user.setRole("product owner");
    user.setRole("cat herder");
    user.setPassword("password");
    users.add(user);
    Map<String, List<String>> rolesToUsers = importHandler.importUsers(users);
    Assert.assertEquals(3, rolesToUsers.size());
    Assert.assertEquals("scrum master", rolesToUsers.get("coder").get(0));
    Assert.assertEquals("scrum master", rolesToUsers.get("product owner").get(0));
    Assert.assertEquals("scrum master", rolesToUsers.get("cat herder").get(0));
    String[] strings = {};
    Mockito.verify(userRoleDao).createUser(Mockito.any(ITenant.class), Mockito.eq("scrum master"), Mockito.anyString(), Mockito.anyString(), Mockito.any(strings.getClass()));
    // should not set the password or roles explicitly if the createUser worked
    Mockito.verify(userRoleDao, Mockito.never()).setUserRoles(Mockito.any(ITenant.class), Mockito.anyString(), Mockito.any(strings.getClass()));
    Mockito.verify(userRoleDao, Mockito.never()).setPassword(Mockito.any(ITenant.class), Mockito.anyString(), Mockito.anyString());
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) UserExport(org.pentaho.platform.plugin.services.importexport.UserExport) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 7 with UserExport

use of org.pentaho.platform.plugin.services.importexport.UserExport in project pentaho-platform by pentaho.

the class PentahoPlatformExporterTest method testExportUsersAndRoles.

@Test
public void testExportUsersAndRoles() {
    IUserRoleListService mockDao = mock(IUserRoleListService.class);
    IAnyUserSettingService userSettingService = mock(IAnyUserSettingService.class);
    UserDetailsService userDetailsService = mock(UserDetailsService.class);
    PentahoSystem.registerObject(mockDao);
    PentahoSystem.registerObject(userSettingService);
    PentahoSystem.registerObject(userDetailsService);
    IRoleAuthorizationPolicyRoleBindingDao roleBindingDao = mock(IRoleAuthorizationPolicyRoleBindingDao.class);
    PentahoSystem.registerObject(roleBindingDao);
    String tenantPath = "path";
    when(session.getAttribute(IPentahoSession.TENANT_ID_KEY)).thenReturn(tenantPath);
    List<String> userList = new ArrayList<String>();
    String user = "testUser";
    String role = "testRole";
    userList.add(user);
    when(mockDao.getAllUsers(any(ITenant.class))).thenReturn(userList);
    List<String> roleList = new ArrayList<String>();
    roleList.add(role);
    when(mockDao.getAllRoles()).thenReturn(roleList);
    Map<String, List<String>> map = new HashMap<String, List<String>>();
    List<String> permissions = new ArrayList<String>();
    permissions.add("read");
    map.put("testRole", permissions);
    RoleBindingStruct struct = mock(RoleBindingStruct.class);
    struct.bindingMap = map;
    when(roleBindingDao.getRoleBindingStruct(anyString())).thenReturn(struct);
    ArgumentCaptor<UserExport> userCaptor = ArgumentCaptor.forClass(UserExport.class);
    ArgumentCaptor<RoleExport> roleCaptor = ArgumentCaptor.forClass(RoleExport.class);
    ExportManifest manifest = mock(ExportManifest.class);
    exporter.setExportManifest(manifest);
    List<IUserSetting> settings = new ArrayList<>();
    IUserSetting setting = mock(IUserSetting.class);
    settings.add(setting);
    when(userSettingService.getUserSettings(user)).thenReturn(settings);
    when(userSettingService.getGlobalUserSettings()).thenReturn(settings);
    List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>();
    UserDetails userDetails = new User("testUser", "testPassword", true, true, true, true, authList);
    when(userDetailsService.loadUserByUsername(anyString())).thenReturn(userDetails);
    exporter.exportUsersAndRoles();
    verify(manifest).addUserExport(userCaptor.capture());
    verify(manifest).addRoleExport(roleCaptor.capture());
    verify(userSettingService).getGlobalUserSettings();
    verify(manifest).addGlobalUserSetting(any(ExportManifestUserSetting.class));
    assertEquals(settings.size(), userCaptor.getValue().getUserSettings().size());
    UserExport userExport = userCaptor.getValue();
    assertEquals("testUser", userExport.getUsername());
    RoleExport roleExport = roleCaptor.getValue();
    assertEquals("testRole", roleExport.getRolename());
}
Also used : IRoleAuthorizationPolicyRoleBindingDao(org.pentaho.platform.security.policy.rolebased.IRoleAuthorizationPolicyRoleBindingDao) User(org.springframework.security.core.userdetails.User) HashMap(java.util.HashMap) RoleBindingStruct(org.pentaho.platform.security.policy.rolebased.RoleBindingStruct) GrantedAuthority(org.springframework.security.core.GrantedAuthority) ArrayList(java.util.ArrayList) ExportManifestUserSetting(org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting) Mockito.anyString(org.mockito.Mockito.anyString) ExportManifest(org.pentaho.platform.plugin.services.importexport.exportManifest.ExportManifest) IUserSetting(org.pentaho.platform.api.usersettings.pojo.IUserSetting) IAnyUserSettingService(org.pentaho.platform.api.usersettings.IAnyUserSettingService) ITenant(org.pentaho.platform.api.mt.ITenant) UserDetails(org.springframework.security.core.userdetails.UserDetails) UserExport(org.pentaho.platform.plugin.services.importexport.UserExport) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) List(java.util.List) ArrayList(java.util.ArrayList) IUserRoleListService(org.pentaho.platform.api.engine.IUserRoleListService) RoleExport(org.pentaho.platform.plugin.services.importexport.RoleExport) Test(org.junit.Test)

Example 8 with UserExport

use of org.pentaho.platform.plugin.services.importexport.UserExport in project pentaho-platform by pentaho.

the class SolutionImportHandlerTest method testImportUsers_userAlreadyExists_overwriteFalse.

@Test
public void testImportUsers_userAlreadyExists_overwriteFalse() throws Exception {
    List<UserExport> users = new ArrayList<>();
    UserExport user = new UserExport();
    user.setUsername("scrum master");
    user.setRole("coder");
    user.setPassword("password");
    users.add(user);
    String[] strings = {};
    Mockito.when(userRoleDao.createUser(Mockito.any(ITenant.class), Mockito.eq("scrum master"), Mockito.anyString(), Mockito.anyString(), Mockito.any(strings.getClass()))).thenThrow(new AlreadyExistsException("already there"));
    importHandler.setOverwriteFile(false);
    Map<String, List<String>> rolesToUsers = importHandler.importUsers(users);
    Assert.assertEquals(1, rolesToUsers.size());
    Assert.assertEquals("scrum master", rolesToUsers.get("coder").get(0));
    Mockito.verify(userRoleDao).createUser(Mockito.any(ITenant.class), Mockito.eq("scrum master"), Mockito.anyString(), Mockito.anyString(), Mockito.any(strings.getClass()));
    // should set the password or roles explicitly if the createUser failed
    Mockito.verify(userRoleDao, Mockito.never()).setUserRoles(Mockito.any(ITenant.class), Mockito.anyString(), Mockito.any(strings.getClass()));
    Mockito.verify(userRoleDao, Mockito.never()).setPassword(Mockito.any(ITenant.class), Mockito.anyString(), Mockito.anyString());
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) UserExport(org.pentaho.platform.plugin.services.importexport.UserExport) AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 9 with UserExport

use of org.pentaho.platform.plugin.services.importexport.UserExport in project pentaho-platform by pentaho.

the class SolutionImportHandlerTest method testImportUsers_manyUserManyRoles.

@Test
public void testImportUsers_manyUserManyRoles() throws Exception {
    List<UserExport> users = new ArrayList<>();
    UserExport user = new UserExport();
    user.setUsername("scrum master");
    user.setRole("coder");
    user.setRole("product owner");
    user.setRole("cat herder");
    user.setPassword("password");
    users.add(user);
    UserExport user2 = new UserExport();
    user2.setUsername("the dude");
    user2.setRole("coder");
    user2.setRole("awesome");
    user2.setPassword("password");
    users.add(user2);
    Map<String, List<String>> rolesToUsers = importHandler.importUsers(users);
    Assert.assertEquals(4, rolesToUsers.size());
    Assert.assertEquals(2, rolesToUsers.get("coder").size());
    Assert.assertEquals(1, rolesToUsers.get("product owner").size());
    Assert.assertEquals("scrum master", rolesToUsers.get("product owner").get(0));
    Assert.assertEquals(1, rolesToUsers.get("cat herder").size());
    Assert.assertEquals("scrum master", rolesToUsers.get("cat herder").get(0));
    Assert.assertEquals(1, rolesToUsers.get("awesome").size());
    Assert.assertEquals("the dude", rolesToUsers.get("awesome").get(0));
    String[] strings = {};
    Mockito.verify(userRoleDao).createUser(Mockito.any(ITenant.class), Mockito.eq("scrum master"), Mockito.anyString(), Mockito.anyString(), Mockito.any(strings.getClass()));
    Mockito.verify(userRoleDao).createUser(Mockito.any(ITenant.class), Mockito.eq("the dude"), Mockito.anyString(), Mockito.anyString(), Mockito.any(strings.getClass()));
    // should not set the password or roles explicitly if the createUser worked
    Mockito.verify(userRoleDao, Mockito.never()).setUserRoles(Mockito.any(ITenant.class), Mockito.anyString(), Mockito.any(strings.getClass()));
    Mockito.verify(userRoleDao, Mockito.never()).setPassword(Mockito.any(ITenant.class), Mockito.anyString(), Mockito.anyString());
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) UserExport(org.pentaho.platform.plugin.services.importexport.UserExport) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Aggregations

UserExport (org.pentaho.platform.plugin.services.importexport.UserExport)9 Test (org.junit.Test)7 ITenant (org.pentaho.platform.api.mt.ITenant)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 IAnyUserSettingService (org.pentaho.platform.api.usersettings.IAnyUserSettingService)4 ExportManifestUserSetting (org.pentaho.platform.plugin.services.importexport.ExportManifestUserSetting)4 AlreadyExistsException (org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException)3 IUserSetting (org.pentaho.platform.api.usersettings.pojo.IUserSetting)3 HashMap (java.util.HashMap)2 IUserRoleListService (org.pentaho.platform.api.engine.IUserRoleListService)2 RoleExport (org.pentaho.platform.plugin.services.importexport.RoleExport)2 IRoleAuthorizationPolicyRoleBindingDao (org.pentaho.platform.security.policy.rolebased.IRoleAuthorizationPolicyRoleBindingDao)2 UserDetailsService (org.springframework.security.core.userdetails.UserDetailsService)2 IOException (java.io.IOException)1 Mockito.anyString (org.mockito.Mockito.anyString)1 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)1 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)1 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)1 IUserRoleDao (org.pentaho.platform.api.engine.security.userroledao.IUserRoleDao)1