6 * This class is a representation of a simple principal
8 * Many WebDAV specs require a user to show up in the directory
11 * This principal also has basic ACL settings, only allowing the principal
12 * access it's own principal.
16 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
17 * @author Evert Pot (http://www.rooftopsolutions.nl/)
18 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
20 class Sabre_DAVACL_Principal extends Sabre_DAV_Node implements Sabre_DAVACL_IPrincipal, Sabre_DAV_IProperties, Sabre_DAVACL_IACL {
23 * Struct with principal information.
27 protected $principalProperties;
32 * @var Sabre_DAVACL_IPrincipalBackend
34 protected $principalBackend;
37 * Creates the principal object
39 * @param Sabre_DAVACL_IPrincipalBackend $principalBackend
40 * @param array $principalProperties
42 public function __construct(Sabre_DAVACL_IPrincipalBackend $principalBackend, array $principalProperties = array()) {
44 if (!isset($principalProperties['uri'])) {
45 throw new Sabre_DAV_Exception('The principal properties must at least contain the \'uri\' key');
47 $this->principalBackend = $principalBackend;
48 $this->principalProperties = $principalProperties;
53 * Returns the full principal url
57 public function getPrincipalUrl() {
59 return $this->principalProperties['uri'];
64 * Returns a list of alternative urls for a principal
66 * This can for example be an email address, or ldap url.
70 public function getAlternateUriSet() {
73 if (isset($this->principalProperties['{DAV:}alternate-URI-set'])) {
75 $uris = $this->principalProperties['{DAV:}alternate-URI-set'];
79 if (isset($this->principalProperties['{http://sabredav.org/ns}email-address'])) {
80 $uris[] = 'mailto:' . $this->principalProperties['{http://sabredav.org/ns}email-address'];
83 return array_unique($uris);
88 * Returns the list of group members
90 * If this principal is a group, this function should return
91 * all member principal uri's for the group.
95 public function getGroupMemberSet() {
97 return $this->principalBackend->getGroupMemberSet($this->principalProperties['uri']);
102 * Returns the list of groups this principal is member of
104 * If this principal is a member of a (list of) groups, this function
105 * should return a list of principal uri's for it's members.
109 public function getGroupMembership() {
111 return $this->principalBackend->getGroupMemberShip($this->principalProperties['uri']);
117 * Sets a list of group members
119 * If this principal is a group, this method sets all the group members.
120 * The list of members is always overwritten, never appended to.
122 * This method should throw an exception if the members could not be set.
124 * @param array $groupMembers
127 public function setGroupMemberSet(array $groupMembers) {
129 $this->principalBackend->setGroupMemberSet($this->principalProperties['uri'], $groupMembers);
135 * Returns this principals name.
139 public function getName() {
141 $uri = $this->principalProperties['uri'];
142 list(, $name) = Sabre_DAV_URLUtil::splitPath($uri);
148 * Returns the name of the user
152 public function getDisplayName() {
154 if (isset($this->principalProperties['{DAV:}displayname'])) {
155 return $this->principalProperties['{DAV:}displayname'];
157 return $this->getName();
163 * Returns a list of properties
165 * @param array $requestedProperties
168 public function getProperties($requestedProperties) {
170 $newProperties = array();
171 foreach($requestedProperties as $propName) {
173 if (isset($this->principalProperties[$propName])) {
174 $newProperties[$propName] = $this->principalProperties[$propName];
179 return $newProperties;
184 * Updates this principals properties.
186 * @param array $mutations
187 * @see Sabre_DAV_IProperties::updateProperties
190 public function updateProperties($mutations) {
192 return $this->principalBackend->updatePrincipal($this->principalProperties['uri'], $mutations);
197 * Returns the owner principal
199 * This must be a url to a principal, or null if there's no owner
201 * @return string|null
203 public function getOwner() {
205 return $this->principalProperties['uri'];
211 * Returns a group principal
213 * This must be a url to a principal, or null if there's no owner
215 * @return string|null
217 public function getGroup() {
224 * Returns a list of ACE's for this node.
226 * Each ACE has the following properties:
227 * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
228 * currently the only supported privileges
229 * * 'principal', a url to the principal who owns the node
230 * * 'protected' (optional), indicating that this ACE is not allowed to
235 public function getACL() {
239 'privilege' => '{DAV:}read',
240 'principal' => $this->getPrincipalUrl(),
250 * This method will receive a list of new ACE's.
255 public function setACL(array $acl) {
257 throw new Sabre_DAV_Exception_MethodNotAllowed('Updating ACLs is not allowed here');
262 * Returns the list of supported privileges for this node.
264 * The returned data structure is a list of nested privileges.
265 * See Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet for a simple
266 * standard structure.
268 * If null is returned from this method, the default privilege set is used,
269 * which is fine for most common usecases.
273 public function getSupportedPrivilegeSet() {