FileDocCategorySizeDatePackage
RoleRequestProcessor.javaAPI DocExample1174Wed Sep 01 23:43:06 BST 2004com.oreilly.strutsckbk.ch11

RoleRequestProcessor

public class RoleRequestProcessor extends RequestProcessor

Fields Summary
Constructors Summary
Methods Summary
protected booleanprocessRoles(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, ActionMapping mapping)

    // Is this action protected by role requirements?
    String roles[] = mapping.getRoleNames();
    if ((roles == null) || (roles.length < 1)) {
      return true;
    }
    // Check the current user against the list of required roles
    HttpSession session = request.getSession();
    User user = (User) session.getAttribute("user");
    if (user == null) {
      return false;
    }
    for (int i = 0; i < roles.length; i++) {
      if (user.hasRole(roles[i])) {
        return (true);
      }
    }
    response.sendError(HttpServletResponse.SC_BAD_REQUEST,
                       getInternal().getMessage("notAuthorized",
                       mapping.getPath()));
    return (false);