Package org.geoserver.security.web.role

Source Code of org.geoserver.security.web.role.NewRolePage

/* (c) 2014 Open Source Geospatial Foundation - all rights reserved
* (c) 2001 - 2013 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.security.web.role;

import java.io.IOException;

import org.geoserver.security.GeoServerRoleStore;
import org.geoserver.security.impl.GeoServerRole;
import org.geoserver.security.validation.RoleStoreValidationWrapper;

/**
* Page for adding a new {@link GeoServerRole} object
*
* @author christian
*
*/
public class NewRolePage extends AbstractRolePage {

    public NewRolePage(String roleServiceName) {
        super(roleServiceName, null);
       
        if (hasRoleStore(roleServiceName)==false) {
            throw new RuntimeException("Workflow error, new role not possible for read only service");
        }
    }

    @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;
        }
    }

}
TOP

Related Classes of org.geoserver.security.web.role.NewRolePage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.