public GeoServerRole createRoleObject(String role) throws IOException { return new GeoServerRole(role); }
public GeoServerRole createRoleObject(String role) throws IOException { return new GeoServerRole(role); }
@Override public GeoServerRole convertRoleFromString(String roleString, String userName) { if (roleString == null) return null; roleString = roleString.trim(); if (roleString.isEmpty()) return null; checkDelimiters(); List<String> working = splitString(roleString.trim(), getRoleParameterStartString()); GeoServerRole result = new GeoServerRole(working.get(0)); if (working.size() == 1) { return result; } // we have role parameters result.setUserName(userName); if (working.get(1).endsWith(getRoleParameterEndString()) == false) throw createExcpetion(roleString + " does not end with " + getRoleParameterEndString()); int index = working.get(1).lastIndexOf(getRoleParameterEndString()); String roleParamString = working.get(1).substring(0, index).trim(); working = splitString(roleParamString, getRoleParameterDelimiterString()); for (String kvp : working) { List<String> tmp = splitString(kvp.trim(), getRoleParameterAssignmentString()); if (tmp.size() != 2) throw createExcpetion(roleString + " Invalid role string: " + roleString); result.getProperties().put(tmp.get(0).trim(), tmp.get(1).trim()); } return result; }
protected void addRolesToCreate(GeoServerRoleStore roleStore, String... roleNames) throws IOException { for (String roleName : roleNames) { expect(roleStore.createRoleObject(roleName)) .andReturn(new GeoServerRole(roleName)) .anyTimes(); } } }
protected GeoServerRoleStore createRoleStore( String name, GeoServerSecurityManager secMgr, String... roleNames) throws IOException { GeoServerRoleStore roleStore = createNiceMock(GeoServerRoleStore.class); expect(roleStore.getSecurityManager()).andReturn(secMgr).anyTimes(); expect(roleStore.getName()).andReturn(name).anyTimes(); for (String roleName : roleNames) { expect(roleStore.getRoleByName(roleName)) .andReturn(new GeoServerRole(roleName)) .anyTimes(); } for (GeoServerRole role : GeoServerRole.SystemRoles) { String roleName = role.getAuthority(); expect(roleStore.createRoleObject(roleName)) .andReturn(new GeoServerRole(roleName)) .anyTimes(); } expect(secMgr.loadRoleService(name)).andReturn(roleStore).anyTimes(); return roleStore; }
/** * @see org.geoserver.security.GeoServerRoleService#createRoleObject(java.lang.String) */ public GeoServerRole createRoleObject(String role) { return new GeoServerRole(role); }
@Override public GeoServerRole createRoleObject(String role) throws IOException { return new GeoServerRole(rolePrefix + (convertToUpperCase ? role.toUpperCase() : role)); }
public NewRolePage(String roleServiceName) { super(roleServiceName, new GeoServerRole(GeoServerRole.NULL_ROLE.getAuthority())); if (hasRoleStore(roleServiceName)==false) { throw new RuntimeException("Workflow error, new role not possible for read only service"); } }
protected void insert(GeoServerRoleService roleService, String roleName) throws IOException { GeoServerRoleStore store = getStore(roleService); try { store.addRole(new GeoServerRole(roleName)); } finally { store.store(); } }
@Test public void testRoles() throws Exception { copyWebXML("web2.xml"); GeoServerRoleService service = getSecurityManager().loadRoleService("test2"); assertEquals(4, service.getRoleCount()); assertTrue(service.getRoles().contains(new GeoServerRole("role1"))); assertTrue(service.getRoles().contains(new GeoServerRole("role2"))); assertTrue(service.getRoles().contains(new GeoServerRole("employee"))); assertTrue(service.getRoles().contains(new GeoServerRole("MGR"))); }
@Override public GeoServerSecurityManager createSecurityManager(MockTestData testData) throws Exception { GeoServerSecurityManager secMgr = createNiceMock(GeoServerSecurityManager.class); GeoServerRoleStore roleStore = createRoleStore("test", secMgr, "admin", "groupAdmin", "role1"); addRolesToCreate(roleStore, "admin", "groupAdmin"); expect(roleStore.getAdminRole()) .andReturn(new GeoServerRole("admin")) .anyTimes(); expect(roleStore.getGroupAdminRole()) .andReturn(new GeoServerRole("groupAdmin")) .anyTimes(); replay(roleStore, secMgr); return secMgr; } });
private void checkUserNamesForRole(String roleName, int expected, boolean userFilter) throws IOException { createRoleService(userFilter); SortedSet<String> userNames = service.getUserNamesForRole(new GeoServerRole(roleName)); assertNotNull(userNames); assertEquals(expected, userNames.size()); }
expect(roleStore.removeRole(new GeoServerRole("unused"))).andReturn(true);
@Override public GeoServerSecurityManager createSecurityManager(MockTestData testData) throws Exception { GeoServerSecurityManager secMgr = createNiceMock(GeoServerSecurityManager.class); GeoServerUserGroupStore ugStore1 = createUserGroupStore("test1", secMgr); addUsers(ugStore1, "user1", "abc"); addGroups(ugStore1, "group1"); GeoServerUserGroupStore ugStore2 = createUserGroupStore("test2", secMgr); addUsers(ugStore1, "user2", "abc"); addGroups(ugStore1, "group2"); GeoServerRoleStore roleStore = createRoleStore("test", secMgr, "role1"); expect(roleStore.getGroupNamesForRole(new GeoServerRole("role1"))) .andReturn(new TreeSet<String>(Arrays.asList("group1", "group2"))) .anyTimes(); replay(ugStore1, ugStore2, roleStore, secMgr); return secMgr; } });
@Override protected void onFormSubmit(GeoServerRole role) throws IOException { GeoServerRoleStore store = null; try { //copy into a new one so we can set the name properly GeoServerRole newRole = new GeoServerRole(get("form:name").getDefaultModelObjectAsString()); newRole.setUserName(role.getUserName()); newRole.getProperties().putAll(role.getProperties()); role = newRole; store = new RoleStoreValidationWrapper(getRoleStore(roleServiceName)); 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; } }
@Test public void testConverter() { GeoServerRole r1 = new GeoServerRole("r1"); r1.getProperties().setProperty("r1_p1", "r1_v1"); r1.getProperties().setProperty("r1_p2", "r1_v2"); GeoServerRole r2 = new GeoServerRole("r2"); r2.getProperties().setProperty("r2_p1", "r2_v1"); GeoServerRole r3 = new GeoServerRole("r3");
checkForAuthenticatedRole(auth); assertEquals(testUserName, ((UserDetails) auth.getPrincipal()).getUsername()); assertTrue(auth.getAuthorities().contains(new GeoServerRole(rootRole))); assertTrue(auth.getAuthorities().contains(new GeoServerRole(derivedRole))); checkForAuthenticatedRole(auth); assertEquals(testUserName, ((UserDetails) auth.getPrincipal()).getUsername()); assertTrue(auth.getAuthorities().contains(new GeoServerRole(rootRole))); assertTrue(auth.getAuthorities().contains(new GeoServerRole(derivedRole)));
role=new GeoServerRole("");
boolean hasRoleStore = hasRoleStore(roleServiceName); if (role == null) role = new GeoServerRole("");
assertTrue(user.getAuthorities().contains(new GeoServerRole("ROLE_MYROLE_1"))); assertTrue(user.getAuthorities().contains(new GeoServerRole("ROLE_MYROLE_2")));