[Bedework-commit] r448 - in trunk/calendar3:
access/src/edu/rpi/cct/uwcal/access
appcommon/src/org/bedework/appcommon
calCore/src/org/bedework/calcore/hibernate
test/src/org/bedework/tests/access
webadmin/src/org/bedework/webadmin/system
svnadmin at bedework.org
svnadmin at bedework.org
Thu May 4 15:16:10 EDT 2006
Author: douglm
Date: 2006-05-04 15:16:09 -0400 (Thu, 04 May 2006)
New Revision: 448
Added:
trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/PrivilegeSet.java
Modified:
trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Access.java
trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Ace.java
trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Acl.java
trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/PrivilegeDefs.java
trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Privileges.java
trunk/calendar3/appcommon/src/org/bedework/appcommon/AccessAppUtil.java
trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/AccessUtil.java
trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java
trunk/calendar3/test/src/org/bedework/tests/access/AccessTest.java
trunk/calendar3/webadmin/src/org/bedework/webadmin/system/UpdateSysparsAction.java
Log:
Define new class to hold all allowed privileges
Add code to handle special cases of attempting to access the user calendar root folder or
home directories.
User root should be denied to all except superuser to prevent user browsing
User home directory needs to be limited to read + write-content + writeacl for anybody except
the superuser to prevent users deleting or renaming that directory.
Modified: trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Access.java
===================================================================
--- trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Access.java 2006-05-04 17:23:01 UTC (rev 447)
+++ trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Access.java 2006-05-04 19:16:09 UTC (rev 448)
@@ -57,7 +57,7 @@
import edu.rpi.cct.uwcal.access.Acl.CurrentAccess;
-/** Class to handle access control. Because we may be evaluating access
+/** Class to handle access control. Because we may be evaluating access
* frequently we try do so without creating (many) objects.
*
* <p>This class is created for a session or perhaps a thread and reused to
@@ -109,7 +109,7 @@
acl.addAce(new Ace(null, false, Ace.whoTypeOther, read));
acl.addAce(new Ace(null, false, Ace.whoTypeUnauthenticated, read));
defaultPublicAccess = new String(acl.encode());
-
+
acl.clear();
acl.addAce(new Ace(null, false, Ace.whoTypeOwner, all));
acl.addAce(new Ace(null, false, Ace.whoTypeOther, none));
@@ -118,7 +118,7 @@
throw new RuntimeException(t);
}
}
-
+
/** Constructor
*
* @param debug boolean true fro debug on
@@ -185,13 +185,17 @@
* @param owner String owner of object
* @param how Privilege set definign desired access
* @param aclString String defining current acls for object
+ * @param filter if not null specifies maximum access
* @return CurrentAccess access + allowed/disallowed
* @throws AccessException
*/
public CurrentAccess evaluateAccess(AccessPrincipal who, String owner,
- Privilege[] how, String aclString)
+ Privilege[] how, String aclString,
+ PrivilegeSet filter)
throws AccessException {
- return new Acl(debug).evaluateAccess(who, owner, how, aclString.toCharArray());
+ return new Acl(debug).evaluateAccess(who, owner, how,
+ aclString.toCharArray(),
+ filter);
}
/** convenience method
@@ -200,13 +204,16 @@
* @param owner String owner of object
* @param how Privilege set defining desired access
* @param aclChars char[] defining current acls for object
+ * @param filter if not null specifies maximum access
* @return CurrentAccess access + allowed/disallowed
* @throws AccessException
*/
public CurrentAccess evaluateAccess(AccessPrincipal who, String owner,
- Privilege[] how, char[] aclChars)
+ Privilege[] how, char[] aclChars,
+ PrivilegeSet filter)
throws AccessException {
- return new Acl(debug).evaluateAccess(who, owner, how, aclChars);
+ return new Acl(debug).evaluateAccess(who, owner, how, aclChars,
+ filter);
}
/** convenience method - check for read access
@@ -214,13 +221,16 @@
* @param who Acl.Principal defining who is trying to get access
* @param owner String owner of object
* @param aclChars char[] defining current acls for object
+ * @param filter if not null specifies maximum access
* @return CurrentAccess access + allowed/disallowed
* @throws AccessException
*/
public CurrentAccess checkRead(AccessPrincipal who, String owner,
- char[] aclChars)
+ char[] aclChars,
+ PrivilegeSet filter)
throws AccessException {
- return new Acl(debug).evaluateAccess(who, owner, privSetRead, aclChars);
+ return new Acl(debug).evaluateAccess(who, owner, privSetRead, aclChars,
+ filter);
}
/** convenience method - check for read write access
@@ -228,13 +238,16 @@
* @param who Acl.Principal defining who is trying to get access
* @param owner String owner of object
* @param aclChars char[] defining current acls for object
+ * @param filter if not null specifies maximum access
* @return CurrentAccess access + allowed/disallowed
* @throws AccessException
*/
public CurrentAccess checkReadWrite(AccessPrincipal who, String owner,
- char[] aclChars)
+ char[] aclChars,
+ PrivilegeSet filter)
throws AccessException {
- return new Acl(debug).evaluateAccess(who, owner, privSetReadWrite, aclChars);
+ return new Acl(debug).evaluateAccess(who, owner, privSetReadWrite, aclChars,
+ filter);
}
/** convenience method - check for given access
@@ -243,15 +256,17 @@
* @param owner String owner of object
* @param priv int desired access as defined above
* @param aclChars char[] defining current acls for object
+ * @param filter if not null specifies maximum access
* @return CurrentAccess access + allowed/disallowed
* @throws AccessException
*/
public CurrentAccess evaluateAccess(AccessPrincipal who, String owner,
- int priv, char[] aclChars)
+ int priv, char[] aclChars,
+ PrivilegeSet filter)
throws AccessException {
return new Acl(debug).evaluateAccess(who, owner,
new Privilege[]{Privileges.makePriv(priv)},
- aclChars);
+ aclChars, filter);
}
}
Modified: trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Ace.java
===================================================================
--- trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Ace.java 2006-05-04 17:23:01 UTC (rev 447)
+++ trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Ace.java 2006-05-04 19:16:09 UTC (rev 448)
@@ -165,9 +165,9 @@
private boolean notWho;
- /** array of allowed/denied/undefined indexed by Privilege index
+ /** allowed/denied/undefined indexed by Privilege index
*/
- private char[] how;
+ private PrivilegeSet how;
/** Privilege objects defining the access. Used when manipulating acls
*/
@@ -199,7 +199,7 @@
public Ace(String who,
boolean notWho,
int whoType,
- char[] how) {
+ PrivilegeSet how) {
this.who = who;
this.notWho = notWho;
this.whoType = whoType;
@@ -286,17 +286,17 @@
}
/**
- * @param val char[] array of allowed/denied/undefined indexed by Privilege index
+ * @param val PrivilegeSet of allowed/denied/undefined indexed by Privilege index
*/
- public void setHow(char[] val) {
+ public void setHow(PrivilegeSet val) {
how = val;
}
/**
*
- * @return char[] array of allowed/denied/undefined indexed by Privilege index
+ * @return PrivilegeSet array of allowed/denied/undefined indexed by Privilege index
*/
- public char[] getHow() {
+ public PrivilegeSet getHow() {
return how;
}
@@ -347,12 +347,12 @@
* @param acl
* @param name
* @param whoType
- * @return char[] merged privileges if we find a match else null
+ * @return PrivilegeSet merged privileges if we find a match else null
* @throws AccessException
*/
- public static char[] findMergedPrivilege(Acl acl,
+ public static PrivilegeSet findMergedPrivilege(Acl acl,
String name, int whoType) throws AccessException {
- char[] privileges = null;
+ PrivilegeSet privileges = null;
Iterator it = acl.getAces().iterator();
while (it.hasNext()) {
@@ -362,57 +362,14 @@
((whoType == whoTypeUnauthenticated) ||
(whoType == whoTypeOwner) ||
ace.whoMatch(name))) {
- privileges = mergePrivileges(privileges, ace.getHow(),
- ace.getInherited());
+ privileges = PrivilegeSet.mergePrivileges(privileges, ace.getHow(),
+ ace.getInherited());
}
}
return privileges;
}
- /** If current is null it is set to a cloned copy of morePriv otherwise the
- * privilege(s) in morePriv are merged into current.
- *
- * <p>Specified access overrides inherited access,<br/>
- * allowed overrides denied overrides unspecified so the order is, from
- * highest to lowest:<br/>
- *
- * allowed, denied, allowedInherited, deniedInherited, unspecified.
- *
- * <p>Only allowed and denied appear in encoded aces.
- *
- * @param current
- * @param morePriv
- * @param inherited true if the ace was an inherited ace
- * @return char[] mergedPrivileges
- */
- public static char[] mergePrivileges(char[] current, char[] morePriv,
- boolean inherited) {
- char[] mp = (char[])morePriv.clone();
-
- if (inherited) {
- for (int i = 0; i <= privMaxType; i++) {
- char p = mp[i];
- if (p == allowed) {
- mp[i] = allowedInherited;
- } else if (p == denied) {
- mp[i] = deniedInherited;
- }
- }
- }
- if (current == null) {
- return mp;
- }
-
- for (int i = 0; i <= privMaxType; i++) {
- if (current[i] < mp[i]) {
- current[i] = mp[i];
- }
- }
-
- return current;
- }
-
/* ====================================================================
* Decoding methods
* ==================================================================== */
Modified: trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Acl.java
===================================================================
--- trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Acl.java 2006-05-04 17:23:01 UTC (rev 447)
+++ trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Acl.java 2006-05-04 19:16:09 UTC (rev 448)
@@ -129,7 +129,7 @@
/** Allowed access for each privilege type
* @see PrivilegeDefs
*/
- public char[] privileges = null;
+ public PrivilegeSet privileges = null;
/** Privileges desired */
public Privilege[] desiredAccess;
@@ -182,11 +182,13 @@
* @param owner
* @param how
* @param acl
+ * @param filter if not null specifies maximum access
* @return CurrentAccess access + allowed/disallowed
* @throws AccessException
*/
public CurrentAccess evaluateAccess(AccessPrincipal who, String owner,
- Privilege[] how, char[] acl)
+ Privilege[] how, char[] acl,
+ PrivilegeSet filter)
throws AccessException {
boolean authenticated = !who.getUnauthenticated();
boolean isOwner = false;
@@ -221,7 +223,7 @@
if (isOwner) {
ca.privileges = Ace.findMergedPrivilege(this, null, Ace.whoTypeOwner);
if (ca.privileges == null) {
- ca.privileges = defaultOwnerPrivileges;
+ ca.privileges = PrivilegeSet.makeDefaultOwnerPrivileges();
}
break getPrivileges;
@@ -231,7 +233,7 @@
ca.privileges = Ace.findMergedPrivilege(this, who.getAccount(), Ace.whoTypeUser);
if (ca.privileges != null) {
if (debug) {
- debugsb.append("... For user got: " + new String(ca.privileges));
+ debugsb.append("... For user got: " + ca.privileges);
}
break getPrivileges;
@@ -247,16 +249,16 @@
if (debug) {
debugsb.append("...Try access for group " + group);
}
- char[] privs = Ace.findMergedPrivilege(this, group, Ace.whoTypeGroup);
+ PrivilegeSet privs = Ace.findMergedPrivilege(this, group, Ace.whoTypeGroup);
if (privs != null) {
- ca.privileges = Ace.mergePrivileges(ca.privileges, privs, false);
+ ca.privileges = PrivilegeSet.mergePrivileges(ca.privileges, privs, false);
}
}
}
if (ca.privileges != null) {
if (debug) {
- debugsb.append("...For groups got: " + new String(ca.privileges));
+ debugsb.append("...For groups got: " + ca.privileges);
}
break getPrivileges;
@@ -266,7 +268,7 @@
ca.privileges = Ace.findMergedPrivilege(this, null, Ace.whoTypeOther);
if (ca.privileges != null) {
if (debug) {
- debugsb.append("...For other got: " + new String(ca.privileges));
+ debugsb.append("...For other got: " + ca.privileges);
}
break getPrivileges;
@@ -280,19 +282,14 @@
return ca;
}
- ca.privileges = (char[])ca.privileges.clone();
- for (int pi = 0; pi < ca.privileges.length; pi++) {
- if (ca.privileges[pi] == unspecified) {
- if (isOwner) {
- ca.privileges[pi] = allowed;
- } else {
- ca.privileges[pi] = denied;
- }
- }
+ ca.privileges.setUnspecified(isOwner);
+
+ if (filter != null) {
+ ca.privileges.filterPrivileges(filter);
}
for (int i = 0; i < how.length; i++) {
- char priv = ca.privileges[how[i].getIndex()];
+ char priv = ca.privileges.getPrivilege(how[i].getIndex());
if ((priv != allowed) && (priv != allowedInherited)) {
if (debug) {
@@ -376,7 +373,7 @@
return false;
}
- return aces.remove(new Ace(who, notWho, whoType, (char[])null));
+ return aces.remove(new Ace(who, notWho, whoType, (PrivilegeSet)null));
}
/** Remove access for a given 'who' entry
Modified: trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/PrivilegeDefs.java
===================================================================
--- trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/PrivilegeDefs.java 2006-05-04 17:23:01 UTC (rev 447)
+++ trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/PrivilegeDefs.java 2006-05-04 19:16:09 UTC (rev 448)
@@ -183,7 +183,7 @@
};
/** Default privs for an owner
- */
+ * /
public char[] defaultOwnerPrivileges = {
allowed, // privAll
allowed, // privRead
@@ -200,8 +200,28 @@
allowed, // privNone
};
+ /** User home max privileges for non-super user
+ * This allows us to turn off privileges which would allow delete or rename
+ * for example.
+ * /
+ public char[] userHomeMaxPrivileges = {
+ denied, // privAll
+ allowed, // privRead
+ allowed, // privReadAcl
+ allowed, // privReadCurrentUserPrivilegeSet
+ allowed, // privReadFreeBusy
+ denied, // privWrite
+ allowed, // privWriteAcl
+ allowed, // privWriteProperties
+ allowed, // privWriteContent
+ denied, // privBind
+ denied, // privUnbind
+ allowed, // privUnlock
+ allowed, // privNone
+ };
+
/** Default privs for a non owner
- */
+ * /
public char[] defaultNonOwnerPrivileges = {
denied, // privAll
denied, // privRead
@@ -216,7 +236,7 @@
denied, // privUnbind
denied, // privUnlock
denied, // privNone
- };
+ };*/
}
Added: trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/PrivilegeSet.java
===================================================================
--- trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/PrivilegeSet.java (rev 0)
+++ trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/PrivilegeSet.java 2006-05-04 19:16:09 UTC (rev 448)
@@ -0,0 +1,322 @@
+/*
+ Copyright (c) 2000-2005 University of Washington. All rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+
+ The above copyright notice and this permission notice appear in
+ all copies and supporting documentation;
+
+ The name, identifiers, and trademarks of the University of Washington
+ are not used in advertising or publicity without the express prior
+ written permission of the University of Washington;
+
+ Recipients acknowledge that this distribution is made available as a
+ research courtesy, "as is", potentially with defects, without
+ any obligation on the part of the University of Washington to
+ provide support, services, or repair;
+
+ THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR
+ IMPLIED, WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION
+ ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ PARTICULAR PURPOSE, AND IN NO EVENT SHALL THE UNIVERSITY OF
+ WASHINGTON BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT (INCLUDING
+ NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
+ THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+/* **********************************************************************
+ Copyright 2005 Rensselaer Polytechnic Institute. All worldwide rights reserved.
+
+ Redistribution and use of this distribution in source and binary forms,
+ with or without modification, are permitted provided that:
+ The above copyright notice and this permission notice appear in all
+ copies and supporting documentation;
+
+ The name, identifiers, and trademarks of Rensselaer Polytechnic
+ Institute are not used in advertising or publicity without the
+ express prior written permission of Rensselaer Polytechnic Institute;
+
+ DISCLAIMER: The software is distributed" AS IS" without any express or
+ implied warranty, including but not limited to, any implied warranties
+ of merchantability or fitness for a particular purpose or any warrant)'
+ of non-infringement of any current or pending patent rights. The authors
+ of the software make no representations about the suitability of this
+ software for any particular purpose. The entire risk as to the quality
+ and performance of the software is with the user. Should the software
+ prove defective, the user assumes the cost of all necessary servicing,
+ repair or correction. In particular, neither Rensselaer Polytechnic
+ Institute, nor the authors of the software are liable for any indirect,
+ special, consequential, or incidental damages related to the software,
+ to the maximum extent the law permits.
+*/
+package edu.rpi.cct.uwcal.access;
+
+import java.io.Serializable;
+
+/** Allowed privileges for a principal
+ *
+ * @author Mike Douglass douglm at rpi.edu
+ */
+public class PrivilegeSet implements Serializable, PrivilegeDefs {
+ private char[] privileges;
+
+ /** Default privs for an owner
+ */
+ public static PrivilegeSet defaultOwnerPrivileges =
+ new PrivilegeSet(denied, // privAll
+ denied, // privRead
+ denied, // privReadAcl
+ denied, // privReadCurrentUserPrivilegeSet
+ denied, // privReadFreeBusy
+ denied, // privWrite
+ denied, // privWriteAcl
+ denied, // privWriteProperties
+ denied, // privWriteContent
+ denied, // privBind
+ denied, // privUnbind
+ denied, // privUnlock
+ denied); // privNone
+
+ /** User home max privileges for non-super user
+ * This allows us to turn off privileges which would allow delete or rename
+ * for example.
+ */
+ public static PrivilegeSet userHomeMaxPrivileges =
+ new PrivilegeSet(denied, // privAll
+ allowed, // privRead
+ allowed, // privReadAcl
+ allowed, // privReadCurrentUserPrivilegeSet
+ allowed, // privReadFreeBusy
+ denied, // privWrite
+ allowed, // privWriteAcl
+ allowed, // privWriteProperties
+ allowed, // privWriteContent
+ denied, // privBind
+ denied, // privUnbind
+ allowed, // privUnlock
+ allowed); // privNone
+
+ /** Default privs for a non owner
+ */
+ public static PrivilegeSet defaultNonOwnerPrivileges =
+ new PrivilegeSet(denied, // privAll
+ denied, // privRead
+ denied, // privReadAcl
+ denied, // privReadCurrentUserPrivilegeSet
+ denied, // privReadFreeBusy
+ denied, // privWrite
+ denied, // privWriteAcl
+ denied, // privWriteProperties
+ denied, // privWriteContent
+ denied, // privBind
+ denied, // privUnbind
+ denied, // privUnlock
+ denied); // privNone
+
+ /**
+ * @param privAllState
+ * @param privReadState
+ * @param privReadAclState
+ * @param privReadCurrentUserPrivilegeSetState
+ * @param privReadFreeBusyState
+ * @param privWriteState
+ * @param privWriteAclState
+ * @param privWritePropertiesState
+ * @param privWriteContentState
+ * @param privBindState
+ * @param privUnbindState
+ * @param privUnlockState
+ * @param privNoneState
+ */
+ public PrivilegeSet(char privAllState,
+ char privReadState,
+ char privReadAclState,
+ char privReadCurrentUserPrivilegeSetState,
+ char privReadFreeBusyState,
+ char privWriteState,
+ char privWriteAclState,
+ char privWritePropertiesState,
+ char privWriteContentState,
+ char privBindState,
+ char privUnbindState,
+ char privUnlockState,
+ char privNoneState) {
+ privileges = new char[privMaxType + 1];
+
+ privileges[privAll] = privAllState;
+ privileges[privRead] = privReadState;
+ privileges[privReadAcl] = privReadAclState;
+ privileges[privReadCurrentUserPrivilegeSet] = privReadCurrentUserPrivilegeSetState;
+ privileges[privReadFreeBusy] = privReadFreeBusyState;
+ privileges[privWrite] = privWriteState;
+ privileges[privWriteAcl] = privWriteAclState;
+ privileges[privWriteProperties] = privWritePropertiesState;
+ privileges[privWriteContent] = privWriteContentState;
+ privileges[privBind] = privBindState;
+ privileges[privUnbind] = privUnbindState;
+ privileges[privUnlock] = privUnlockState;
+ privileges[privNone] = privNoneState;
+ }
+
+ /**
+ * @param privileges
+ */
+ public PrivilegeSet(char[] privileges) {
+ this.privileges = privileges;
+ }
+
+ /** Default privs for an owner
+ *
+ * @return PrivilegeSet
+ */
+ public static PrivilegeSet makeDefaultOwnerPrivileges() {
+ return (PrivilegeSet)defaultOwnerPrivileges.clone();
+ }
+
+ /** User home max privileges for non-super user
+ * This allows us to turn off privileges which would allow delete or rename
+ * for example.
+ *
+ * @return PrivilegeSet
+ */
+ public static PrivilegeSet makeUserHomeMaxPrivileges() {
+ return (PrivilegeSet)userHomeMaxPrivileges.clone();
+ }
+
+ /** Default privs for a non owner
+ *
+ * @return PrivilegeSet
+ */
+ public static PrivilegeSet makeDefaultNonOwnerPrivileges() {
+ return (PrivilegeSet)defaultNonOwnerPrivileges.clone();
+ }
+
+ /** Set the given privilege
+ *
+ * @param index
+ * @param val
+ */
+ public void setPrivilege(int index, char val) {
+ if (privileges == null) {
+ privileges = (char[])defaultNonOwnerPrivileges.getPrivileges().clone();
+ }
+
+ privileges[index] = val;
+ }
+
+ /** Get the given privilege
+ *
+ * @param index
+ * @return char
+ */
+ public char getPrivilege(int index) {
+ if (privileges == null) {
+ return unspecified;
+ }
+
+ return privileges[index];
+ }
+
+ /** Ensure thsi privilegeset has no privilege greater than those in the filter
+ *
+ * @param filter
+ */
+ public void filterPrivileges(PrivilegeSet filter) {
+ if (privileges == null) {
+ privileges = (char[])defaultNonOwnerPrivileges.getPrivileges().clone();
+ }
+
+ char[] filterPrivs = filter.getPrivileges();
+
+ for (int pi = 0; pi < privileges.length; pi++) {
+ if (privileges[pi] > filterPrivs[pi]) {
+ privileges[pi] = filterPrivs[pi];
+ }
+ }
+ }
+
+ /** If current is null it is set to a cloned copy of morePriv otherwise the
+ * privilege(s) in morePriv are merged into current.
+ *
+ * <p>Specified access overrides inherited access,<br/>
+ * allowed overrides denied overrides unspecified so the order is, from
+ * highest to lowest:<br/>
+ *
+ * allowed, denied, allowedInherited, deniedInherited, unspecified.
+ *
+ * <p>Only allowed and denied appear in encoded aces.
+ *
+ * @param current
+ * @param morePriv
+ * @param inherited true if the ace was an inherited ace
+ * @return PrivilegeSet mergedPrivileges
+ */
+ public static PrivilegeSet mergePrivileges(PrivilegeSet current,
+ PrivilegeSet morePriv,
+ boolean inherited) {
+ PrivilegeSet mp = (PrivilegeSet)morePriv.clone();
+
+ if (inherited) {
+ for (int i = 0; i <= privMaxType; i++) {
+ char p = mp.getPrivilege(i);
+ if (p == allowed) {
+ mp.setPrivilege(i, allowedInherited);
+ } else if (p == denied) {
+ mp.setPrivilege(i, deniedInherited);
+ }
+ }
+ }
+
+ if (current == null) {
+ return mp;
+ }
+
+ for (int i = 0; i <= privMaxType; i++) {
+ char priv = mp.getPrivilege(i);
+ if (current.getPrivilege(i) < priv) {
+ current.setPrivilege(i, priv);
+ }
+ }
+
+ return current;
+ }
+
+ /** Set all unspecified values to allowed for the owner or denied otherwise.
+ *
+ * @param isOwner
+ */
+ public void setUnspecified(boolean isOwner) {
+ for (int pi = 0; pi < privileges.length; pi++) {
+ if (privileges[pi] == unspecified) {
+ if (isOwner) {
+ privileges[pi] = allowed;
+ } else {
+ privileges[pi] = denied;
+ }
+ }
+ }
+ }
+
+ /**
+ * @return char[] privileges for this object
+ */
+ public char[] getPrivileges() {
+ return privileges;
+ }
+
+ public Object clone() {
+ return new PrivilegeSet((char[])getPrivileges().clone());
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer("PrivilegeSet[");
+
+ sb.append(privileges);
+ sb.append("]");
+
+ return sb.toString();
+ }
+}
+
Modified: trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Privileges.java
===================================================================
--- trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Privileges.java 2006-05-04 17:23:01 UTC (rev 447)
+++ trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Privileges.java 2006-05-04 19:16:09 UTC (rev 448)
@@ -195,7 +195,7 @@
* @return char[] access flags
* @throws AccessException
*/
- public static char[] fromEncoding(EncodedAcl acl) throws AccessException {
+ public static PrivilegeSet fromEncoding(EncodedAcl acl) throws AccessException {
char[] privStates = {
unspecified, // privAll
unspecified, // privRead
@@ -228,7 +228,7 @@
setState(privStates, p, p.getDenial());
}
- return privStates;
+ return new PrivilegeSet(privStates);
}
/** Skip all the privileges info.
Modified: trunk/calendar3/appcommon/src/org/bedework/appcommon/AccessAppUtil.java
===================================================================
--- trunk/calendar3/appcommon/src/org/bedework/appcommon/AccessAppUtil.java 2006-05-04 17:23:01 UTC (rev 447)
+++ trunk/calendar3/appcommon/src/org/bedework/appcommon/AccessAppUtil.java 2006-05-04 19:16:09 UTC (rev 448)
@@ -61,6 +61,7 @@
import edu.rpi.cct.uwcal.access.Acl;
import edu.rpi.cct.uwcal.access.Privilege;
import edu.rpi.cct.uwcal.access.PrivilegeDefs;
+import edu.rpi.cct.uwcal.access.PrivilegeSet;
import edu.rpi.cct.uwcal.access.Privileges;
import edu.rpi.sss.util.xml.QName;
import edu.rpi.sss.util.xml.XmlEmit;
@@ -253,13 +254,15 @@
* of allowed/disallowed/unspecified flags indexed by a privilege index,
* returning the representation a a String
*
- * @param privileges char[] of allowed/disallowed
+ * @param ps PrivilegeSet allowed/disallowed
* @return String xml
* @throws CalFacadeException
*/
- public static String getCurrentPrivSetString(char[] privileges)
+ public static String getCurrentPrivSetString(PrivilegeSet ps)
throws CalFacadeException {
try {
+ char[] privileges = ps.getPrivileges();
+
XmlEmit xml = new XmlEmit(true); // no headers
StringWriter su = new StringWriter();
xml.startEmit(su);
Modified: trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/AccessUtil.java
===================================================================
--- trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/AccessUtil.java 2006-05-04 17:23:01 UTC (rev 447)
+++ trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/AccessUtil.java 2006-05-04 19:16:09 UTC (rev 448)
@@ -57,6 +57,7 @@
import edu.rpi.cct.uwcal.access.Ace;
import edu.rpi.cct.uwcal.access.Acl;
import edu.rpi.cct.uwcal.access.PrivilegeDefs;
+import edu.rpi.cct.uwcal.access.PrivilegeSet;
import edu.rpi.cct.uwcal.access.Acl.CurrentAccess;
import org.bedework.calfacade.base.BwShareableContainedDbentity;
@@ -65,6 +66,7 @@
import org.bedework.calfacade.BwCategory;
import org.bedework.calfacade.BwLocation;
import org.bedework.calfacade.BwSponsor;
+import org.bedework.calfacade.BwSystem;
import org.bedework.calfacade.BwUser;
import org.bedework.calfacade.CalFacadeAccessException;
import org.bedework.calfacade.CalFacadeException;
@@ -92,6 +94,12 @@
private BwUser authUser;
+ private BwSystem syspars;
+
+ private String userRootPath;
+
+ private String userHomePathPrefix;
+
private transient Logger log;
/* Information created and saved about access on a given path.
@@ -141,6 +149,16 @@
public void close() {
}
+ /** Set the system parameters object.
+ * @param val
+ */
+ public void setSyspars(BwSystem val) {
+ syspars = val;
+
+ userRootPath = "/" + syspars.getUserCalendarRoot();
+ userHomePathPrefix = userRootPath + "/";
+ }
+
/* ====================================================================
* Access control
* ==================================================================== */
@@ -248,19 +266,52 @@
*/
try {
- CurrentAccess ca;
+ CurrentAccess ca = null;
+
String account = ent.getOwner().getAccount();
+ PrivilegeSet maxPrivs = null;
- char[] aclChars = getAclChars(ent);
+ char[] aclChars = null;
- if (desiredAccess == privRead) {
- ca = access.checkRead(authUser, account, aclChars);
- } else if (desiredAccess == privWrite) {
- ca = access.checkReadWrite(authUser, account, aclChars);
- } else {
- ca = access.evaluateAccess(authUser, account, desiredAccess, aclChars);
+ if (ent instanceof BwCalendar) {
+ BwCalendar cal = (BwCalendar)ent;
+ String path = cal.getPath();
+
+ if (userRootPath.equals(path)) {
+ ca = new CurrentAccess();
+
+ if (getSuperUser()) {
+ ca.privileges = PrivilegeSet.makeDefaultOwnerPrivileges();
+ } else {
+ ca.privileges = PrivilegeSet.makeDefaultNonOwnerPrivileges();
+ }
+ } else if (path.equals(userHomePathPrefix + account)){
+ // Accessing user home directory
+ if (getSuperUser()) {
+ ca = new CurrentAccess();
+
+ ca.privileges = PrivilegeSet.makeDefaultOwnerPrivileges();
+ } else {
+ // Set the maximumn access
+ maxPrivs = PrivilegeSet.userHomeMaxPrivileges;
+ }
+ }
}
+ if (ca == null) {
+ // Not special
+ aclChars = getAclChars(ent);
+
+ if (desiredAccess == privRead) {
+ ca = access.checkRead(authUser, account, aclChars, maxPrivs);
+ } else if (desiredAccess == privWrite) {
+ ca = access.checkReadWrite(authUser, account, aclChars, maxPrivs);
+ } else {
+ ca = access.evaluateAccess(authUser, account, desiredAccess, aclChars,
+ maxPrivs);
+ }
+ }
+
if ((authUser != null) && superUser) {
// Nobody can stop us - BWAAA HAA HAA
ca.accessAllowed = true;
Modified: trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java
===================================================================
--- trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java 2006-05-04 17:23:01 UTC (rev 447)
+++ trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java 2006-05-04 19:16:09 UTC (rev 448)
@@ -297,6 +297,7 @@
authUser.setGroups(groups.getAllGroups(authUser));
access.setAuthUser(authUser);
+ access.setSyspars((BwSystem)getSyspars().clone());
events = new Events(this, access, currentMode, debug);
@@ -321,6 +322,7 @@
if (userCreated) {
calendars.addNewCalendars(authUser);
}
+
return userCreated;
}
@@ -406,6 +408,8 @@
public void updateSyspars(BwSystem val) throws CalFacadeException {
checkOpen();
sess.update(val);
+ syspars = null; // Force refresh
+ access.setSyspars((BwSystem)getSyspars().clone());
}
public CalTimezones getTimezones() throws CalFacadeException {
Modified: trunk/calendar3/test/src/org/bedework/tests/access/AccessTest.java
===================================================================
--- trunk/calendar3/test/src/org/bedework/tests/access/AccessTest.java 2006-05-04 17:23:01 UTC (rev 447)
+++ trunk/calendar3/test/src/org/bedework/tests/access/AccessTest.java 2006-05-04 19:16:09 UTC (rev 448)
@@ -154,7 +154,8 @@
private void tryEvaluateAccess(BwPrincipal who, BwPrincipal owner,
Privilege[] how,char[] encoded,
boolean expected, String title) throws Throwable {
- CurrentAccess ca = new Acl().evaluateAccess(who, owner.getAccount(), how, encoded);
+ CurrentAccess ca = new Acl().evaluateAccess(who, owner.getAccount(), how,
+ encoded, null);
if (debug) {
log(title + " got " + ca.accessAllowed + " and expected " + expected);
Modified: trunk/calendar3/webadmin/src/org/bedework/webadmin/system/UpdateSysparsAction.java
===================================================================
--- trunk/calendar3/webadmin/src/org/bedework/webadmin/system/UpdateSysparsAction.java 2006-05-04 17:23:01 UTC (rev 447)
+++ trunk/calendar3/webadmin/src/org/bedework/webadmin/system/UpdateSysparsAction.java 2006-05-04 19:16:09 UTC (rev 448)
@@ -65,6 +65,9 @@
/** This action updates the system parameters
*
* <p>Parameters are:<ul>
+ * <li>updateCancelled</li>
+ * <li>admingroupsClass</li>
+ * <li>usergroupsClass</li>
* <li>defaultUserViewName</li>
* <li>directoryBrowsingDisallowed</li>
* <li>httpConnectionsPerUser</li>
More information about the Bedework-commit
mailing list