0

I don't know if my Permission Checking is right but I'm doing it this way.

public class User {
   public boolean hasPermission (String permission){
       // codes here to check from Roles.permissions if permission parameter exists
       // return true if exists, otherwise return false
   }
}

In my JSP, I want to hide a button if the User which is saved in the session as "currentUser" doesn't have 'save.settings' permission.

to organize my codes, I declared an interface:

public interface Permission {
    public static final String SAVE_SETTINGS = "save.settings";
}

so that I will just access the static variable in my JSP when checking for permission.

now how do i do this in my JSP? I tried...

<s:if test="{#session.currentUser.hasPermission(@my.pkg.Permission@SAVE_SETTINGS)}">
     <div>
        <input id="iSave" type="button" value="Save" /> 
    </div>
</s:if>

but it doesn work.

<constant name="struts.ognl.allowStaticMethodAccess" value="true"/> 

is also set in my struts.xml

Any idea guys?

Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243
Macchiato
  • 825
  • 1
  • 11
  • 24

1 Answers1

1

Use

<s:if test="#session['currentUser'].hasPermission(@my.pkg.Permission@SAVE_SETTINGS)">

or

<s:if test="#session.currentUser.hasPermission(@my.pkg.Permission@SAVE_SETTINGS)">
Andrea Ligios
  • 49,480
  • 26
  • 114
  • 243