All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.navigator.menu.RolesPermissionsAdapter Maven / Gradle / Ivy

Go to download

This application allows creation of many different menu systems from an XML file or dynamically from a database.

There is a newer version: 2.4.3
Show newest version
/*
 * RolesPermissionsAdapter.java
 *
 * Created on December 7, 2002 2:25 PM
 */

package net.sf.navigator.menu;

import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;

/**
 * This class used container-managed security to check access
 * to menus.  The roles are set in menu-config.xml.
 * tst
 * @author Matt Raible
 */
public class RolesPermissionsAdapter implements PermissionsAdapter {
    
    /**
     * The current request for this user
     */
    private HttpServletRequest request;
    
    /**
     * Creates a new instance of RolesPermissionsAdapter
     */
    public RolesPermissionsAdapter(HttpServletRequest request) {
        this.request = request;
    }
    
    /**
     * If the menu is allowed, this should return true.
     *
     * @return whether or not the menu is allowed.
     */
    public boolean isAllowed(MenuComponent menu) { 
        if (menu.getRoles() == null) { 
            return true; // no roles define, allow everyone
        } else {
            // Get the list of roles this menu allows
            String[] allowedRoles = StringUtils.split(menu.getRoles(),",");    
            for (int i=0; i < allowedRoles.length; i++) {
                if (request.isUserInRole(allowedRoles[i])) {
                    return true;
                }
            }
        }
        return false;
    }    
    
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy