GeoServerRoleStore roleStore = roleService.createStore(); for (String roleName : roles) { GeoServerRole role = roleStore.getRoleByName(roleName); if (role == null) { role = roleStore.createRoleObject(roleName); roleStore.addRole(role); roleStore.associateRoleToUser(role, username); roleStore.store();
@Test public void testIsModified() throws Exception { assertFalse(store.isModified()); assertTrue(store.isModified()); store.load(); assertFalse(store.isModified()); store.store(); assertFalse(store.isModified()); GeoServerRole role = store.createRoleObject("ROLE_DUMMY"); GeoServerRole role_parent = store.createRoleObject("ROLE_PARENT"); assertFalse(store.isModified()); store.addRole(role); store.addRole(role_parent); assertTrue(store.isModified()); store.store(); assertFalse(store.isModified()); store.updateRole(role); assertTrue(store.isModified()); store.load(); assertFalse(store.isModified()); store.removeRole(role); assertTrue(store.isModified());
public void removeValues(GeoServerRoleStore roleStore) throws IOException { GeoServerRole role_auth = roleStore.createRoleObject("ROLE_AUTHENTICATED"); GeoServerRole role_wfs = roleStore.getRoleByName("ROLE_WFS"); roleStore.removeRole(role_wfs); roleStore.removeRole(role_auth); }
public void modifyValues(GeoServerRoleStore roleStore) throws IOException { GeoServerRole role_auth = roleStore.getRoleByName("ROLE_AUTHENTICATED"); GeoServerRole role_wfs = roleStore.getRoleByName("ROLE_WFS"); GeoServerRole role_wms = roleStore.getRoleByName("ROLE_WMS"); role_auth.getProperties().remove("bbox"); role_auth.getProperties().setProperty("employee", "4711"); roleStore.updateRole(role_auth); role_wms.getProperties().setProperty("envelope", "10 10 20 20"); roleStore.updateRole(role_wms); roleStore.disAssociateRoleFromGroup(role_wfs, "g_all"); roleStore.disAssociateRoleFromUser(role_wfs, "user1"); roleStore.setParentRole(role_wms, null); roleStore.setParentRole(role_wfs, role_wms); }
public void insertValues(GeoServerRoleStore roleStore) throws IOException { GeoServerRole role_admin = roleStore.createRoleObject(GeoServerRole.ADMIN_ROLE.getAuthority()); GeoServerRole role_auth = roleStore.createRoleObject("ROLE_AUTHENTICATED"); GeoServerRole role_wfs = roleStore.createRoleObject("ROLE_WFS"); GeoServerRole role_wms = roleStore.createRoleObject("ROLE_WMS"); role_auth.getProperties().put("employee", ""); role_auth.getProperties().put("bbox", "lookupAtRuntime"); roleStore.addRole(role_admin); roleStore.addRole(role_auth); roleStore.addRole(role_wfs); roleStore.addRole(role_wms); roleStore.setParentRole(role_wms, role_auth); roleStore.setParentRole(role_wfs, role_auth); roleStore.associateRoleToUser(role_admin, "admin"); roleStore.associateRoleToUser(role_wms, "user1"); roleStore.associateRoleToUser(role_wfs, "user1"); roleStore.associateRoleToGroup(role_wms, "g_wms"); roleStore.associateRoleToGroup(role_wfs, "g_wfs"); roleStore.associateRoleToGroup(role_wms, "g_all"); roleStore.associateRoleToGroup(role_wfs, "g_all"); }
list.addAll(gaStore.getRolesForUser(user.getUsername())); for (GeoServerRole role: list) gaStore.disAssociateRoleFromUser(role, user.getUsername()); gaStore.store(); } catch (IOException ex) { try {gaStore.load(); } catch (IOException ex2) {}; throw new RuntimeException(ex);
@Override protected void onFormSubmit(GeoServerRole role) throws IOException { GeoServerRoleStore store = null; try { store = new RoleStoreValidationWrapper(getRoleStore(roleServiceName)); //copy into a new one so we can set the name properly GeoServerRole newRole= store.createRoleObject(get("form:name").getDefaultModelObjectAsString()); newRole.setUserName(role.getUserName()); newRole.getProperties().putAll(role.getProperties()); role = newRole; store.addRole(role); String parentRoleName = get("form:parent").getDefaultModelObjectAsString(); if (parentRoleName != null) { GeoServerRole parentRole = store.getRoleByName(parentRoleName); store.setParentRole(role, parentRole); } store.store(); } catch (IOException ex) { try {store.load(); } catch (IOException ex2) {}; throw ex; } }
gaStore = new RoleStoreValidationWrapper(gaStore); Set<GeoServerRole> orig = gaStore.getRolesForGroup(group.getGroupname()); Set<GeoServerRole> add = new HashSet<GeoServerRole>(); Set<GeoServerRole> remove = new HashSet<GeoServerRole>(); gaStore.associateRoleToGroup(role, group.getGroupname()); for (GeoServerRole role : remove) gaStore.disAssociateRoleFromGroup(role, group.getGroupname()); gaStore.store(); try {gaStore.load(); } catch (IOException ex2) {}; throw ex;
roleStore.addRole(GeoServerRole.ADMIN_ROLE); roleStore.associateRoleToUser(GeoServerRole.ADMIN_ROLE, "sa"); roleStore.store(); getSecurityManager().setActiveRoleService(roleService);
role = roleStore.createRoleObject("userrole1"); roleStore.addRole(role); roleStore.associateRoleToUser(role, username); roles.add(role); checkRoles(username, roles); role = roleStore.createRoleObject("userrole2"); roleStore.addRole(role); roleStore.associateRoleToUser(role, username); roles.add(role); checkRoles(username, roles); usergroupStore.addGroup(theGroup1); usergroupStore.associateUserToGroup(theUser, theGroup1); role = roleStore.createRoleObject("grouprole1a"); roleStore.addRole(role); roleStore.associateRoleToGroup(role, "theGroup1"); roles.add(role); checkRoles(username, roles); role = roleStore.createRoleObject("grouprole1b"); roleStore.addRole(role); roleStore.associateRoleToGroup(role, "theGroup1"); roles.add(role); checkRoles(username, roles); usergroupStore.addGroup(theGroup2); usergroupStore.associateUserToGroup(theUser, theGroup2); role = roleStore.createRoleObject("grouprole2a");
@Override protected void onFormSubmit(GeoServerRole updated) throws IOException{ if (hasRoleStore(roleServiceName)==false) { throw new RuntimeException("Invalid workflow, cannot store in a read only role service"); } GeoServerRoleStore store=null; try { store = new RoleStoreValidationWrapper(getRoleStore(roleServiceName)); GeoServerRole role = store.getRoleByName(updated.getAuthority()); role.getProperties().clear(); role.getProperties().putAll(updated.getProperties()); store.updateRole(role); String parentRoleName = get("form:parent").getDefaultModelObjectAsString(); if (parentRoleName != null) { GeoServerRole parentRole = store.getRoleByName(parentRoleName); store.setParentRole(role, parentRole); } store.store(); } catch (IOException ex) { try {store.load(); } catch (IOException ex2) {}; throw ex; } }
gaStore = new RoleStoreValidationWrapper(gaStore); for (GeoServerRole role : rolePalette.getSelectedRoles()) { gaStore.associateRoleToUser(role, user.getUsername()); gaStore.store(); try {gaStore.load(); } catch (IOException ex2) {}; throw ex;
protected boolean onSubmit(AjaxRequestTarget target, Component contents) { // cascade delete the whole selection GeoServerRoleStore gaStore = null; try { GeoServerRoleService gaService = GeoServerApplication.get().getSecurityManager().loadRoleService(roleServiceName); gaStore = new RoleStoreValidationWrapper(gaService.createStore()); for (GeoServerRole role : removePanel.getRoots()) { gaStore.removeRole(role); } gaStore.store(); } catch (IOException ex) { try {gaStore.load(); } catch (IOException ex2) {}; throw new RuntimeException(ex); } // the deletion will have changed what we see in the page // so better clear out the selection roles.clearSelection(); return true; }
@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; } }
@Override public void store() throws IOException { delegateAsStore().store(); }
@Test public void testModify() throws Exception { checkEmpty(service); checkEmpty(store); insertValues(store); store.store(); checkValuesInserted(store); checkValuesInserted(service); modifyValues(store); if (!isJDBCTest()) checkValuesInserted(service); checkValuesModified(store); store.load(); checkValuesInserted(store); checkValuesInserted(service); modifyValues(store); store.store(); checkValuesModified(store); checkValuesModified(service); }
GeoServerRole role_test1 = store1.createRoleObject("ROLE_TEST1"); store1.addRole(role_test1); store1.store(); assertTrue(service1.getRoles().size() == 1);
protected void associate(GeoServerRoleService roleService, String roleName, String userName) throws IOException { GeoServerRoleStore store = getStore(roleService); try { store.associateRoleToUser(getRole(store, roleName), userName); } finally { store.store(); } }