1 package org.roller.presentation.tags.menu; 2 3 import java.util.ArrayList ; 4 import java.util.Arrays ; 5 import java.util.Iterator ; 6 import java.util.List ; 7 8 import javax.servlet.http.HttpServletRequest ; 9 10 import org.roller.RollerException; 11 import org.roller.config.RollerConfig; 12 import org.roller.presentation.RollerRequest; 13 import org.roller.util.Utilities; 14 15 19 public abstract class BaseRollerMenu 20 { 21 protected String mName = null; 22 protected String mEnabledProperty = null; 23 protected String mDisabledProperty = null; 24 protected List mRoles = new ArrayList (); 25 26 public BaseRollerMenu() {} 27 28 public BaseRollerMenu(String name) { mName = name; } 29 30 31 public void setName( String v ) { mName = v; } 32 33 34 public String getName() { return mName; } 35 36 37 public void setRoles( String roles ) 38 { 39 mRoles = Arrays.asList(Utilities.stringToStringArray(roles,",")); 40 } 41 42 43 public void setEnabledProperty(String enabledProperty) 44 { 45 mEnabledProperty = enabledProperty; 46 } 47 48 49 public void setDisabledProperty(String disabledProperty) 50 { 51 mDisabledProperty = disabledProperty; 52 } 53 54 55 public boolean isPermitted(HttpServletRequest req) throws RollerException 56 { 57 if (mEnabledProperty != null) 58 { 59 String enabledProp = RollerConfig.getProperty(mEnabledProperty); 60 if (enabledProp != null && enabledProp.equalsIgnoreCase("false")) 61 { 62 return false; 63 } 64 } 65 if (mDisabledProperty != null) 66 { 67 String disabledProp = RollerConfig.getProperty(mDisabledProperty); 68 if (disabledProp != null && disabledProp.equalsIgnoreCase("true")) 69 { 70 return false; 71 } 72 } 73 if (mRoles != null && mRoles.size() > 0) 74 { 75 Iterator roles = mRoles.iterator(); 76 while (roles.hasNext()) 77 { 78 RollerRequest rreq = RollerRequest.getRollerRequest(req); 79 String role = (String )roles.next(); 80 if (req.isUserInRole(role)) 81 { 82 return true; 83 } 84 else if (role.equals("admin") && rreq.isAdminUser()) 85 { 86 return true; 87 } 88 } 89 return false; 90 } 91 return true; 92 } 93 } 94 | Popular Tags |