You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by ta...@apache.org on 2006/08/31 09:55:51 UTC
svn commit: r438834 - in /portals/jetspeed-2/trunk/components/portal/src:
java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java
test/org/apache/jetspeed/layout/TestConstraintsAction.java
Author: taylor
Date: Thu Aug 31 00:55:50 2006
New Revision: 438834
URL: http://svn.apache.org/viewvc?rev=438834&view=rev
Log:
bug fixes on security constraints actions
Modified:
portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java
portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestConstraintsAction.java
Modified: portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java?rev=438834&r1=438833&r2=438834&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/java/org/apache/jetspeed/layout/impl/SecurityConstraintsAction.java Thu Aug 31 00:55:50 2006
@@ -41,7 +41,7 @@
*
* AJAX Parameters:
* action = constraints
- * method = add-def | update-def | remove-def | add-global | remove-global
+ * method = add-def | update-def | remove-def | add-global | remove-global
* name = name of constraint definition or global definition
* xml = the constraints payload, same format as PSML constraint defs
*
@@ -118,7 +118,7 @@
}
return success;
}
-
+
protected int removeConstraintDefinition(RequestContext requestContext, Map resultMap)
throws AJAXException
{
@@ -150,6 +150,7 @@
throws AJAXException
{
int count = 0;
+ boolean added = false;
String xml = requestContext.getRequestParameter("xml");
if (xml == null)
throw new AJAXException("Missing 'xml' parameter");
@@ -163,15 +164,25 @@
System.out.println("name = " + name);
PageSecurity pageSecurity = pm.getPageSecurity();
SecurityConstraintsDef def = pageSecurity.getSecurityConstraintsDef(name);
+ int defsSize = 0;
if (def == null)
{
- def = pm.newSecurityConstraintsDef();
+ def = pm.newSecurityConstraintsDef();
+ def.setName(name);
+ added = true;
+ }
+ int xmlSize = root.getChildren("security-constraint").size();
+ if (added == false)
+ {
+ defsSize = def.getSecurityConstraints().size();
}
- int xmlSize = root.getChildren().size();
- int defsSize = def.getSecurityConstraints().size();
int min = (xmlSize < defsSize) ? xmlSize : defsSize;
- List xmlConstraints = root.getChildren();
+ List xmlConstraints = root.getChildren("security-constraint");
List constraints = def.getSecurityConstraints();
+ Element owner = root.getChild("owner");
+ if (owner != null)
+ {
+ }
for (int ix = 0; ix < min; ix++)
{
Element xmlConstraint = (Element)xmlConstraints.get(ix);
@@ -201,10 +212,15 @@
Element xmlConstraint = (Element)xmlConstraints.get(ix);
SecurityConstraint constraint = pm.newPageSecuritySecurityConstraint();
updateConstraintValues(xmlConstraint, constraint);
- constraints.add(constraint);
+ constraints.add(constraint);
count++;
}
}
+ if (added)
+ {
+ pageSecurity.getSecurityConstraintsDefs().add(def);
+ pageSecurity.setSecurityConstraintsDefs(pageSecurity.getSecurityConstraintsDefs());
+ }
pm.updatePageSecurity(pageSecurity);
}
catch (Exception e)
@@ -256,7 +272,7 @@
{
PageSecurity pageSecurity = pm.getPageSecurity();
List globals = pageSecurity.getGlobalSecurityConstraintsRefs();
- if (globals.contains(name))
+ if (!globals.contains(name))
{
return 0;
}
@@ -285,7 +301,6 @@
{
PageSecurity pageSecurity = pm.getPageSecurity();
List globals = pageSecurity.getGlobalSecurityConstraintsRefs();
- ;
if (pageSecurity.getSecurityConstraintsDef(name) == null)
{
throw new AJAXException("global name doesnt exist in definitions");
Modified: portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestConstraintsAction.java
URL: http://svn.apache.org/viewvc/portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestConstraintsAction.java?rev=438834&r1=438833&r2=438834&view=diff
==============================================================================
--- portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestConstraintsAction.java (original)
+++ portals/jetspeed-2/trunk/components/portal/src/test/org/apache/jetspeed/layout/TestConstraintsAction.java Thu Aug 31 00:55:50 2006
@@ -125,6 +125,24 @@
assertEquals("update failed for constraints " + constraint.getPermissions().toString(), constraint.getPermissions().toString(), "[view, edit]");
}
+ public void testAdd()
+ throws Exception
+ {
+ String method = "add-def";
+ String defName = "newone";
+ String xml =
+ "<security-constraints-def name=\"" +
+ defName +
+ "\"><security-constraint><roles>user, manager</roles><permissions>view,edit</permissions></security-constraint></security-constraints-def>";
+ runTest(xml, defName, method);
+ PageSecurity pageSecurity = pageManager.getPageSecurity();
+ SecurityConstraintsDef def = pageSecurity.getSecurityConstraintsDef(defName);
+ assertNotNull("definition " + defName + " not found ", def);
+ SecurityConstraint constraint = (SecurityConstraint)def.getSecurityConstraints().get(0);
+ assertNotNull("first constraint for " + defName + " not found ", def);
+ assertEquals("update failed for constraints " + constraint.getPermissions().toString(), constraint.getPermissions().toString(), "[view, edit]");
+ }
+
public void testAdds()
throws Exception
{
@@ -205,10 +223,25 @@
String xml = "";
runTest(xml, defName, method);
PageSecurity pageSecurity = pageManager.getPageSecurity();
- SecurityConstraintsDef def = pageSecurity.getSecurityConstraintsDef(defName);
List globals = pageSecurity.getGlobalSecurityConstraintsRefs();
assertTrue("should have found new global " + defName, globals.contains(defName));
assertTrue("should have found old global " + defName, globals.contains("admin"));
+ }
+
+ public void testDeleteGlobal()
+ throws Exception
+ {
+ PageSecurity pageSecurity = pageManager.getPageSecurity();
+ String method = "add-global";
+ String defName = "public-edit";
+ String xml = "";
+ runTest(xml, defName, method);
+ List globals = pageSecurity.getGlobalSecurityConstraintsRefs();
+ assertTrue("should have found new global " + defName, globals.contains(defName));
+ method = "remove-global";
+ runTest(xml, defName, method);
+ globals = pageSecurity.getGlobalSecurityConstraintsRefs();
+ assertFalse("should have not found new global " + defName, globals.contains(defName));
}
public void runTest(String xml, String defName, String method)
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@portals.apache.org
For additional commands, e-mail: jetspeed-dev-help@portals.apache.org