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()); }
store.getSecurityManager().loadPasswordEncoder(store.getPasswordEncoderName()); encoder.initializeFor(store); new GeoServerMultiplexingPasswordEncoder(store.getSecurityManager(), store); for (GeoServerUser user : store.getUsers()) { if (encoder.isResponsibleForEncoding(user.getPassword())) continue; // nothing to do try { user.setPassword(encPass); try { store.updateUser(user); } catch (PasswordPolicyException e) { store.load(); // rollback throw new RuntimeException("Never should reach this point", e); store.store();
GeoServerUser user = ugStore.createUserObject(username, password, true); ugStore.addUser(user); GeoServerUserGroup group = ugStore.getGroupByGroupname(groupName); if (group == null) { group = ugStore.createGroupObject(groupName, true); ugStore.addGroup(group); ugStore.associateUserToGroup(user, group); ugStore.store();
public void removeValues(GeoServerUserGroupStore userGroupStore) throws IOException { GeoServerUser user2 = userGroupStore.getUserByUsername("user2"); if (user2 != null) { userGroupStore.removeUser(user2); } GeoServerUserGroup disabledGroup = userGroupStore.getGroupByGroupname("disabledgroup"); if (disabledGroup != null) { userGroupStore.removeGroup(disabledGroup); } }
userGroupStore.createUserObject( GeoServerUser.ADMIN_USERNAME, GeoServerUser.DEFAULT_ADMIN_PASSWD, GeoServerUser.AdminEnabled); GeoServerUser user1 = userGroupStore.createUserObject("user1", "11111", true); GeoServerUser user2 = userGroupStore.createUserObject("user2", "22222", true); GeoServerUser disableduser = userGroupStore.createUserObject("disableduser", "", false); GeoServerUser groupAdminUser = userGroupStore.createUserObject("groupAdminUser", "foo", true); userGroupStore.addUser(admin); userGroupStore.addUser(user1); userGroupStore.addUser(user2); userGroupStore.addUser(disableduser); userGroupStore.addUser(groupAdminUser); GeoServerUserGroup admins = userGroupStore.createGroupObject("admins", true); GeoServerUserGroup group1 = userGroupStore.createGroupObject("group1", true); GeoServerUserGroup group2 = userGroupStore.createGroupObject("group2", true); GeoServerUserGroup disabledgroup = userGroupStore.createGroupObject("disabledgroup", false); userGroupStore.addGroup(admins); userGroupStore.addGroup(group1); userGroupStore.addGroup(disabledgroup); userGroupStore.addGroup(group2); userGroupStore.associateUserToGroup(admin, admins); userGroupStore.associateUserToGroup(user1, group1);
@Test public void testIsModified() throws Exception { assertFalse(store.isModified()); assertTrue(store.isModified()); store.load(); assertFalse(store.isModified()); store.store(); assertFalse(store.isModified()); GeoServerUser user = store.createUserObject("uuuu", "", true); GeoServerUserGroup group = store.createGroupObject("gggg", true); assertFalse(store.isModified()); store.addUser(user); assertTrue(store.isModified()); store.store(); assertFalse(store.isModified()); store.addGroup(group); assertTrue(store.isModified()); store.store(); assertFalse(store.isModified()); store.updateUser(user); assertTrue(store.isModified()); store.load();
ugStore = new UserGroupStoreValidationWrapper(ugService.createStore()); Set<GeoServerUserGroup> orig = ugStore.getGroupsForUser(user); Set<GeoServerUserGroup> add = new HashSet<GeoServerUserGroup>(); Set<GeoServerUserGroup> remove = new HashSet<GeoServerUserGroup>(); userGroupPalette.diff(orig, add, remove); ugStore.updateUser(user); for (GeoServerUserGroup g : add) ugStore.associateUserToGroup(user, g); for (GeoServerUserGroup g : remove) ugStore.disAssociateUserFromGroup(user,g); ugStore.store(); try { ugStore.load(); } catch (IOException ex2) {}; throw ex; } catch (PasswordPolicyException ex) { try { ugStore.load(); } catch (IOException ex2) {}; throw ex;
new UserGroupStoreValidationWrapper(getUserGroupStore(ugServiceName)); try { ugStore.addUser(user); ugStore.associateUserToGroup(user, group); ugStore.store(); try {ugStore.load(); } catch (IOException ex2) {}; throw ex; } catch (PasswordPolicyException ex) { try {ugStore.load(); } catch (IOException ex2) {}; throw ex;
GeoServerUser sa = ugStore.createUserObject("sa", "", true); ugStore.addUser(sa); ugStore.store(); ugStore.updateUser(sa); ugStore.store();
@Override protected void onFormSubmit(GeoServerUserGroup group) throws IOException { GeoServerUserGroupStore store=null; try { store = new UserGroupStoreValidationWrapper(getUserGroupStore(userGroupServiceName)); group = store.createGroupObject(group.getGroupname(),group.isEnabled()); store.addGroup(group); store.store(); } catch (IOException ex) { try { store.load(); } catch (IOException ex2) {}; throw ex; } GeoServerRoleStore gaStore=null; try { if (hasRoleStore(getSecurityManager().getActiveRoleService().getName())) { gaStore = getRoleStore(getSecurityManager().getActiveRoleService().getName()); gaStore = new RoleStoreValidationWrapper(gaStore); for (GeoServerRole role : rolePalette.getSelectedRoles()) { gaStore.associateRoleToGroup(role, group.getGroupname()); } gaStore.store(); } } catch (IOException ex) { try {gaStore.load(); } catch (IOException ex2) {}; throw ex; } }
@Test public void testRemoveUserNotInGroup() throws Exception { GeoServerUserGroupService ugService = getSecurityManager().loadUserGroupService(ugStore.getName()); GeoServerUserGroupStore ugStore = ugService.createStore(); GeoServerUser sally = ugStore.createUserObject("sally", "foobar", true); ugStore.addUser(sally); ugStore.associateUserToGroup(sally, admins); ugStore.store(); setAuth(); ugService = getSecurityManager().loadUserGroupService(ugStore.getName()); ugStore = ugService.createStore(); try { ugStore.removeUser(sally); fail(); } catch (IOException e) { ugStore.load(); } ; } }
store.getSecurityManager().loadPasswordEncoder(store.getPasswordEncoderName()); encoder.initializeFor(store); new GeoServerMultiplexingPasswordEncoder(store.getSecurityManager(), service); store.clear(); Map<String, GeoServerUser> newUserDict = new HashMap<String, GeoServerUser>(); Map<String, GeoServerUserGroup> newGroupDict = new HashMap<String, GeoServerUserGroup>(); store.createUserObject(user.getUsername(), encPassword, user.isEnabled()); for (Object key : user.getProperties().keySet()) { newUser.getProperties().put(key, user.getProperties().get(key)); store.addUser(newUser); newUserDict.put(newUser.getUsername(), newUser); store.createGroupObject(group.getGroupname(), group.isEnabled()); store.addGroup(newGroup); newGroupDict.put(newGroup.getGroupname(), newGroup); store.associateUserToGroup(newUser, newGroup);
theUser = usergroupStore.createUserObject(username, "", true); usergroupStore.addUser(theUser); GeoServerUserGroup theGroup1 = usergroupStore.createGroupObject("theGroup1", true); usergroupStore.addGroup(theGroup1); usergroupStore.associateUserToGroup(theUser, theGroup1); role = roleStore.createRoleObject("grouprole1a"); roleStore.addRole(role); GeoServerUserGroup theGroup2 = usergroupStore.createGroupObject("theGroup2", false); usergroupStore.addGroup(theGroup2); usergroupStore.associateUserToGroup(theUser, theGroup2); role = roleStore.createRoleObject("grouprole2a"); roleStore.addRole(role); usergroupStore.updateGroup(theGroup2); roles.add(role); checkRoles(username, roles); usergroupStore.removeGroup(theGroup2); tmp = roleStore.getRoleByName("grouprole2a"); roles.remove(tmp);
GeoServerUser u1 = ugstore.createUserObject("user1", "passwd1", true); ugstore.addUser(u1); GeoServerUser u2 = ugstore.createUserObject("user2", "passwd2", true); ugstore.addUser(u2); ugstore.store(); GeoServerUser u3 = ugstore.createUserObject("user3", "passwd3", true); ugstore.addUser(u3); ugstore.removeUser(u1); ugstore.store(); u2 = (GeoServerUser) ugstore.loadUserByUsername("user2"); u2.setEnabled(false); ugstore.updateUser(u2); ugstore.store();
ugStore = new UserGroupStoreValidationWrapper(ugService.createStore()); for (GeoServerUser user : removePanel.getRoots()) { ugStore.removeUser(user); ugStore.store(); } catch (IOException ex) { try {ugStore.load(); } catch (IOException ex2) {}; throw new RuntimeException(ex);
@Override protected void onSetUp(SystemTestData testData) throws Exception { super.onSetUp(testData); // set up the services GeoServerUserGroupService ugService = createUserGroupService("gaugs"); GeoServerRoleService roleService = createRoleService("gars"); getSecurityManager().setActiveRoleService(roleService); // add the users GeoServerUserGroupStore ugStore = createStore(ugService); GeoServerUser bob = ugStore.createUserObject("bob", "foobar", true); GroupAdminProperty.set(bob.getProperties(), new String[] {"users"}); ugStore.addUser(bob); GeoServerUser alice = ugStore.createUserObject("alice", "foobar", true); ugStore.addUser(alice); GeoServerUserGroup users = ugStore.createGroupObject("users", true); ugStore.addGroup(users); GeoServerUserGroup admins = ugStore.createGroupObject("admins", true); ugStore.addGroup(admins); ugStore.store(); // grant bob group admin privilege GeoServerRole groupAdminRole = null; GeoServerRoleStore roleStore = createStore(roleService); roleStore.addRole(roleStore.createRoleObject("adminRole")); roleStore.addRole(groupAdminRole = roleStore.createRoleObject("groupAdminRole")); roleStore.associateRoleToUser(groupAdminRole, bob.getUsername()); roleStore.store(); }
ugStore = new UserGroupStoreValidationWrapper(ugService.createStore()); for (GeoServerUserGroup group : removePanel.getRoots()) { ugStore.removeGroup(group); ugStore.store(); } catch (IOException ex) { try {ugStore.load(); } catch (IOException ex2) {}; throw new RuntimeException(ex);
if (hasUserGroupStore(userGroupServiceName)) { store = new UserGroupStoreValidationWrapper(getUserGroupStore(userGroupServiceName)); store.updateGroup(group); store.store(); }; } catch (IOException ex) { try { store.load(); } catch (IOException ex2) {}; throw ex;
@Override protected void onSetUp(SystemTestData testData) throws Exception { addUser("pippo", "clown", null, Arrays.asList("CIRCUS", "KLINIEK", "ZEVER")); addUser("jantje", "jantje", null, Arrays.asList("MOPJES", "ZEVER")); GeoServerSecurityManager secMgr = getSecurityManager(); GeoServerUserGroupService userGroupService = secMgr.loadUserGroupService("default"); GeoServerRoleService roleService = secMgr.loadRoleService("default"); GeoServerUserGroupStore userGroupStore = userGroupService.createStore(); GeoServerRoleStore rolesStore = roleService.createStore(); GeoServerUser roleUserTest = userGroupService.createUserObject("role_user_test", "role_user_test", true); userGroupStore.addUser(roleUserTest); GeoServerRole roleTest = rolesStore.createRoleObject("ROLE_TEST"); rolesStore.addRole(roleTest); rolesStore.associateRoleToUser(roleTest, "role_user_test"); GeoServerRole roleTest2 = rolesStore.createRoleObject("ROLE_TEST_2"); rolesStore.addRole(roleTest2); GeoServerUserGroup roleGroup = userGroupService.createGroupObject("ROLE_GROUP", true); userGroupStore.addGroup(roleGroup); userGroupStore.associateUserToGroup(roleUserTest, roleGroup); rolesStore.associateRoleToGroup(roleTest2, "ROLE_GROUP"); userGroupStore.store(); rolesStore.store(); }
@Override public void store() throws IOException { delegateAsStore().store(); }