paulsp 2002/06/04 10:38:39
Modified: src/java/org/apache/jetspeed/om/registry Tag: security_14
RegistryEntry.java SecurityEntry.java
src/java/org/apache/jetspeed/om/registry/base Tag:
security_14 BaseRegistryEntry.java
BaseSecurityEntry.java
src/java/org/apache/jetspeed/services/registry Tag:
security_14 TestMarshallRegistry.java
webapp/WEB-INF/conf Tag: security_14 registry.xml
webapp/WEB-INF/psml/test Tag: security_14
testcase-security.xreg
Log:
o Add SecurityReference support to registry entries
o Add getter/setters required by BaseRegistryEntry interface to SecurityEntry
and BaseSecurityEntry
o Add allowRole() and allowUser() to SecurityEntry.
o Update unittest
Revision Changes Path
No revision
No revision
1.7.2.1 +15 -1
jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/RegistryEntry.java
Index: RegistryEntry.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/RegistryEntry.java,v
retrieving revision 1.7
retrieving revision 1.7.2.1
diff -u -r1.7 -r1.7.2.1
--- RegistryEntry.java 1 Apr 2002 23:16:53 -0000 1.7
+++ RegistryEntry.java 4 Jun 2002 17:38:37 -0000 1.7.2.1
@@ -54,15 +54,19 @@
package org.apache.jetspeed.om.registry;
+// Java imports
import java.util.Locale;
+// Jetspeed imports
+import org.apache.jetspeed.om.SecurityReference;
+
/**
* RegistryEntry is the base interface that objects must implement in order
* to be used with the Registry service.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Rapha�l Luta</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Kevin A. Burton</a>
- * @version $Id: RegistryEntry.java,v 1.7 2002/04/01 23:16:53 taylor Exp $
+ * @version $Id: RegistryEntry.java,v 1.7.2.1 2002/06/04 17:38:37 paulsp Exp $
*/
public interface RegistryEntry
{
@@ -141,4 +145,14 @@
*/
public void setHidden(boolean hidden);
+ /** Getter for property securityRef.
+ * @return Value of property securityRef.
+ */
+ public SecurityReference getSecurityRef();
+
+ /** Setter for property securityRef.
+ * @param securityRef New value of property securityRef.
+ */
+ public void setSecurityRef(SecurityReference securityRef);
+
}
1.1.2.2 +88 -11
jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/Attic/SecurityEntry.java
Index: SecurityEntry.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/Attic/SecurityEntry.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- SecurityEntry.java 3 Jun 2002 04:17:24 -0000 1.1.2.1
+++ SecurityEntry.java 4 Jun 2002 17:38:37 -0000 1.1.2.2
@@ -57,26 +57,20 @@
// Java imports
import java.util.Vector;
+// Jetspeed imports
+import org.apache.jetspeed.om.SecurityReference;
+import org.apache.jetspeed.om.registry.MetaInfo;
+
/**
* Interface for manipulatin the security entries on the registry entries
*
*
* @author <a href="mailto:[EMAIL PROTECTED]">Paul Spencer</a>
- * @version $Id: SecurityEntry.java,v 1.1.2.1 2002/06/03 04:17:24 paulsp Exp $
+ * @version $Id: SecurityEntry.java,v 1.1.2.2 2002/06/04 17:38:37 paulsp Exp $
*/
public interface SecurityEntry {
- /** Getter for property id.
- * @return Value of property id.
- */
- public String getId();
-
- /** Setter for property id.
- * @param id New value of property id.
- */
- public void setId(String id);
-
/** Getter for property accesses.
* @return Value of property accesses.
*/
@@ -86,5 +80,88 @@
* @param accesses New value of property accesses.
*/
public void setAccesses(Vector accesses);
+
+ /** Getter for property name.
+ * @return Value of property name.
+ */
+ public String getName();
+
+ /** Setter for property name.
+ * @param name New value of property name.
+ */
+ public void setName(String name);
+
+ /** Getter for property description.
+ * @return Value of property description.
+ */
+ public String getDescription();
+
+ /** Setter for property description.
+ * @param description New value of property description.
+ */
+ public void setDescription(String description);
+
+ /** Getter for property securityRef.
+ * @return Value of property securityRef.
+ */
+ public SecurityReference getSecurityRef();
+
+ /** Setter for property securityRef.
+ * @param securityRef New value of property securityRef.
+ */
+ public void setSecurityRef(SecurityReference securityRef);
+
+ /** Getter for property title.
+ * @return Value of property title.
+ */
+ public String getTitle();
+
+ /** Setter for property title.
+ * @param title New value of property title.
+ */
+ public void setTitle(String title);
+
+ /** Getter for property metaInfo.
+ * @return Value of property metaInfo.
+ */
+ public MetaInfo getMetaInfo();
+
+ /** Setter for property metaInfo.
+ * @param metaInfo New value of property metaInfo.
+ */
+ public void setMetaInfo(MetaInfo metaInfo);
+
+ /** Getter for property hidden.
+ * @return Value of property hidden.
+ */
+ public boolean isHidden();
+
+ /** Setter for property hidden.
+ * @param hidden New value of property hidden.
+ */
+ public void setHidden(boolean hidden);
+
+ /** Getter for property id.
+ * @return Value of property id.
+ */
+ public long getId();
+
+ /**
+ * Aututhorizes action for a role
+ *
+ * @param role requesting action
+ * @param action being requested
+ * @return <CODE>true</CODE> if action is allowed for role
+ */
+ public boolean allowsRole(String role, String action);
+
+ /**
+ * Aututhorizes action for a named user
+ *
+ * @param userName requesting action
+ * @param action being requested
+ * @return <CODE>true</CODE> if action is allowed for named user
+ */
+ public boolean allowsUser(String userName, String action);
}
No revision
No revision
1.4.2.1 +29 -3
jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/BaseRegistryEntry.java
Index: BaseRegistryEntry.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/BaseRegistryEntry.java,v
retrieving revision 1.4
retrieving revision 1.4.2.1
diff -u -r1.4 -r1.4.2.1
--- BaseRegistryEntry.java 1 Apr 2002 23:16:53 -0000 1.4
+++ BaseRegistryEntry.java 4 Jun 2002 17:38:37 -0000 1.4.2.1
@@ -54,16 +54,23 @@
package org.apache.jetspeed.om.registry.base;
-import org.apache.jetspeed.om.registry.*;
+// Java imports
import java.util.Vector;
import java.util.Locale;
+// Jetspeed imports
+import org.apache.jetspeed.om.SecurityReference;
+import org.apache.jetspeed.om.registry.MetaInfo;
+import org.apache.jetspeed.om.registry.Security;
+import org.apache.jetspeed.om.registry.RegistryEntry;
+//import org.apache.jetspeed.om.registry.*;
+
/**
* Base simple bean-like implementation of the RegistryEntry interface
* suitable for Castor XML serialization.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Rapha�l Luta</a>
- * @version $Id: BaseRegistryEntry.java,v 1.4 2002/04/01 23:16:53 taylor Exp $
+ * @version $Id: BaseRegistryEntry.java,v 1.4.2.1 2002/06/04 17:38:37 paulsp Exp $
*/
public abstract class BaseRegistryEntry implements RegistryEntry,
java.io.Serializable
{
@@ -79,6 +86,9 @@
protected int _hidden;
+ /** Holds value of property securityRef. */
+ protected SecurityReference securityRef = null;
+
public BaseRegistryEntry()
{}
@@ -257,10 +267,26 @@
this.image = metaInfo.getImage();
}
-
+ /** Getter for property securityId.
+ * @return Value of property securityId.
+ */
+ public SecurityReference getSecurityRef()
+ {
+ return securityRef;
+ }
+
+ /** Setter for property securityId.
+ * @param securityId New value of property securityId.
+ */
+ public void setSecurityRef(SecurityReference securityRef)
+ {
+ this.securityRef = securityRef;
+ }
+
// OJB - can't seem to get embedded objects to work without this hack
String title;
String description;
String image;
String role;
+
}
1.1.2.2 +160 -21
jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/Attic/BaseSecurityEntry.java
Index: BaseSecurityEntry.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/om/registry/base/Attic/BaseSecurityEntry.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- BaseSecurityEntry.java 3 Jun 2002 04:17:24 -0000 1.1.2.1
+++ BaseSecurityEntry.java 4 Jun 2002 17:38:37 -0000 1.1.2.2
@@ -55,44 +55,43 @@
package org.apache.jetspeed.om.registry.base;
// Java imports
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
import java.util.Vector;
// Jetspeed imports
+import org.apache.jetspeed.om.registry.SecurityAccess;
+import org.apache.jetspeed.om.registry.SecurityAllow;
import org.apache.jetspeed.om.registry.SecurityEntry;
+import org.apache.jetspeed.om.registry.base.BaseRegistryEntry;
/**
* Interface for manipulatin the Security Entry on the registry entries
*
* @author <a href="mailto:[EMAIL PROTECTED]">Paul Spencer</a>
- * @version $Id: BaseSecurityEntry.java,v 1.1.2.1 2002/06/03 04:17:24 paulsp Exp $
+ * @version $Id: BaseSecurityEntry.java,v 1.1.2.2 2002/06/04 17:38:37 paulsp Exp $
*/
-public class BaseSecurityEntry implements SecurityEntry, java.io.Serializable
+public class BaseSecurityEntry extends BaseRegistryEntry implements SecurityEntry,
java.io.Serializable
{
- /** Holds value of property id. */
- private String id;
-
/** Holds value of property accesses. */
private Vector accesses;
- public BaseSecurityEntry()
- {}
+ private Map accessMap = null;
- /** Getter for property id.
- * @return Value of property id.
- */
- public String getId()
- {
- return id;
- }
+ public static final String ALL_ACTIONS = "*";
- /** Setter for property id.
- * @param id New value of property id.
- */
- public void setId(String id)
- {
- this.id = id;
- }
+ public static final String ALL_ROLES = "*";
+
+ public static final String ALL_USERS = "*";
+
+ private static final String ROLE_MAP = "role";
+
+ private static final String USER_MAP = "user";
+
+ public BaseSecurityEntry()
+ {}
/** Getter for property accesses.
* @return Value of property accesses.
@@ -108,6 +107,146 @@
public void setAccesses(Vector accesses)
{
this.accesses = accesses;
+ }
+
+ /**
+ * Aututhorizes action for a role.
+ *
+ * o If the requested action and the action ALL_ACTIONS
+ * do not exist, then return false.
+ *
+ * o If the requesting role and ALL_ROLES does not exist for the
+ * the action, then return false.
+ *
+ * @param role requesting action
+ * @param action being requested
+ * @return <CODE>true</CODE> if action is allowed for role
+ */
+ public boolean allowsRole(String role, String action)
+ {
+ if (accessMap == null)
+ buildAccessMap();
+
+ Map allowMap = (Map) accessMap.get(action);
+ if (allowMap == null)
+ {
+ allowMap = (Map) accessMap.get(ALL_ACTIONS);
+ if (allowMap == null)
+ return false;
+ }
+ Map allowRoleMap = (Map) allowMap.get(ROLE_MAP);
+ if (allowRoleMap == null)
+ return false;
+
+ boolean allow = allowRoleMap.containsKey( role);
+ if ( allow == false)
+ allow = allowRoleMap.containsKey( ALL_ROLES);
+ return allow;
+ }
+
+ /**
+ * Aututhorizes action for a named user
+ *
+ * @param userName requesting action
+ * @param action being requested
+ * @return <CODE>true</CODE> if action is allowed for named user
+ */
+ public boolean allowsUser(String userName, String action)
+ {
+ if (accessMap == null)
+ buildAccessMap();
+
+ Map allowMap = (Map) accessMap.get(action);
+ if (allowMap == null)
+ {
+ allowMap = (Map) accessMap.get(ALL_ACTIONS);
+ if (allowMap == null)
+ return false;
+ }
+ Map allowUserMap = (Map) allowMap.get(USER_MAP);
+ if (allowUserMap == null)
+ return false;
+
+ boolean allow = allowUserMap.containsKey( userName);
+ if ( allow == false)
+ allow = allowUserMap.containsKey( ALL_USERS);
+ return allow;
+ }
+
+ private void buildAccessMap()
+ {
+ Map actionMap = null;
+ SecurityAccess accessElement = null;
+
+ if (accessMap == null)
+ accessMap = new HashMap();
+
+ accessMap.clear();
+
+ // Build allow map
+ for ( Iterator accessIterator = getAccesses().iterator();
accessIterator.hasNext();)
+ {
+ accessElement = (SecurityAccess) accessIterator.next();
+
+ // Get action map of the action. Create one if none exists
+ String action = accessElement.getAction();
+ if (action == null)
+ action = ALL_ACTIONS;
+
+ actionMap = (Map) accessMap.get(action );
+ if (actionMap == null)
+ {
+ actionMap = new HashMap();
+ accessMap.put(action, actionMap);
+ }
+ addAllows( actionMap, accessElement);
+ }
+ }
+
+ private void addAllows(Map accessMap, SecurityAccess accessElement)
+ {
+ SecurityAllow allowElement = null;
+ String role = null;
+ Map roleMap = null; // Map of roles allowed
+ Map userMap = null; // Map of users allowed
+ String userName = null;
+
+ if (accessElement.getAllows() == null)
+ return;
+
+ // Add allows to the action Map
+ for ( Iterator allowIterator = accessElement.getAllows().iterator();
allowIterator.hasNext();)
+ {
+ allowElement = (SecurityAllow) allowIterator.next();
+ role = null;
+ userName = null;
+
+ // Add Role
+ role = allowElement.getRole();
+ if (role != null)
+ {
+ roleMap = (Map) accessMap.get(ROLE_MAP);
+ if (roleMap == null)
+ {
+ roleMap = new HashMap();
+ accessMap.put(ROLE_MAP, roleMap);
+ }
+ roleMap.put(role, null);
+ }
+
+ // Add User
+ userName = allowElement.getUser();
+ if (userName != null)
+ {
+ userMap = (Map) accessMap.get(USER_MAP);
+ if (userMap == null)
+ {
+ userMap = new HashMap();
+ accessMap.put(USER_MAP, userMap);
+ }
+ userMap.put(userName, null);
+ }
+ }
}
}
No revision
No revision
1.3.2.2 +119 -196
jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/TestMarshallRegistry.java
Index: TestMarshallRegistry.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/src/java/org/apache/jetspeed/services/registry/TestMarshallRegistry.java,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -u -r1.3.2.1 -r1.3.2.2
--- TestMarshallRegistry.java 3 Jun 2002 04:17:23 -0000 1.3.2.1
+++ TestMarshallRegistry.java 4 Jun 2002 17:38:37 -0000 1.3.2.2
@@ -76,6 +76,7 @@
import org.xml.sax.InputSource;
import org.apache.jetspeed.om.registry.*;
+import org.apache.jetspeed.om.SecurityReference;
import org.apache.turbine.services.TurbineServices;
import org.apache.jetspeed.services.idgenerator.*;
@@ -88,7 +89,7 @@
* TestMarshallRegistry
*
* @author <a href="[EMAIL PROTECTED]">David Sean Taylor</a>
- * @version $Id: TestMarshallRegistry.java,v 1.3.2.1 2002/06/03 04:17:23 paulsp Exp
$
+ * @version $Id: TestMarshallRegistry.java,v 1.3.2.2 2002/06/04 17:38:37 paulsp Exp
$
*/
public class TestMarshallRegistry extends TestCase {
@@ -350,215 +351,137 @@
File map = new File(mapFile);
if (map.exists() && map.isFile() && map.canRead())
{
- try
+ FileReader reader = new FileReader(xregFile);
+ mapping = new Mapping();
+ InputSource is = new InputSource( new FileReader(map) );
+ is.setSystemId( mapFile );
+ mapping.loadMapping( is );
+ Unmarshaller unmarshaller = new Unmarshaller(mapping);
+ RegistryFragment fragment =
(RegistryFragment)unmarshaller.unmarshal(reader);
+ assertNotNull(fragment);
+ Vector securityEntries = fragment.getSecurityEntries();
+ assertTrue( "Security Entries exist", !securityEntries.isEmpty());
+
+ // test abstract
+ SecurityEntry securityEntry =
(SecurityEntry)securityEntries.firstElement();
+ assertNotNull("Got first Security Entry", securityEntry);
+ assertTrue("Getting expect security
entry",securityEntry.getName().equals("basic_testcase"));
+
+ // Get the action
+ Vector securityAccesses = securityEntry.getAccesses();
+ assertNotNull( "Got SecurityAccesses", securityAccesses);
+ SecurityAccess securityAccess = (SecurityAccess)
securityAccesses.firstElement();
+ assertNotNull( "Got SecurityAccess", securityAccess);
+ assertEquals( "Verify action", "view", securityAccess.getAction());
+
+ // Get allows
+ Vector securityAllows = securityAccess.getAllows();
+ assertNotNull( "Got SecurityAllows", securityAllows);
+ SecurityAllow securityAllow = (SecurityAllow)
securityAllows.firstElement();
+ assertNotNull( "Got SecurityAllow", securityAllow);
+ assertEquals( "Verify role", "clerk", securityAllow.getRole());
+ assertNull( "Verify user" , securityAllow.getUser());
+
+ securityAllow = (SecurityAllow) securityAllows.elementAt(1);
+ assertNotNull( "Got SecurityAllow", securityAllow);
+ assertNull( "Verify role", securityAllow.getRole());
+ assertEquals( "Verify user", "joe" , securityAllow.getUser());
+
+ securityAllow = (SecurityAllow) securityAllows.elementAt(2);
+ assertNotNull( "Got SecurityAllow", securityAllow);
+ assertEquals( "Verify role", "manager", securityAllow.getRole());
+ assertEquals( "Verify user", "fred" , securityAllow.getUser());
+
+ // test allows
+ assertEquals( "clerk role can view", true,
securityEntry.allowsRole("clerk","view"));
+ assertEquals( "manager role can view", true,
securityEntry.allowsRole("manager","view"));
+ assertEquals( "anonymous role can NOT view", false,
securityEntry.allowsRole("anonymous","view"));
+ assertEquals( "fred user can view", true,
securityEntry.allowsUser("fred","view"));
+ assertEquals( "joe user can view", true,
securityEntry.allowsUser("joe","view"));
+ assertEquals( "anonymous user can NOT view", false,
securityEntry.allowsUser("anonymous","view"));
+
+ // Customize has <allow-id user="*"/>
+ assertEquals( "clerk role can NOT customize", false,
securityEntry.allowsRole("clerk","customize"));
+ assertEquals( "joe user can customize", true,
securityEntry.allowsUser("joe","customize"));
+
+ // Minimize has no <allows-if .../>
+ assertEquals( "clerk role can NOT minimize", false,
securityEntry.allowsRole("clerk","minimize"));
+ assertEquals( "joe user can NOT minimize", false,
securityEntry.allowsUser("joe","minimize"));
+
+ // Maximixe is not defined
+ assertEquals( "clerk role can NOT minimize", false,
securityEntry.allowsRole("clerk","minimize"));
+ assertEquals( "joe user can NOT minimize", false,
securityEntry.allowsUser("joe","minimize"));
+
+ // Test the wide-open entry
+ boolean entryFound = false;
+ for (Iterator securityIterator = securityEntries.iterator();
securityIterator.hasNext();)
{
- FileReader reader = new FileReader(xregFile);
- mapping = new Mapping();
- InputSource is = new InputSource( new FileReader(map) );
- is.setSystemId( mapFile );
- mapping.loadMapping( is );
- Unmarshaller unmarshaller = new Unmarshaller(mapping);
- RegistryFragment fragment =
(RegistryFragment)unmarshaller.unmarshal(reader);
- assertNotNull(fragment);
- Vector securityEntries = fragment.getSecurityEntries();
- assertTrue( "Security Entries exist", !securityEntries.isEmpty());
-
- // test abstract
- SecurityEntry securityEntry =
(SecurityEntry)securityEntries.firstElement();
- assertNotNull(securityEntry);
- assertTrue(securityEntry.getId().equals("admin-all"));
-
- // Get the action
- Vector securityAccesses = securityEntry.getAccesses();
- assertNotNull( "Got SecurityAccesses", securityAccesses);
- SecurityAccess securityAccess = (SecurityAccess)
securityAccesses.firstElement();
- assertNotNull( "Got SecurityAccess", securityAccess);
- assertEquals( "Verify action", "view", securityAccess.getAction());
-
- // Get allows
- Vector securityAllows = securityAccess.getAllows();
- assertNotNull( "Got SecurityAllows", securityAllows);
- SecurityAllow securityAllow = (SecurityAllow)
securityAllows.firstElement();
- assertNotNull( "Got SecurityAllow", securityAllow);
- assertEquals( "Verify role", "clerk", securityAllow.getRole());
- assertNull( "Verify user" , securityAllow.getUser());
-
- securityAllow = (SecurityAllow) securityAllows.elementAt(1);
- assertNotNull( "Got SecurityAllow", securityAllow);
- assertNull( "Verify role", securityAllow.getRole());
- assertEquals( "Verify user", "joe" , securityAllow.getUser());
-
- securityAllow = (SecurityAllow) securityAllows.elementAt(2);
- assertNotNull( "Got SecurityAllow", securityAllow);
- assertEquals( "Verify role", "manager", securityAllow.getRole());
- assertEquals( "Verify user", "fred" , securityAllow.getUser());
-/*
- Iterator it = securityEntry.getAccesses();
- HashMap mapParams = new HashMap();
- while (it.hasNext())
- {
- String name = (String)it.next();
- Parameter p = securityEntry.getParameter(name);
- assertNotNull(p);
- //System.out.println("PARAM:" + p.getName() + " = " +
p.getValue());
- mapParams.put(p.getName(), p);
- }
- assertTrue(mapParams.containsKey("showtitle"));
- assertTrue(mapParams.containsKey("stylesheet"));
- assertTrue(mapParams.containsKey("itemdisplayed"));
-
- // test ref
- PortletEntry hack = (PortletEntry)portlets.elementAt(2);
- assertNotNull(hack);
- assertTrue(hack.getName().equals("XMLHack"));
- assertTrue(hack.isHidden());
- assertTrue(hack.getType().equals("ref"));
- assertTrue(hack.getParent().equals("RSS"));
- assertTrue(!hack.isApplication());
- assertTrue(hack.getTitle().equals("XMLHack Title"));
- assertTrue(hack.getDescription().equals("XMLHack Description"));
- assertTrue(hack.getMetaInfo().getTitle().equals("XMLHack Title"));
- assertTrue(hack.getMetaInfo().getDescription().equals("XMLHack
Description"));
-
assertTrue(hack.getClassname().equals("org.apache.jetspeed.portal.portlets.NewRSSPortlet"));
-
- mapParams.clear();
- it = hack.getParameterNames();
- while (it.hasNext())
+ securityEntry = (SecurityEntry)securityIterator.next();
+ if (securityEntry.getName().equals("wide_open") == true)
{
- String name = (String)it.next();
- Parameter p = hack.getParameter(name);
- assertNotNull(p);
- //System.out.println("HACK PARAM:" + p.getName() + " = " +
p.getValue());
- mapParams.put(p.getName(), p);
+ entryFound = true;
+ assertEquals( "any role can is NOT allowed", false,
securityEntry.allowsRole("customer","do_any_thing"));
+ assertEquals( "any role can is allowed", true,
securityEntry.allowsUser("joe_customer","do_any_thing"));
}
- assertTrue(mapParams.containsKey("showtitle"));
- assertTrue(mapParams.containsKey("stylesheet"));
- assertTrue(mapParams.containsKey("itemdisplayed"));
- assertTrue(mapParams.containsKey("HACK"));
- Parameter p = (Parameter)mapParams.get("HACK");
- assertTrue(p.getValue().equals("hacker"));
- Parameter p2 = (Parameter)mapParams.get("showtitle");
- MetaInfo p2m = p2.getMetaInfo();
- assertTrue(p2m.getTitle().equals("Show title description ?"));
- assertTrue(p2.getTitle().equals("Show title description ?"));
- Map pMap = hack.getParameterMap();
- String v15 = (String)pMap.get("itemdisplayed");
- assertTrue(v15.equals("15"));
+ }
+ assertTrue("Found wide_open security entry", entryFound);
+ }
+ }
- // test falling back on meta info
+ public void testUnmarshallSecurityReference() throws Exception
+ {
+ System.out.println("Testing marshalling of Registry security-ref");
- PortletEntry mp = (PortletEntry)portlets.elementAt(5);
- assertNotNull(mp);
- assertTrue(mp.getName().equals("MetaTest"));
- assertTrue(mp.getType().equals("ref"));
- assertTrue(mp.getParent().equals("AdminScreen"));
-
assertTrue(mp.getClassname().equals("org.apache.jetspeed.portal.portlets.TurbineScreenPortlet"));
- String title = mp.getTitle();
- assertNotNull(title);
- assertTrue(title.equals("Turbine Screen in a portlet"));
- assertTrue(mp.getDescription().equals("We put the Admin Screen in a
portlet."));
- MetaInfo meta = mp.getMetaInfo();
- assertNotNull(meta);
- assertTrue(mp.getMetaInfo().getTitle().equals("Turbine Screen in a
portlet"));
- assertTrue(meta.getDescription().equals("We put the Admin Screen in
a portlet."));
+ String xregFile = "../webapp/WEB-INF/psml/test/testcase-security.xreg";
- // media type
- Iterator mpi = mp.listMediaTypes();
- assertNotNull(mpi);
- HashMap mpMap = new HashMap();
- while(mpi.hasNext())
+ Mapping mapping = null;
+ String mapFile = getMappingFileName();
+ File map = new File(mapFile);
+ if (map.exists() && map.isFile() && map.canRead())
+ {
+ FileReader reader = new FileReader(xregFile);
+ mapping = new Mapping();
+ InputSource is = new InputSource( new FileReader(map) );
+ is.setSystemId( mapFile );
+ mapping.loadMapping( is );
+ Unmarshaller unmarshaller = new Unmarshaller(mapping);
+ RegistryFragment fragment =
(RegistryFragment)unmarshaller.unmarshal(reader);
+ assertNotNull(fragment);
+ Vector securityEntries = fragment.getSecurityEntries();
+ assertTrue( "Security Entries exist", !securityEntries.isEmpty());
+
+ // Test the wide-open entry
+ boolean entryFound = false;
+ Iterator securityIterator = null;
+ for (securityIterator = securityEntries.iterator();
securityIterator.hasNext();)
+ {
+ SecurityEntry securityEntry =
(SecurityEntry)securityIterator.next();
+ if (securityEntry.getName().equals("wide_open") == true)
{
- String s = (String)mpi.next();
- mpMap.put(s, s);
+ entryFound = true;
+ SecurityReference securityReference =
securityEntry.getSecurityRef();
+ assertNotNull( "Security entry 'wide_open' has a
SecurityReference", securityReference);
+ assertEquals( "Got parent", "admin_only",
securityReference.getParent());
}
- assertTrue(mpMap.containsKey("html"));
- assertTrue(mpMap.containsKey("wml"));
- assertTrue(mpMap.containsKey("xml"));
- assertTrue(mp.hasMediaType("wml"));
-
- PortletEntry mt = (PortletEntry)portlets.elementAt(6);
- assertNotNull(mt);
- assertTrue(mt.getName().equals("NoMediaType"));
- assertTrue(mt.getType().equals("ref"));
- Iterator mti = mt.listMediaTypes();
- assertNotNull(mti);
- assertTrue(mti.hasNext());
- String s = (String)mti.next();
- assertTrue(s.equals("html"));
-
- assertTrue(hack.getURL().equals("http://www.xmlhack.com/rss.php"));
- assertTrue(hack.isCachedOnURL());
+ }
+ assertTrue("Found wide_open security entry", entryFound);
- PortletEntry keytest = (PortletEntry)portlets.elementAt(7);
- assertNotNull(keytest);
- assertTrue(keytest.getName().equals("KeyTest"));
- assertTrue(keytest.getType().equals("ref"));
- it = keytest.getParameterNames();
- mpMap.clear();
- while (it.hasNext())
+ // Test the use_only entry
+ entryFound = false;
+ for (securityIterator = securityEntries.iterator();
securityIterator.hasNext();)
+ {
+ SecurityEntry securityEntry =
(SecurityEntry)securityIterator.next();
+ if (securityEntry.getName().equals("user_only") == true)
{
- String name = (String)it.next();
- CachedParameter cp = keytest.getCachedParameter(name);
- mpMap.put(cp.getName(), cp);
- //System.out.println("param = " + cp.getName() + "," +
cp.getValue());
- //System.out.println("keys = " + cp.isCachedOnName() + "," +
cp.isCachedOnValue());
-
- }
- assertTrue(keytest.isCachedOnURL() == false);
- CachedParameter cp = (CachedParameter)mpMap.get("newsid");
- assertNotNull(cp);
- assertTrue(cp.isCachedOnName() == false);
- assertTrue(cp.isCachedOnValue() == true);
- cp = (CachedParameter)mpMap.get("sportsid");
- assertNotNull(cp);
- assertTrue(cp.isCachedOnName() == true);
- assertTrue(cp.isCachedOnValue() == false);
- cp = (CachedParameter)mpMap.get("contact2");
- assertNotNull(cp);
- assertTrue(cp.isCachedOnName() == true);
- assertTrue(cp.isCachedOnValue() == true);
- cp = (CachedParameter)mpMap.get("showtitle");
- assertNotNull(cp);
- assertTrue(cp.isCachedOnName() == true);
- assertTrue(cp.isCachedOnValue() == true);
-
- // categories
- PortletEntry feeder = (PortletEntry)portlets.elementAt(3);
- assertNotNull(feeder);
- assertTrue(feeder.getName().equals("Feeder"));
- assertTrue(feeder.getType().equals("ref"));
- Iterator fi = feeder.listCategories();
- Category cat = (Category)fi.next();
- assertTrue(cat.getName().equals("news.world.politics"));
- assertTrue(cat.getGroup().equals("news"));
- assertTrue(feeder.hasCategory("news.world.politics", "news"));
- feeder.addCategory("news.us.economy");
- assertTrue(feeder.hasCategory("news.us.economy"));
- feeder.removeCategory("news.us.economy");
- assertTrue(!feeder.hasCategory("news.us.economy"));
-/*
- /*
- Iterator fi = feeder.listCategories();
- Category cat = (Category)fi.next();
- System.out.println("cat = " + cat.getName());
- System.out.println("cat.group = " + cat.getGroup());
+ entryFound = true;
+ SecurityReference securityReference =
securityEntry.getSecurityRef();
+ assertNull( "Security entry 'user_open' has no
SecurityReference", securityReference);
}
- */
- }
- catch (Exception e)
- {
- String errmsg = "Error in xreg mapping creation: " + e.toString();
- // e.printStackTrace();
- assertNotNull(errmsg, null);
}
+ assertEquals("Found user_only security entry", true, entryFound);
}
- else
- {
- String errmsg = "Registy Mapping not found or not a file or unreadable:
";
- System.err.println(errmsg);
- assertNotNull(errmsg, null);
- }
}
+
/**
* Tests IdentityElement unmarshaling entryset base stuff
* @throws Exception
No revision
No revision
1.8.2.2 +54 -3 jakarta-jetspeed/webapp/WEB-INF/conf/registry.xml
Index: registry.xml
===================================================================
RCS file: /home/cvs/jakarta-jetspeed/webapp/WEB-INF/conf/registry.xml,v
retrieving revision 1.8.2.1
retrieving revision 1.8.2.2
diff -u -r1.8.2.1 -r1.8.2.2
--- registry.xml 3 Jun 2002 04:17:24 -0000 1.8.2.1
+++ registry.xml 4 Jun 2002 17:38:38 -0000 1.8.2.2
@@ -57,6 +57,10 @@
<bind-xml name="security"/>
</field>
+ <field name="securityRef" type="org.apache.jetspeed.om.BaseSecurityReference">
+ <bind-xml name="security-ref"/>
+ </field>
+
<field name="baseMetaInfo"
type="org.apache.jetspeed.om.registry.base.BaseMetaInfo">
<bind-xml name="meta-info"/>
@@ -117,6 +121,10 @@
<bind-xml name="security"/>
</field>
+ <field name="securityRef" type="org.apache.jetspeed.om.BaseSecurityReference">
+ <bind-xml name="security-ref"/>
+ </field>
+
<field name="baseMetaInfo"
type="org.apache.jetspeed.om.registry.base.BaseMetaInfo">
<bind-xml name="meta-info"/>
@@ -156,6 +164,10 @@
<bind-xml name="security"/>
</field>
+ <field name="securityRef" type="org.apache.jetspeed.om.BaseSecurityReference">
+ <bind-xml name="security-ref"/>
+ </field>
+
<field name="baseMetaInfo"
type="org.apache.jetspeed.om.registry.base.BaseMetaInfo">
<bind-xml name="meta-info"/>
@@ -195,6 +207,10 @@
<bind-xml name="security"/>
</field>
+ <field name="securityRef" type="org.apache.jetspeed.om.BaseSecurityReference">
+ <bind-xml name="security-ref"/>
+ </field>
+
<field name="baseMetaInfo"
type="org.apache.jetspeed.om.registry.base.BaseMetaInfo">
<bind-xml name="meta-info"/>
@@ -222,6 +238,10 @@
<bind-xml name="security"/>
</field>
+ <field name="securityRef" type="org.apache.jetspeed.om.BaseSecurityReference">
+ <bind-xml name="security-ref"/>
+ </field>
+
<field name="baseMetaInfo"
type="org.apache.jetspeed.om.registry.base.BaseMetaInfo">
<bind-xml name="meta-info"/>
@@ -291,6 +311,10 @@
<bind-xml name="security"/>
</field>
+ <field name="securityRef" type="org.apache.jetspeed.om.BaseSecurityReference">
+ <bind-xml name="security-ref"/>
+ </field>
+
<field name="baseMetaInfo"
type="org.apache.jetspeed.om.registry.base.BaseMetaInfo">
<bind-xml name="meta-info"/>
@@ -322,6 +346,10 @@
<bind-xml name="security"/>
</field>
+ <field name="securityRef" type="org.apache.jetspeed.om.BaseSecurityReference">
+ <bind-xml name="security-ref"/>
+ </field>
+
<field name="baseMetaInfo"
type="org.apache.jetspeed.om.registry.base.BaseMetaInfo">
<bind-xml name="meta-info"/>
@@ -359,34 +387,57 @@
<class name="org.apache.jetspeed.om.registry.base.BaseSecurityEntry">
<map-to xml="security-entry"/>
- <field name="id" type="java.lang.String">
- <bind-xml name="id" node="attribute"/>
+
+ <field name="name" type="java.lang.String">
+ <bind-xml name="name" node="attribute"/>
</field>
+
+ <field name="securityRef" type="org.apache.jetspeed.om.BaseSecurityReference">
+ <bind-xml name="security-ref"/>
+ </field>
+
<field name="accesses"
type="org.apache.jetspeed.om.registry.base.BaseSecurityAccess"
collection="vector">
- <bind-xml name="id"/>
+ <bind-xml name="access"/>
</field>
+
</class>
<class name="org.apache.jetspeed.om.registry.base.BaseSecurityAccess">
<map-to xml="access"/>
+
<field name="action" type="java.lang.String">
<bind-xml name="action" node="attribute"/>
</field>
+
<field name="allows"
type="org.apache.jetspeed.om.registry.base.BaseSecurityAllow"
collection="vector">
<bind-xml name="allow-if"/>
</field>
+
</class>
+
<class name="org.apache.jetspeed.om.registry.base.BaseSecurityAllow">
<map-to xml="allow-if"/>
+
<field name="role" type="java.lang.String">
<bind-xml name="role" node="attribute"/>
</field>
+
<field name="user" type="java.lang.String">
<bind-xml name="user" node="attribute"/>
</field>
+
+ </class>
+
+ <class name="org.apache.jetspeed.om.BaseSecurityReference">
+ <map-to xml="security-ref"/>
+
+ <field name="parent" type="java.lang.String">
+ <bind-xml name="parent" node="attribute"/>
+ </field>
+
</class>
</mapping>
No revision
No revision
1.1.2.2 +62 -92
jakarta-jetspeed/webapp/WEB-INF/psml/test/Attic/testcase-security.xreg
Index: testcase-security.xreg
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed/webapp/WEB-INF/psml/test/Attic/testcase-security.xreg,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- testcase-security.xreg 3 Jun 2002 04:17:24 -0000 1.1.2.1
+++ testcase-security.xreg 4 Jun 2002 17:38:38 -0000 1.1.2.2
@@ -1,115 +1,85 @@
<?xml version="1.0" encoding="UTF-8"?>
<registry>
- <security-entry id="admin-all">
+ <security-entry name="basic_testcase">
<access action="view">
<allow-if role="clerk"/>
<allow-if user="joe"/>
<allow-if role="manager" user="fred"/>
</access>
+ <access action="customize">
+ <allow-if user="*"/>
+ </access>
+ <access action="minimize">
+ </access>
+ </security-entry>
+ <security-entry name="admin_only">
+ <access action="customize">
+ <allow-if role="admin"/>
+ </access>
+ <access action="maximize">
+ <allow-if role="admin"/>
+ </access>
+ <access action="minimize">
+ <allow-if role="admin"/>
+ </access>
+ <access action="view">
+ <allow-if role="admin"/>
+ </access>
+ </security-entry>
+ <security-entry name="admin_all-user_view">
+ <access action="customize">
+ <allow-if role="admin"/>
+ </access>
+ <access action="maximize">
+ <allow-if role="admin"/>
+ </access>
+ <access action="minimize">
+ <allow-if role="admin"/>
+ </access>
+ <access action="view">
+ <allow-if role="admin"/>
+ <allow-if role="user"/>
+ </access>
+ </security-entry>
+ <security-entry name="user_only">
+ <access action="customize">
+ <allow-if role="user"/>
+ </access>
+ <access action="maximize">
+ <allow-if role="user"/>
+ </access>
+ <access action="minimize">
+ <allow-if role="user"/>
+ </access>
+ <access action="view">
+ <allow-if role="user"/>
+ </access>
+ </security-entry>
+ <security-entry name="wide_open">
+ <security-ref parent="admin_only"/>
+ <access>
+ <allow-if user="*"/>
+ </access>
</security-entry>
<portlet-entry name="XSL" hidden="false" type="abstract" application="false">
- <classname>org.apache.jetspeed.portal.portlets.XSLPortlet</classname>
+ <security-ref name="user_only"/>
</portlet-entry>
+
<portlet-entry name="RSS" hidden="false" type="abstract" application="false">
- <meta-info>
- <title>RSS-Default-Title</title>
- <description>RSS-Default-Description</description>
- </meta-info>
+ <security-ref name="wide_open"/>
<classname>org.apache.jetspeed.portal.portlets.NewRSSPortlet</classname>
<parameter name="stylesheet" value="/WEB-INF/xsl/rss.xsl" hidden="false">
- <security role="admin"/>
+ <security-ref name="admin_only"/>
</parameter>
<parameter name="stylesheet.text/html" value="/WEB-INF/xsl/rss.xsl"
hidden="false">
- <security role="admin"/>
+ <security-ref name="admin_only"/>
</parameter>
<parameter name="stylesheet.text/vnd.wap.wml"
value="/WEB-INF/xsl/rss-wml.xsl" hidden="false">
- <security role="admin"/>
+ <security-ref name="admin_only"/>
</parameter>
<parameter name="itemdisplayed" value="15" hidden="false">
- <meta-info>
- <title>Number of items</title>
- <description>This parameter controls how many items may
- be shown in this portlet. If the
- information channel has more items, only the first
- will be displayed. </description>
- </meta-info>
- </parameter>
- <parameter name="openinpopup" value="false" type="boolean" hidden="false">
- <meta-info>
- <title>Open links in Popup window</title>
- <description>Links will be opened in a new browser
window.</description>
- </meta-info>
- </parameter>
- <parameter name="showdescription" value="true" type="boolean"
hidden="false">
- <meta-info>
- <title>Show item description ?</title>
- <description> This parameter specify whether
- the item descriptions and icons should be
- displayed in this portlet, or only the headlines.
</description>
- </meta-info>
+ <security-ref name="admin_all-user_view"/>
</parameter>
- <parameter name="showtitle" value="true" type="boolean" hidden="false">
- <meta-info>
- <title>Show title description ?</title>
- <description> This parameter specify whether
- the title description and icon should be
- displayed in this portlet, or only the title.
</description>
- </meta-info>
- </parameter>
- <parameter name="showtextinput" value="true" type="boolean" hidden="false">
- <meta-info>
- <title>Show Text Input?</title>
- <description> This parameter specify whether
- the text input will be displayed. Text
- Input is an optional element in the RSS feed.
</description>
- </meta-info>
- </parameter>
- <category>news.feeds</category>
- <category group="base">xml.rss</category>
- <media-type ref="html"/>
- </portlet-entry>
-
- <portlet-entry name="XMLHack" hidden="true" type="ref" parent="RSS"
application="false">
- <meta-info>
- <title>XMLHack Title</title>
- <description>XMLHack Description</description>
- </meta-info>
- <url cachedOnURL="true">http://www.xmlhack.com/rss.php</url>
- <parameter name="HACK" value="hacker"/>
- </portlet-entry>
-
- <portlet-entry name="Feeder" hidden="true" type="ref" parent="RSS"
application="false">
- <url cachedOnURL="true">http://www.feeder-site.com/feed.rss</url>
- <category group="news">news.world.politics</category>
- <category group="news">news.world.wars</category>
</portlet-entry>
-
- <portlet-entry name="AdminScreen" hidden="false" type="instance"
application="false">
- <meta-info>
- <title>Turbine Screen in a portlet</title>
- <description>We put the Admin Screen in a portlet.</description>
- </meta-info>
-
<classname>org.apache.jetspeed.portal.portlets.TurbineScreenPortlet</classname>
- <parameter name="display.screen" value="Admin" hidden="false"/>
- <parameter name="bgcolor" value="gray" hidden="false"/>
- <media-type ref="html"/>
- </portlet-entry>
-
- <portlet-entry name="MetaTest" hidden="false" type="ref" parent="AdminScreen"
application="false">
- <media-type ref="wml"/>
- <media-type ref="xml"/>
- </portlet-entry>
-
- <portlet-entry name="NoMediaType" hidden="false" type="ref"
parent="AdminScreen" application="false"/>
-
- <portlet-entry name="KeyTest" hidden="true" type="ref" parent="RSS"
application="false">
- <url cachedOnURL="false">http://www.newnews.com/</url>
- <parameter cachedOnName="false" cachedOnValue="true" name="newsid"
value="99" hidden="false"/>
- <parameter cachedOnName="true" cachedOnValue="false" name="sportsid"
value="100" hidden="false"/>
- <parameter cachedOnName="false" cachedOnValue="false" name="contact"
value="Joe" hidden="false"/>
- <parameter name="contact2" value="Jon" hidden="false"/>
-
- </portlet-entry>
-
</registry>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>