use of org.pentaho.platform.api.engine.IUserRoleListService in project pentaho-platform by pentaho.
the class SystemService method getRoles.
/**
* Returns XML for list of roles.
*/
public Document getRoles() throws ServletException, IOException {
IUserRoleListService service = PentahoSystem.get(IUserRoleListService.class);
// $NON-NLS-1$
Element rootElement = new DefaultElement("roles");
Document doc = DocumentHelper.createDocument(rootElement);
if (service != null) {
List<String> roles = service.getAllRoles();
for (Iterator<String> rolesIterator = roles.iterator(); rolesIterator.hasNext(); ) {
String roleName = rolesIterator.next().toString();
if ((null != roleName) && (roleName.length() > 0)) {
// $NON-NLS-1$
rootElement.addElement("role").setText(roleName);
}
}
}
return doc;
}
use of org.pentaho.platform.api.engine.IUserRoleListService in project pentaho-platform by pentaho.
the class SystemService method getUsers.
/**
* Returns XML for list of users in the platform.
*/
public Document getUsers() throws ServletException, IOException, IllegalAccessException {
if (!canAdminister()) {
throw new IllegalAccessException();
}
IUserRoleListService service = PentahoSystem.get(IUserRoleListService.class);
// $NON-NLS-1$
Element rootElement = new DefaultElement("users");
Document doc = DocumentHelper.createDocument(rootElement);
if (service != null) {
List<String> users = service.getAllUsers();
for (Iterator<String> usersIterator = users.iterator(); usersIterator.hasNext(); ) {
String username = usersIterator.next().toString();
if ((null != username) && (username.length() > 0)) {
// $NON-NLS-1$
rootElement.addElement("user").setText(username);
}
}
}
return doc;
}
use of org.pentaho.platform.api.engine.IUserRoleListService in project pentaho-platform by pentaho.
the class UserRoleListService method getPermissionRoles.
public RoleListWrapper getPermissionRoles(String adminRole) {
IUserRoleListService userRoleListService = getUserRoleListService();
List<String> allRoles = userRoleListService.getAllRoles();
// We will not allow user to update permission for Administrator
if (allRoles.contains(adminRole)) {
allRoles.remove(adminRole);
}
// Add extra roles to the list of roles
if (extraRoles != null) {
for (String extraRole : extraRoles) {
if (!allRoles.contains(extraRole)) {
allRoles.add(extraRole);
}
}
}
if (null != roleComparator) {
Collections.sort(allRoles, roleComparator);
}
return new RoleListWrapper(allRoles);
}
use of org.pentaho.platform.api.engine.IUserRoleListService in project pentaho-platform by pentaho.
the class HttpWebService method getRoles.
/**
* Returns XML for list of roles.
*/
protected Document getRoles() throws ServletException, IOException {
IUserRoleListService service = PentahoSystem.get(IUserRoleListService.class);
Element rootElement = new DefaultElement("roles");
Document doc = DocumentHelper.createDocument(rootElement);
if (service != null) {
List roles = service.getAllRoles();
for (Iterator rolesIterator = roles.iterator(); rolesIterator.hasNext(); ) {
String roleName = rolesIterator.next().toString();
if ((null != roleName) && (roleName.length() > 0)) {
rootElement.addElement("role").addCDATA(roleName);
}
}
}
return doc;
}
use of org.pentaho.platform.api.engine.IUserRoleListService 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());
}
Aggregations