public int doStartTag() throws JspException { boolean skipBody = true; HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); if (adminRole != null && SecurityHelper.isUserInRole(request, adminRole)) { skipBody = false; } else { String[] roles = role.split(","); for (int i = 0; i < roles.length; i++) { String role = roles[i]; if (SecurityHelper.isUserInRole(request, role)) { skipBody = false; break; } } try { if (userid != null && !SecurityHelper.getUserPrincipal(request).getName().equals(userid)) { skipBody = true; } } catch (AuthenticationException e) { throw new JspException(e); } } return (negate ? !skipBody : skipBody) ? SKIP_BODY : EVAL_BODY_INCLUDE; }
public void setUp() throws Exception { super.setUp(); writableTableTag = new WritableTableTag(); support = new XPlannerTestSupport(); support.pageContext.setAttribute(TableTag.PAGE_ATTRIBUTE_MEDIA, MediaTypeEnum.HTML); writableTableTag.setPageContext(support.pageContext); authorizerControl = MockControl.createControl(Authorizer.class); authorizer = (Authorizer) authorizerControl.getMock(); Collection projectCol = new ArrayList(); writableTableTag.setWholeCollection(projectCol); project = new Project(); projectCol.add(project); Set principalSet = new HashSet(); Person person = new Person(); principalSet.add(new PersonPrincipal(person)); Subject subject = new Subject(false, principalSet, new HashSet(), new HashSet()); SecurityHelper.setSubject(support.request, subject); SystemAuthorizer.set(authorizer); }