You need to subclass the request processor and override the processRoles
method, which by default does nothing. I have included some code which
may help.

public class BHBRequestProcessor extends DelegatingTilesRequestProcessor
{
        
        
    protected boolean processRoles(javax.servlet.http.HttpServletRequest
request, 
            javax.servlet.http.HttpServletResponse response, 
            org.apache.struts.action.ActionMapping mapping
            ) throws java.io.IOException, javax.servlet.ServletException
{
        
        // the roles set in the struts action  mapping
        String[] roles = mapping.getRoleNames();
        
        // no roles defined
        if(roles == null || roles.length == 0) {
                return true;
        }
        HttpSession session = request.getSession(true);
        IUserContainer userContainer = null;
        IUserView userView = null;
        try {
          userContainer =
(IUserContainer)session.getAttribute(IConstants.USER_CONTAINER);
          userView = (IUserView)userContainer.getUserView();
        catch(Exception ex) {
          // not logged in
          // set error info in request 
          errors = new ActionMessages();
          errors.add(ActionMessages.GLOBAL_MESSAGE,new
ActionMessage("user.login.required"));
          return false;
        }
          if(userContainer.getUserView().isAuthenticated()) {
            // loop over the roles set in the action mapping
            for(int i=0; i< roles.length; i++) {
              // check to see if the user has the required role
              // userContainer and userview objects are populated at
login
              if(userContainer.getUserView().containsRole(roles[i])) {
                      return true;
              }
            }
          }
          return false;
      }
}


Hope this helps


Alan 


-----Original Message-----
From: Tony Haidamous [mailto:[EMAIL PROTECTED] 
Sent: 30 January 2006 10:16
To: Struts Users Mailing List
Subject: Roles in struts

I noticed that action mapping can contain a roles parameter. Any idea
how
and where to define those roles & how to set roles for user when
authenticated. Any sample code I can find on this matter?
Thanks

Best Regards,
____________________________________________
Tony HAIDAMOUS
Computer Engineer
CME Offshore S.A.L, Hazmieh - Lebanon
www.gotocme.com
Phone:  + 961 (0) 1 88 66 60
Mobile: + 961 (0) 3 67 05 37
E-mail:         [EMAIL PROTECTED]
         [EMAIL PROTECTED]
         [EMAIL PROTECTED]
MSN:    [EMAIL PROTECTED] 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to