// XMLUserGroupService.DEFAULT_NAME);
// GeoserverRoleService roleService = createRoleService(
// XMLRoleService.DEFAULT_NAME);
// getSecurityManager().setActiveRoleService(roleService);
// getSecurityManager().setActiveUserGroupService(userService);
GeoServerUserGroupService userService = getSecurityManager().loadUserGroupService(XMLUserGroupService.DEFAULT_NAME);
GeoServerRoleService roleService =getSecurityManager().loadRoleService(XMLRoleService.DEFAULT_NAME);
assertEquals(3,userService.getUsers().size());
assertEquals(3,userService.getUserCount());
assertEquals(0,userService.getUserGroups().size());
assertEquals(0,userService.getGroupCount());
assertEquals(9,roleService.getRoles().size());
GeoServerUser admin = (GeoServerUser) userService.loadUserByUsername("admin");
assertNotNull(admin);
GeoServerMultiplexingPasswordEncoder enc= getEncoder(userService);
assertTrue(enc.isPasswordValid(admin.getPassword(), "gs", null));
assertTrue(admin.isEnabled());
GeoServerUser wfs = (GeoServerUser) userService.loadUserByUsername("wfs");
assertNotNull(wfs);
assertTrue(enc.isPasswordValid(wfs.getPassword(), "webFeatureService", null));
assertTrue(wfs.isEnabled());
GeoServerUser disabledUser = (GeoServerUser) userService.loadUserByUsername("disabledUser");
assertNotNull(disabledUser);
assertTrue(enc.isPasswordValid(disabledUser.getPassword(), "nah", null));
assertFalse(disabledUser.isEnabled());
GeoServerRole role_admin = roleService.getRoleByName(XMLRoleService.DEFAULT_LOCAL_ADMIN_ROLE);
assertNotNull(role_admin);
GeoServerRole role_wfs_read = roleService.getRoleByName("ROLE_WFS_READ");
assertNotNull(role_wfs_read);
GeoServerRole role_wfs_write = roleService.getRoleByName("ROLE_WFS_WRITE");
assertNotNull(role_wfs_write);
GeoServerRole role_test = roleService.getRoleByName("ROLE_TEST");
assertNotNull(role_test);
assertNotNull(roleService.getRoleByName("NO_ONE"));
assertNotNull(roleService.getRoleByName("TRUSTED_ROLE"));
assertNotNull(roleService.getRoleByName("ROLE_SERVICE_1"));
assertNotNull(roleService.getRoleByName("ROLE_SERVICE_2"));
assertEquals(2,admin.getAuthorities().size());
assertTrue(admin.getAuthorities().contains(role_admin));
assertTrue(admin.getAuthorities().contains(GeoServerRole.ADMIN_ROLE));
assertEquals(2,wfs.getAuthorities().size());
assertTrue(wfs.getAuthorities().contains(role_wfs_read));
assertTrue(wfs.getAuthorities().contains(role_wfs_write));
assertEquals(1,disabledUser.getAuthorities().size());
assertTrue(disabledUser.getAuthorities().contains(role_test));
GeoServerSecurityManager securityManager = getSecurityManager();
File userfile = new File(securityManager.getSecurityRoot(),"users.properties");
assertFalse(userfile.exists());
File userfileOld = new File(securityManager.getSecurityRoot(),"users.properties.old");
assertTrue(userfileOld.exists());
File roleXSD = new File(new File(securityManager.getRoleRoot(), roleService.getName()),
XMLConstants.FILE_RR_SCHEMA);
assertTrue(roleXSD.exists());
File userXSD = new File (new File(securityManager.getUserGroupRoot(), userService.getName()),
XMLConstants.FILE_UR_SCHEMA);
assertTrue(userXSD.exists());
/* does not work from the command line
*