1 28 29 package com.caucho.server.security; 30 31 import javax.servlet.ServletContext ; 32 import javax.servlet.ServletException ; 33 import javax.servlet.http.HttpServletRequest ; 34 import javax.servlet.http.HttpServletResponse ; 35 import java.io.IOException ; 36 import java.util.ArrayList ; 37 38 public class ContainerConstraint extends AbstractConstraint { 39 private boolean _needsAuthentication; 40 41 private ArrayList <AbstractConstraint> _constraints = 42 new ArrayList <AbstractConstraint>(); 43 44 47 public void addConstraint(AbstractConstraint constraint) 48 { 49 for (AbstractConstraint subConstraint : constraint.toArray()) { 50 _constraints.add(subConstraint); 51 52 if (subConstraint.needsAuthentication()) 53 _needsAuthentication = true; 54 } 55 } 56 57 60 public boolean needsAuthentication() 61 { 62 return _needsAuthentication; 63 } 64 65 79 public boolean isAuthorized(HttpServletRequest request, 80 HttpServletResponse response, 81 ServletContext application) 82 throws ServletException , IOException 83 { 84 for (int i = 0; i < _constraints.size(); i++) { 85 AbstractConstraint constraint = _constraints.get(i); 86 87 if (! constraint.isAuthorized(request, response, application)) 88 return false; 89 } 90 91 return true; 92 } 93 94 97 protected AbstractConstraint []toArray() 98 { 99 return _constraints.toArray(new AbstractConstraint[_constraints.size()]); 100 } 101 } 102 | Popular Tags |