public GeoServerUserGroupStore createStore() throws IOException { return service.createStore(); }
List<String> calculateAdminGroups(UserDetails userDetails) throws IOException { if (userDetails instanceof GeoServerUser) { Properties props = ((GeoServerUser) userDetails).getProperties(); if (GroupAdminProperty.has(props)) { return Arrays.asList(GroupAdminProperty.get(props)); } } // fall back on including every group the user is part of List<String> groupNames = new ArrayList<String>(); for (GeoServerUserGroupService ugService : loadUserGroupServices()) { GeoServerUser user = ugService.getUserByUsername(userDetails.getUsername()); if (user != null) { for (GeoServerUserGroup group : ugService.getGroupsForUser(user)) { groupNames.add(group.getGroupname()); } } } return groupNames; }
protected void checkEmpty(GeoServerUserGroupService userService) throws IOException { assertEquals(0, userService.getUsers().size()); assertEquals(0, userService.getUserGroups().size()); assertEquals(0, userService.getUserCount()); assertEquals(0, userService.getGroupCount()); }
protected void checkValuesInserted(GeoServerUserGroupService userGroupService) throws IOException { assertEquals(5, userGroupService.getUsers().size()); assertEquals(5, userGroupService.getUserCount()); GeoServerUser admin = userGroupService.getUserByUsername(GeoServerUser.ADMIN_USERNAME); GeoServerUser user1 = userGroupService.getUserByUsername("user1"); GeoServerUser user2 = userGroupService.getUserByUsername("user2"); GeoServerUser disableduser = userGroupService.getUserByUsername("disableduser"); GeoServerUser groupAdminUser = userGroupService.getUserByUsername("groupAdminUser"); assertNull(userGroupService.getUserByUsername("xxx")); assertTrue(userGroupService.getUsers().contains(admin)); assertTrue(userGroupService.getUsers().contains(user1)); assertTrue(userGroupService.getUsers().contains(user2)); assertTrue(userGroupService.getUsers().contains(disableduser)); assertTrue(userGroupService.getUsers().contains(groupAdminUser)); for (GeoServerUser user : userGroupService.getUsers()) { if (user2.getUsername().equals(user.getUsername())) { assertEquals(2, user.getProperties().size()); assertEquals(4, userGroupService.getUserGroups().size()); assertEquals(4, userGroupService.getGroupCount()); GeoServerUserGroup admins = userGroupService.getGroupByGroupname("admins"); GeoServerUserGroup group1 = userGroupService.getGroupByGroupname("group1"); GeoServerUserGroup group2 = userGroupService.getGroupByGroupname("group2"); GeoServerUserGroup disabledgroup = userGroupService.getGroupByGroupname("disabledgroup");
protected void checkValuesRemoved(GeoServerUserGroupService userGroupService) throws IOException { GeoServerUser admin = GeoServerUser.createDefaultAdmin(); GeoServerUser user1 = userGroupService.getUserByUsername("user1"); GeoServerUser disableduser = userGroupService.getUserByUsername("disableduser"); GeoServerUser groupAdminUser = userGroupService.getUserByUsername("groupAdminUser"); assertEquals(4, userGroupService.getUsers().size()); assertEquals(4, userGroupService.getUserCount()); assertTrue(userGroupService.getUsers().contains(admin)); assertTrue(userGroupService.getUsers().contains(user1)); assertTrue(userGroupService.getUsers().contains(disableduser)); assertTrue(userGroupService.getUsers().contains(groupAdminUser)); GeoServerUserGroup admins = userGroupService.getGroupByGroupname("admins"); GeoServerUserGroup group1 = userGroupService.getGroupByGroupname("group1"); assertEquals(3, userGroupService.getUserGroups().size()); assertEquals(3, userGroupService.getGroupCount()); assertTrue(userGroupService.getUserGroups().contains(admins)); assertTrue(userGroupService.getUserGroups().contains(group1)); assertEquals(0, userGroupService.getGroupsForUser(disableduser).size()); assertEquals(1, userGroupService.getUsersForGroup(group1).size()); assertTrue(userGroupService.getUsersForGroup(group1).contains(user1)); assertEquals(0, userGroupService.getUsersHavingProperty("mail").size()); assertEquals(0, userGroupService.getUsersHavingPropertyValue("tel", "11-22-33").size()); }
protected void checkValuesModified(GeoServerUserGroupService userGroupService) throws IOException { GeoServerUser disableduser = userGroupService.getUserByUsername("disableduser"); assertTrue(disableduser.isEnabled()); GeoServerMultiplexingPasswordEncoder encoder = getEncoder(userGroupService); assertTrue(encoder.isPasswordValid(disableduser.getPassword(), "hallo", null)); assertEquals(1, disableduser.getProperties().size()); assertEquals("miller", disableduser.getProperties().getProperty("lastname")); GeoServerUser user2 = userGroupService.getUserByUsername("user2"); assertEquals(1, user2.getProperties().size()); assertEquals("11-22-33", user2.getProperties().getProperty("tel")); GeoServerUserGroup disabledgroup = userGroupService.getGroupByGroupname("disabledgroup"); assertTrue(disabledgroup.isEnabled()); GeoServerUserGroup group1 = userGroupService.getGroupByGroupname("group1"); GeoServerUser user1 = userGroupService.getUserByUsername("user1"); assertEquals(1, userGroupService.getUsersForGroup(group1).size()); assertTrue(userGroupService.getUsersForGroup(group1).contains(user1)); assertEquals(0, userGroupService.getGroupsForUser(user2).size()); assertEquals(0, userGroupService.getUsersHavingProperty("mail").size()); assertEquals(0, userGroupService.getUsersHavingPropertyValue("tel", "12-34-38").size()); assertEquals(1, userGroupService.getUsersHavingPropertyValue("tel", "11-22-33").size()); user2 = userGroupService.getUsersHavingPropertyValue("tel", "11-22-33").first(); assertEquals("11-22-33", user2.getProperties().getProperty("tel")); }
@Test public void testDefault() throws Exception { GeoServerUserGroupService service = getSecurityManager().loadUserGroupService(XMLUserGroupService.DEFAULT_NAME); assertEquals(1, service.getUsers().size()); assertEquals(1, service.getUserCount()); assertEquals(0, service.getUserGroups().size()); assertEquals(0, service.getGroupCount()); GeoServerUser admin = service.getUserByUsername(GeoServerUser.ADMIN_USERNAME); assertNotNull(admin); assertEquals(GeoServerUser.AdminEnabled, admin.isEnabled()); GeoServerMultiplexingPasswordEncoder enc = getEncoder(service); assertTrue( enc.isPasswordValid(admin.getPassword(), GeoServerUser.DEFAULT_ADMIN_PASSWD, null)); assertEquals(admin.getProperties().size(), 0); assertEquals(0, service.getGroupsForUser(admin).size()); }
protected GeoServerUserGroupStore getStore(String serviceName) throws IOException { GeoServerUserGroupService service = securityManager.loadUserGroupService(serviceName); if (service == null) { throw new IllegalArgumentException( "Provided user/group service does not exist: " + serviceName); } else if (service.canCreateStore()) { return securityManager.loadUserGroupService(serviceName).createStore(); } else { throw new IOException("Provided UserGroupService is read-only."); } }
upAuthConfig.setName(GeoServerAuthenticationProvider.DEFAULT_NAME); upAuthConfig.setClassName(UsernamePasswordAuthenticationProvider.class.getName()); upAuthConfig.setUserGroupServiceName(userGroupService.getName()); userGroupService.setSecurityManager(this); roleService.setSecurityManager(this); GeoServerUserGroupStore userGroupStore = userGroupService.createStore(); GeoServerRoleStore roleStore = roleService.createStore(); if (userGroupService.getUserByUsername(GeoServerUser.ADMIN_USERNAME) == null) { userGroupStore.addUser(GeoServerUser.createDefaultAdmin()); GeoServerRole localAdminRole =
protected void createServices() throws Exception { GeoServerRoleService rservice = createRoleService("rs1"); GeoServerRoleStore rstore = rservice.createStore(); GeoServerRole root, derived; rstore.addRole(root = rstore.createRoleObject(rootRole)); rstore.addRole(derived = rstore.createRoleObject(derivedRole)); rstore.setParentRole(derived, root); rstore.associateRoleToUser(derived, testUserName); rstore.associateRoleToUser(derived, "castest"); rstore.store(); SecurityManagerConfig mconfig = getSecurityManager().loadSecurityConfig(); mconfig.setRoleServiceName("rs1"); getSecurityManager().saveSecurityConfig(mconfig); GeoServerUserGroupService ugservice = createUserGroupService("ug1"); GeoServerUserGroupStore ugstore = ugservice.createStore(); GeoServerUser u1 = ugstore.createUserObject(testUserName, testPassword, true); ugstore.addUser(u1); GeoServerUser u2 = ugstore.createUserObject("abc@xyz.com", "abc", true); ugstore.addUser(u2); GeoServerUser u3 = ugstore.createUserObject("castest", "castest", true); ugstore.addUser(u3); ugstore.store(); GeoServerAuthenticationProvider prov = createAuthProvider(testProviderName, ugservice.getName()); prepareAuthProviders(prov.getName()); }
@Override protected void onSetUp(SystemTestData testData) throws Exception { super.onSetUp(testData); // Create the test restuser if needed GeoServerUserGroupService service = getSecurityManager().loadUserGroupService(XMLUserGroupService.DEFAULT_NAME); if (service.getUserByUsername(USERNAME) == null) { GeoServerUser user = service.createUserObject(USERNAME, USERPW, true); GeoServerUserGroupStore store = service.createStore(); store.addUser(user); store.store(); service.load(); } xp = XMLUnit.newXpathEngine(); }
Map<String, GeoServerUserGroup> newGroupDict = new HashMap<String, GeoServerUserGroup>(); for (GeoServerUser user : service.getUsers()) { newUserDict.put(newUser.getUsername(), newUser); for (GeoServerUserGroup group : service.getUserGroups()) { GeoServerUserGroup newGroup = store.createGroupObject(group.getGroupname(), group.isEnabled()); newGroupDict.put(newGroup.getGroupname(), newGroup); for (GeoServerUserGroup group : service.getUserGroups()) { GeoServerUserGroup newGroup = newGroupDict.get(group.getGroupname()); for (GeoServerUser member : service.getUsersForGroup(group)) { GeoServerUser newUser = newUserDict.get(member.getUsername()); store.associateUserToGroup(newUser, newGroup);
@Override public SortedSet<GeoServerUserGroup> getGroupsForUser(GeoServerUser user) throws IOException { return filterGroups(new TreeSet<GeoServerUserGroup>(delegate.getGroupsForUser(user))); }
public SortedSet<GeoServerUser> getUsers() throws IOException { return service.getUsers(); }
public GeoServerUser getUserByUsername(String username) throws IOException { return service.getUserByUsername(username); }
public void testConfiguration() { try { setServices("config"); assertEquals(roleService,getSecurityManager().getActiveRoleService()); //assertEquals(usergroupService,getSecurityManager().getActiveUserGroupService()); assertEquals(usergroupService.getName(), getSecurityManager().loadUserGroupService(getFixtureId()).getName()); assertTrue(roleService.canCreateStore()); assertTrue(usergroupService.canCreateStore()); } catch (Exception ex) { Assert.fail(ex.getMessage()); } }
public void resetUserPassword() throws IOException, PasswordPolicyException { GeoServerUserGroupService service = getSecurityManager().loadUserGroupService(XMLUserGroupService.DEFAULT_NAME); GeoServerUser user = service.getUserByUsername(USERNAME); user.setPassword(USERPW); GeoServerUserGroupStore store = service.createStore(); store.updateUser(user); store.store(); service.load(); }
@Test public void testCreateNewUser() throws Exception { setAuth(); GeoServerUserGroupService ugService = getSecurityManager().loadUserGroupService(ugStore.getName()); GeoServerUserGroupStore ugStore = ugService.createStore(); GeoServerUser bill = ugStore.createUserObject("bill", "foobar", true); ugStore.addUser(bill); ugStore.store(); assertNotNull(ugService.getUserByUsername("bill")); }
public GeoServerUserGroup getGroupByGroupname(String groupname) throws IOException { return service.getGroupByGroupname(groupname); }
public SortedSet<GeoServerUserGroup> getUserGroups() throws IOException { return service.getUserGroups(); }