cmailleux 2005/10/13 10:37:40 CEST
Modified files:
core/src/java/org/jahia/engines/rights ManageRights.java
Log:
Correct for fields rights management
Revision Changes Path
1.15 +65 -64
jahia/core/src/java/org/jahia/engines/rights/ManageRights.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/core/src/java/org/jahia/engines/rights/ManageRights.java.diff?r1=1.14&r2=1.15&f=h
Index: ManageRights.java
===================================================================
RCS file:
/home/cvs/repository/jahia/core/src/java/org/jahia/engines/rights/ManageRights.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- ManageRights.java 12 Oct 2005 16:25:48 -0000 1.14
+++ ManageRights.java 13 Oct 2005 08:37:40 -0000 1.15
@@ -50,20 +50,20 @@
* @version 1.1
*/
public class ManageRights {
-
+
private static final org.apache.log4j.Logger logger =
org.apache.log4j.Logger.getLogger(ManageRights.class);
-
+
private static ManageRights instance = null;
public static final String JSP_FILE =
"/jsp/jahia/engines/rights/manage_rights.jsp";
// Contains groups which have read access to the current ACL
private final Set readGroups;
-
- // Variable used to store the ACL entries submitted by the user, when a
+
+ // Variable used to store the ACL entries submitted by the user, when a
// refresh is performed due to warnings.
private final HashMap currentAclEntries;
private final Set currentAclEntriesToRemove;
-
+
private int currentInheritance;
private int lastAclIDLoaded = 0;
/**
@@ -75,14 +75,14 @@
}
return instance;
}
-
+
// Don't let anyone instantiate this class
- private ManageRights() {
+ private ManageRights() {
readGroups = new HashSet();
currentAclEntries = new HashMap();
currentAclEntriesToRemove = new HashSet();
}
-
+
/**
*/
public void resetCacheVariables() {
@@ -93,7 +93,7 @@
logger.debug("Cache variables have been emptied");
lastAclIDLoaded = 0;
}
-
+
/**
* @param jParams a ProcessingContext object
* @param mode the mode, according to JahiaEngine
@@ -108,7 +108,7 @@
public EngineValidationHelper handleActions(final ProcessingContext
jParams, final int mode,
final HashMap engineMap, final int aclID)
throws JahiaException, JahiaSessionExpirationException {
-
+
logger.debug("handling mode : " + mode + " for acl " + aclID);
if(lastAclIDLoaded!=aclID) {
resetCacheVariables();
@@ -119,12 +119,12 @@
evh.setPreviousScreen("rightsMgmt");
try {
theACL = new JahiaBaseACL(aclID);
-
+
} catch (ACLNotFoundException ex) {
final ValidationError ve = new ValidationError(this,
ex.getMessage());
evh.addError(ve);
return evh;
-
+
} catch (JahiaException ex) {
final ValidationError ve = new ValidationError(this,
ex.getMessage());
evh.addError(ve);
@@ -135,13 +135,14 @@
switch (mode) {
case (JahiaEngine.LOAD_MODE):
if (loadACLEntries(jParams, engineMap, theACL)) {
+ lastAclIDLoaded = aclID;
return null;
}
final ValidationError ve = new ValidationError(this,
"Cannot load ACL: "+theACL.getID());
evh.addError(ve);
break;
-
+
case (JahiaEngine.UPDATE_MODE):
if (update(jParams, engineMap, theACL)) {
return null;
@@ -150,7 +151,7 @@
"Cannot update ACL: "+theACL.getID());
evh.addError(ve1);
break;
-
+
case (JahiaEngine.SAVE_MODE):
if (saveACLEntries(theACL)){
resetCacheVariables();
@@ -160,7 +161,7 @@
"Cannot save ACL: "+theACL.getID());
evh.addError(ve2);
break;
-
+
case (JahiaEngine.VALIDATE_MODE):
if (validate(jParams, engineMap, theACL)){
return null;
@@ -169,11 +170,11 @@
"Cannot validate ACL: "+theACL.getID());
evh.addError(ve3);
break;
-
+
case (JahiaEngine.CANCEL_MODE):
resetCacheVariables();
return null;
-
+
default:
throw new JahiaException("Unkown mode: "+mode,
"Unkown mode: "+mode,
@@ -184,7 +185,7 @@
lastAclIDLoaded = aclID;
return evh;
}
-
+
/**
* Load all the ACL entries and inherited ACL from parent object and
store the resulting
* principals to an HashSet.
@@ -200,20 +201,20 @@
*/
private boolean loadACLEntries(final ProcessingContext jParams, final
HashMap engineMap,
final JahiaBaseACL acl) throws JahiaException {
- logger.debug("Load ACL entries in ManageRights - AclID: " +
acl.getID());
-
+ logger.debug("Load ACL entries in ManageRights - AclID: " +
acl.getID());
+
final HashMap aclEntries;
logger.debug("currentAclEntries.size: "+ currentAclEntries.size());
if (currentAclEntries.size() == 0) {
-
+
aclEntries = new HashMap();
currentInheritance = acl.getInheritance();
-
+
final JahiaAclEntry aclEntry = new JahiaAclEntry();
aclEntry.setPermission(JahiaBaseACL.READ_RIGHTS,
JahiaAclEntry.ACL_YES);
readGroups.addAll(acl.getGroupnameListNoAdmin(aclEntry));
logger.debug("Loaded readGroups: " + readGroups);
-
+
// Lookup for user ACL entries and inherited ACL
final Vector userList = acl.getUsernameList(null);
final Enumeration userListEnum = userList.elements();
@@ -221,9 +222,9 @@
final String userKey = (String) userListEnum.nextElement();
final JahiaUser user = ServicesRegistry.getInstance().
getJahiaUserManagerService().lookupUser(userKey);
- final Integer[] value = {new Integer(getPermissions(user,
+ final Integer[] value = {new Integer(getPermissions(user,
new Integer(acl.getID())))};
- logger.debug("Loaded value: "+value[0]+ " for user "+
+ logger.debug("Loaded value: "+value[0]+ " for user "+
user);
aclEntries.put(user, value);
}
@@ -236,18 +237,18 @@
getJahiaGroupManagerService().lookupGroup(groupKey);
final Integer[] value = {new Integer(getPermissions(group,
new Integer(acl.getID())))};
- logger.debug("Loaded value: "+value[0]+ " for group "+
+ logger.debug("Loaded value: "+value[0]+ " for group "+
group);
aclEntries.put(group, value);
- }
+ }
currentAclEntries.putAll(aclEntries);
-
+
} else {
aclEntries = currentAclEntries;
}
-
+
final Integer inheritance = new Integer(currentInheritance);
-
+
logger.debug("aclEntries: "+ aclEntries);
logger.debug("inheritance: "+ inheritance);
@@ -258,10 +259,10 @@
engineMap.put("fieldsEditCallingEngineName","managerights_engine");
engineMap.put("managerights_engine.fieldForm",
ServicesRegistry.getInstance().
getJahiaFetcherService().fetchServlet((ParamBean)jParams,
JSP_FILE));
-
+
return true;
}
-
+
/**
*
*/
@@ -270,11 +271,11 @@
/** todo Find a way to obtain an ACL without creating a new object */
try {
acl = new JahiaBaseACL(aclID.intValue());
-
+
} catch (ACLNotFoundException ex) {
logger.error("ACL (ID = " + aclID + ") not found !", ex);
return 0;
-
+
} catch (JahiaException ex) {
logger.error("Problem with ACL (ID = " + aclID + ") !", ex);
return 0;
@@ -299,7 +300,7 @@
permissions += acl.getPermission((JahiaUser) p,
JahiaBaseACL.ADMIN_RIGHTS) ?
4 : 0;
} else {
- permissions += acl.getPermission((JahiaGroup) p,
+ permissions += acl.getPermission((JahiaGroup) p,
JahiaBaseACL.READ_RIGHTS) ? 1 : 0;
permissions += acl.getPermission((JahiaGroup) p,
JahiaBaseACL.WRITE_RIGHTS) ? 2 : 0;
@@ -314,60 +315,60 @@
return 0;
}
}
-
+
/**
*
*/
private boolean validate(final ProcessingContext jParams, final HashMap
engineMap,
final JahiaBaseACL theACL) throws JahiaException {
-
- logger.debug("Validating: "+theACL.getID());
-
+
+ logger.debug("Validating: "+theACL.getID());
+
if (jParams.getParameter("ignoreWarnings") == null &&
theACL.getID() == jParams.getPage().getAclID()) {
// this means that we are updating the ACL of the page, not one
// of its content objects...
-
+
final Map possibleFuture403 = contentObjectsPointingOnPage(
jParams );
final StringBuffer buff = new StringBuffer();
if (possibleFuture403.size() > 0 ) {
try {
final EngineMessages result = new EngineMessages();
-
+
// Keys are Integers representing the pageID
final Iterator keysIte =
possibleFuture403.keySet().iterator();
-
+
while (keysIte.hasNext()) {
final Integer pageIDObj = (Integer)keysIte.next();
final Set set = (Set)
possibleFuture403.get(pageIDObj);
// Set values are ObjectKeys
final Iterator ite = set.iterator();
-
+
while (ite.hasNext()) {
// key = key of the BigText field
(ContentFieldKey)
final ObjectKey key = (ObjectKey)ite.next();
final JahiaObject jahiaObject =
JahiaObject.getInstance(key);
final ContentObject curContentObject =
(ContentObject)jahiaObject;
-
+
final int pageID = (curContentObject instanceof
ContentField) ?
((ContentField)curContentObject).getPageID()
: -1;
-
+
final Collection c =
getFieldGroupsNotHavingAccessOnPage(
jParams.getPageID(), curContentObject);
-
+
if (c.size() > 0) {
final Iterator iteC = c.iterator();
-
+
while (iteC.hasNext()) {
final String groupID =
(String)iteC.next();
buff.append(groupID).append(",");
}
-
+
if (buff.length() > 0) {
buff.deleteCharAt(buff.length() - 1);
}
-
+
final EngineMessage msg;
if (pageIDObj.intValue() ==
jParams.getPageID()) {
msg = new EngineMessage(
@@ -383,7 +384,7 @@
}
}
}
-
+
if ( !result.isEmpty() ) {
result.saveMessages("manageRights.warning.",
((ParamBean)jParams).getRequest());
@@ -391,7 +392,7 @@
engineMap.put("rightsUpdated", Boolean.FALSE);
return false;
}
-
+
} catch (ClassNotFoundException cnfe) {
logger.error(
"Error while loading content object", cnfe);
@@ -399,10 +400,10 @@
}
}
}
-
+
return true;
}
-
+
/**
* @param jParams a Parambean object
* @param engineMap the engine parameters stored in a HashMap
@@ -412,18 +413,18 @@
*/
private boolean update(final ProcessingContext jParams, final HashMap
engineMap,
final JahiaBaseACL theACL) throws JahiaException {
-
+
final String theScreen = (String) engineMap.get("screen");
if ( theScreen.equals("cancel") ) {
return true;
}
logger.debug("Update (aclID = "+theACL.getID()+")");
-
+
if (! processUserValues(jParams, theACL)) {
return false;
}
logger.debug("Read Groups: "+readGroups);
-
+
if ( validate(jParams, engineMap, theACL) ) {
engineMap.put("rightsUpdated", Boolean.TRUE);
return true;
@@ -431,7 +432,7 @@
engineMap.put("rightsUpdated", Boolean.FALSE);
return false;
}
-
+
/**
*
*/
@@ -439,23 +440,23 @@
final JahiaBaseACL acl) throws JahiaException {
// Check if the inheritance has to be permanently prevent or not.
logger.debug("processUserValues: "+acl.getID());
-
+
final String cutRestAllInherit =
jParams.getParameter("cutRestAllInherit");
-
+
logger.debug("cutRestAllInherit: "+ cutRestAllInherit);
if (cutRestAllInherit != null) { // Is the check box checked ?
if (acl.getInheritance() == ACLInfo.INHERITANCE) { // Has it
changed ?
logger.debug("currentInheritance = ACLInfo.NO_INHERITANCE");
- currentInheritance = ACLInfo.NO_INHERITANCE;
+ currentInheritance = ACLInfo.NO_INHERITANCE;
}
-
+
} else {
if (acl.getInheritance() == ACLInfo.NO_INHERITANCE) { // Has the
checkbox changed ?
logger.debug("currentInheritance = ACLInfo.INHERITANCE");
currentInheritance = ACLInfo.INHERITANCE;
}
}
-
+
final String[] submitedACLEntries = jParams.
getParameterValues("aclEntries");
final Integer userNameWidth = (Integer) jParams.getSessionState().
@@ -465,11 +466,11 @@
readGroups.clear();
return true;
}
-
+
for (int i = 0; i < submitedACLEntries.length; i++) {
if ("00000000".equals(submitedACLEntries[i].substring(0, 8))) {
logger.debug("No change to AclEntry:
"+submitedACLEntries[i]);
-
+
continue; // Don't do anything if no changes to the ACL
entry.
}
// What kind of object has to be saved : user or group ?