Package org.geoserver.security.filter

Source Code of org.geoserver.security.filter.GeoServerJ2eeBaseAuthenticationFilter

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

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

import javax.servlet.http.HttpServletRequest;

import org.geoserver.security.GeoServerRoleService;
import org.geoserver.security.config.J2eeAuthenticationBaseFilterConfig;
import org.geoserver.security.config.J2eeAuthenticationFilterConfig;
import org.geoserver.security.config.RoleSource;
import org.geoserver.security.config.SecurityNamedServiceConfig;
import org.geoserver.security.config.J2eeAuthenticationBaseFilterConfig.J2EERoleSource;
import org.geoserver.security.impl.GeoServerRole;
import org.geoserver.security.impl.RoleCalculator;

/**
* Basic implementation for filters supporting J2EE as a {@link org.geoserver.security.config.RoleSource}
*
* @author Mauro Bartolomeoli (mauro.bartolomeoli@geo-solutions.it)
*
*/
public abstract class GeoServerJ2eeBaseAuthenticationFilter extends
        GeoServerPreAuthenticatedUserNameFilter {

    @Override
    protected Collection<GeoServerRole> getRoles(HttpServletRequest request, String principal) throws IOException{
        if(J2eeAuthenticationBaseFilterConfig.J2EERoleSource.J2EE.equals(getRoleSource())) {
            return getRolesFromJ2EE(request, principal);
        }
        return super.getRoles(request, principal);
    }

    /**
     * Implements roles retrieval from the J2EE container.
     *
     * @param request
     * @param principal
     * @return
     * @throws IOException
     */
    protected Collection<GeoServerRole> getRolesFromJ2EE(
            HttpServletRequest request, String principal) throws IOException {
       
        Collection<GeoServerRole> roles = new ArrayList<GeoServerRole>();
        boolean useActiveService = getRoleServiceName()==null ||
                getRoleServiceName().trim().length()==0;
     
        GeoServerRoleService service = useActiveService ?
              getSecurityManager().getActiveRoleService() :
              getSecurityManager().loadRoleService(getRoleServiceName());
                               
        for (GeoServerRole role: service.getRoles())
          if (request.isUserInRole(role.getAuthority()))
              roles.add(role);
     
        RoleCalculator calc = new RoleCalculator(service);
        calc.addInheritedRoles(roles);
        calc.addMappedSystemRoles(roles);
        return roles;
    }

}
TOP

Related Classes of org.geoserver.security.filter.GeoServerJ2eeBaseAuthenticationFilter

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.