@Test public void testIsPermitted() { Attribute attribute = new Attribute("myvalue"); Request requestContext = createMock(Request.class); expect(requestContext.isUserInRole("first")).andReturn(Boolean.TRUE) .anyTimes(); expect(requestContext.isUserInRole("second")).andReturn(Boolean.FALSE) .anyTimes(); replay(requestContext); assertTrue(attribute.isPermitted(requestContext)); Set<String> roles = new HashSet<String>(); roles.add("first"); attribute.setRoles(roles); assertTrue("The role is not permitted", attribute.isPermitted( requestContext)); roles.clear(); roles.add("second"); assertFalse("The role is not permitted", attribute.isPermitted( requestContext)); verify(requestContext); }
public boolean isPermitted(Request request) { if (roles == null || roles.isEmpty()) { return true; } boolean retValue = false; for (Iterator<String> roleIt = roles.iterator(); roleIt.hasNext() && !retValue;) { retValue = request.isUserInRole(roleIt.next()); } return retValue; }
Attribute implements Serializable, Cloneable { public boolean isPermitted(Request request) { if (roles == null || roles.isEmpty()) { return true; } boolean retValue = false; for (Iterator<String> roleIt = roles.iterator(); roleIt.hasNext() && !retValue;) { retValue = request.isUserInRole(roleIt.next()); } return retValue; } }
Attribute implements Serializable, Cloneable { public boolean isPermitted(Request request) { if (roles == null || roles.isEmpty()) { return true; } boolean retValue = false; for (Iterator<String> roleIt = roles.iterator(); roleIt.hasNext() && !retValue;) { retValue = request.isUserInRole(roleIt.next()); } return retValue; } Attribute();  Attribute(Object value);  Attribute(Attribute attribute);  Attribute(Object value, String role);  Attribute(Object value, Expression expression, String role, String rendererName); }
Attribute implements Serializable, Cloneable { public boolean isPermitted(Request request) { if (roles == null || roles.isEmpty()) { return true; } boolean retValue = false; for (Iterator<String> roleIt = roles.iterator(); roleIt.hasNext() && !retValue;) { retValue = request.isUserInRole(roleIt.next()); } return retValue; } Attribute();  Attribute(Object value);  Attribute(Attribute attribute);  Attribute(Object value, String role);  Attribute(Object value, Expression expression, String role, String rendererName); static Attribute createTemplateAttribute(String template); static Attribute createTemplateAttribute(String template,
            String templateExpression, String templateType, String role); static Attribute createTemplateAttributeWithExpression(
            String templateExpression); String getRole(); Set<String> getRoles(); void setRole(String role); void setRoles(Set<String> roles); Object getValue(); void setValue(Object value); Expression getExpressionObject(); void setExpressionObject(Expression expressionObject); @Override String toString(); String getRenderer(); void setRenderer(String rendererName); void inherit(Attribute attribute); @Override boolean equals(Object obj); boolean isPermitted(Request request); @Override int hashCode(); @Override Attribute clone(); }
Attribute implements Serializable, Cloneable { public boolean isPermitted(Request request) { if (roles == null || roles.isEmpty()) { return true; } boolean retValue = false; for (Iterator<String> roleIt = roles.iterator(); roleIt.hasNext() && !retValue;) { retValue = request.isUserInRole(roleIt.next()); } return retValue; } Attribute();  Attribute(Object value);  Attribute(Attribute attribute);  Attribute(Object value, String role);  Attribute(Object value, Expression expression, String role, String rendererName); static Attribute createTemplateAttribute(String template); static Attribute createTemplateAttribute(String template,
            String templateExpression, String templateType, String role); static Attribute createTemplateAttributeWithExpression(
            String templateExpression); String getRole(); Set<String> getRoles(); void setRole(String role); void setRoles(Set<String> roles); Object getValue(); void setValue(Object value); Expression getExpressionObject(); void setExpressionObject(Expression expressionObject); @Override String toString(); String getRenderer(); void setRenderer(String rendererName); void inherit(Attribute attribute); @Override boolean equals(Object obj); boolean isPermitted(Request request); @Override int hashCode(); @Override Attribute clone();  }