@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; }
/** * Takes the role set for a user and personalizes the roles (matching user properties and role * parameters) * * @param user * @param roles * @throws IOException */ public SortedSet<GeoServerRole> personalizeRoles( GeoServerUser user, Collection<GeoServerRole> roles) throws IOException { SortedSet<GeoServerRole> set = new TreeSet<GeoServerRole>(); for (GeoServerRole role : roles) { Properties personalizedProps = getRoleService() .personalizeRoleParams( role.getAuthority(), role.getProperties(), user.getUsername(), user.getProperties()); if (personalizedProps == null) { set.add(role); } else { // create personalized role GeoServerRole pRole = getRoleService().createRoleObject(role.getAuthority()); pRole.setUserName(user.getUsername()); for (Object key : personalizedProps.keySet()) pRole.getProperties().put(key, personalizedProps.get(key)); set.add(pRole); } } return set; } }
@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; } }
@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; } }
newRole.setUserName(role.getUserName()); newRole.getProperties().putAll(role.getProperties()); role = newRole;