Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
AuthorizationPolicy.inc.php
1 <?php
25 define ('AUTHORIZATION_PERMIT', 0x01);
26 define ('AUTHORIZATION_DENY', 0x02);
27 
28 define ('AUTHORIZATION_ADVICE_DENY_MESSAGE', 0x01);
29 define ('AUTHORIZATION_ADVICE_CALL_ON_DENY', 0x02);
30 
33  var $_advice = array();
34 
39  var $_authorizedContext = array();
40 
41 
46  function AuthorizationPolicy($message = null) {
47  if (!is_null($message)) $this->setAdvice(AUTHORIZATION_ADVICE_DENY_MESSAGE, $message);
48  }
49 
50  //
51  // Setters and Getters
52  //
58  function setAdvice($adviceType, &$adviceContent) {
59  $this->_advice[$adviceType] =& $adviceContent;
60  }
61 
68  function hasAdvice($adviceType) {
69  return isset($this->_advice[$adviceType]);
70  }
71 
77  function &getAdvice($adviceType) {
78  if ($this->hasAdvice($adviceType)) {
79  return $this->_advice[$adviceType];
80  } else {
81  $nullVar = null;
82  return $nullVar;
83  }
84  }
85 
91  function addAuthorizedContextObject($assocType, &$authorizedObject) {
92  $this->_authorizedContext[$assocType] =& $authorizedObject;
93  }
94 
101  function hasAuthorizedContextObject($assocType) {
102  return isset($this->_authorizedContext[$assocType]);
103  }
104 
111  function &getAuthorizedContextObject($assocType) {
112  if ($this->hasAuthorizedContextObject($assocType)) {
113  return $this->_authorizedContext[$assocType];
114  } else {
115  $nullVar = null;
116  return $nullVar;
117  }
118  }
119 
124  function setAuthorizedContext(&$authorizedContext) {
125  $this->_authorizedContext =& $authorizedContext;
126  }
127 
132  function &getAuthorizedContext() {
134  }
135 
136  //
137  // Protected template methods to be implemented by sub-classes
138  //
143  function applies() {
144  // Policies apply by default
145  return true;
146  }
147 
152  function effect() {
153  // Deny by default.
154  return AUTHORIZATION_DENY;
155  }
156 }
157 
158 ?>
AuthorizationPolicy($message=null)
setAuthorizedContext(&$authorizedContext)
& getAuthorizedContextObject($assocType)
addAuthorizedContextObject($assocType, &$authorizedObject)
setAdvice($adviceType, &$adviceContent)
Class to represent an authorization policy.