01: /*
02: * Created on Apr 6, 2003
03: */
04: package net.sf.jportlet.portlet.descriptor;
05:
06: import java.util.ArrayList;
07: import java.util.Collection;
08: import java.util.Iterator;
09:
10: import net.sf.jportlet.util.Constants;
11:
12: /**
13: * The <code>AuthConstraintDescriptor</code> describe the authorization constraint
14: *
15: * @author <a href="mailto:tchbansi@sourceforge.net">Herve Tchepannou</a>
16: */
17: public class AuthConstraintDescriptor {
18: //~ Instance fields --------------------------------------------------------
19:
20: private boolean _allowAnonymous;
21: private String _mode;
22: private Collection _roles = new ArrayList();
23:
24: //~ Methods ----------------------------------------------------------------
25:
26: public void addRole(String role) {
27: _roles.add(role);
28: }
29:
30: public boolean containsRole(String role) {
31: return _roles.contains(role) ? true : _roles
32: .contains(Constants.ALL);
33: }
34:
35: public boolean containsRoles(Collection roles) {
36: if (_roles.contains(Constants.ALL)) {
37: return true;
38: } else {
39: Iterator it = roles.iterator();
40: while (it.hasNext()) {
41: if (containsRole(it.next().toString())) {
42: return true;
43: }
44: }
45:
46: return false;
47: }
48: }
49:
50: /**
51: * @return String
52: */
53: public String getMode() {
54: return _mode;
55: }
56:
57: /**
58: * @return Collection
59: */
60: public Collection getRoles() {
61: return _roles;
62: }
63:
64: /**
65: * @return boolean
66: */
67: public boolean isAllowAnonymous() {
68: return _allowAnonymous;
69: }
70:
71: /**
72: * Sets the allowAnonymous.
73: * @param allowAnonymous The allowAnonymous to set
74: */
75: public void setAllowAnonymous(boolean allowAnonymous) {
76: _allowAnonymous = allowAnonymous;
77: }
78:
79: /**
80: * Sets the mode.
81: * @param mode The mode to set
82: */
83: public void setMode(String mode) {
84: _mode = mode;
85: }
86: }
|