You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by aj...@apache.org on 2008/02/23 20:05:01 UTC

svn commit: r630506 - in /incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth: acl/ authorize/

Author: ajaquith
Date: Sat Feb 23 11:04:59 2008
New Revision: 630506

URL: http://svn.apache.org/viewvc?rev=630506&view=rev
Log:
Initial Stripes component commit.

Modified:
    incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/acl/AclImpl.java
    incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/acl/DefaultAclManager.java
    incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/Group.java
    incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/GroupManager.java
    incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/JDBCGroupDatabase.java
    incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/WebContainerAuthorizer.java
    incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/XMLGroupDatabase.java

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/acl/AclImpl.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/acl/AclImpl.java?rev=630506&r1=630505&r2=630506&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/acl/AclImpl.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/acl/AclImpl.java Sat Feb 23 11:04:59 2008
@@ -33,7 +33,7 @@
  */
 public class AclImpl implements Acl
 {
-    private final Vector m_entries = new Vector();
+    private final Vector<AclEntry> m_entries = new Vector<AclEntry>();
 
     /**
      * Constructs a new AclImpl instance.
@@ -52,7 +52,7 @@
      */
     public Principal[] findPrincipals( Permission permission )
     {
-        Vector principals = new Vector();
+        Vector<Principal> principals = new Vector<Principal>();
         Enumeration entries = entries();
         
         while (entries.hasMoreElements()) 
@@ -68,7 +68,7 @@
                 }
             }
         }
-        return (Principal[])principals.toArray( new Principal[principals.size()] );
+        return principals.toArray( new Principal[principals.size()] );
     }
   
     private boolean hasEntry( AclEntry entry )

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/acl/DefaultAclManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/acl/DefaultAclManager.java?rev=630506&r1=630505&r2=630506&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/acl/DefaultAclManager.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/acl/DefaultAclManager.java Sat Feb 23 11:04:59 2008
@@ -179,7 +179,7 @@
                 //
                 //  Or, try parsing the page
                 //
-                WikiContext ctx = new WikiContext( m_engine, page );
+                WikiContext ctx = m_engine.getWikiActionBeanFactory().newViewActionBean( page );
 
                 ctx.setVariable( RenderingManager.VAR_EXECUTE_PLUGINS, Boolean.FALSE );
 
@@ -246,7 +246,7 @@
     protected static String printAcl( Acl acl )
     {
         // Extract the ACL entries into a Map with keys == permissions, values == principals
-        Map permissionPrincipals = new TreeMap();
+        Map<String,List<Principal>> permissionPrincipals = new TreeMap<String,List<Principal>>();
         Enumeration entries = acl.entries();
         while ( entries.hasMoreElements() )
         {
@@ -256,10 +256,10 @@
             while ( permissions.hasMoreElements() )
             {
                 Permission permission = (Permission)permissions.nextElement();
-                List principals = (List)permissionPrincipals.get( permission.getActions() );
+                List<Principal> principals = permissionPrincipals.get( permission.getActions() );
                 if ( principals == null )
                 {
-                    principals = new ArrayList();
+                    principals = new ArrayList<Principal>();
                     String action = permission.getActions();
                     if ( action.indexOf(',') != -1 )
                     {
@@ -274,18 +274,17 @@
         // Now, iterate through each permission in the map and generate an ACL string
 
         StringBuffer s = new StringBuffer();
-        for ( Iterator it = permissionPrincipals.entrySet().iterator(); it.hasNext(); )
+        for ( Map.Entry<String,List<Principal>> entry : permissionPrincipals.entrySet() )
         {
-            Map.Entry entry = (Map.Entry)it.next();
-            String action = (String)entry.getKey();
-            List principals = (List)entry.getValue();
+            String action = entry.getKey();
+            List<Principal> principals = entry.getValue();
             Collections.sort( principals, new PrincipalComparator() );
             s.append( "[{ALLOW ");
             s.append( action );
             s.append( " ");
             for ( int i = 0; i < principals.size(); i++ )
             {
-                Principal principal = (Principal)principals.get( i );
+                Principal principal = principals.get( i );
                 s.append( principal.getName() );
                 if ( i < ( principals.size() - 1 ) )
                 {

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/Group.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/Group.java?rev=630506&r1=630505&r2=630506&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/Group.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/Group.java Sat Feb 23 11:04:59 2008
@@ -14,9 +14,7 @@
 package com.ecyrd.jspwiki.auth.authorize;
 
 import java.security.Principal;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.Vector;
+import java.util.*;
 
 import com.ecyrd.jspwiki.auth.GroupPrincipal;
 
@@ -57,10 +55,10 @@
 public class Group
 {
 
-    static final String[]  RESTRICTED_GROUPNAMES = new String[]
+    public static final String[]  RESTRICTED_GROUPNAMES = new String[]
                                                   { "Anonymous", "All", "Asserted", "Authenticated" };
 
-    private final Vector    m_members             = new Vector();
+    private final List<Principal> m_members = new ArrayList<Principal>();
 
     private String          m_creator             = null;
 
@@ -76,6 +74,8 @@
 
     private final String    m_wiki;
 
+    private final String    m_qualifiedName;
+
     /**
      * Protected constructor to prevent direct instantiation except by other
      * package members. Callers should use
@@ -90,6 +90,7 @@
         m_name = name;
         m_wiki = wiki;
         m_principal = new GroupPrincipal( name );
+        m_qualifiedName = wiki + ":" + name;
     }
 
     /**
@@ -214,6 +215,16 @@
     }
 
     /**
+     * The qualified name of the group, defined as the wiki plus the name,
+     * separated by a colon (<em>e.g.</em>, <code>MyWiki:MyGroup</code>).
+     * @return the qualified name of the Group
+     */
+    public String getQualifiedName()
+    {
+        return m_qualifiedName;
+    }
+
+    /**
      * Returns the GroupPrincipal that represents this Group.
      * @return the group principal
      */
@@ -245,12 +256,22 @@
     }
 
     /**
+     * Returns the members of the group as an unmodifiable Set of Principal
+     * objects.
+     */
+    public List<Principal> getMembers()
+    {
+        return Collections.unmodifiableList(m_members);
+    }
+
+    /**
      * Returns the members of the group as an array of Principal objects.
      * @return the members
+     * @deprecated
      */
     public Principal[] members()
     {
-        return (Principal[]) m_members.toArray( new Principal[m_members.size()] );
+        return m_members.toArray(new Principal[m_members.size()]);
     }
 
     /**

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/GroupManager.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/GroupManager.java?rev=630506&r1=630505&r2=630506&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/GroupManager.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/GroupManager.java Sat Feb 23 11:04:59 2008
@@ -14,12 +14,7 @@
 package com.ecyrd.jspwiki.auth.authorize;
 
 import java.security.Principal;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.StringTokenizer;
+import java.util.*;
 
 import javax.servlet.http.HttpServletRequest;
 
@@ -72,7 +67,7 @@
     private GroupDatabase       m_groupDatabase    = null;
 
     /** Map with GroupPrincipals as keys, and Groups as values */
-    private final Map           m_groups           = new HashMap();
+    private final Map<Principal,Group> m_groups    = new HashMap<Principal,Group>();
 
     /**
      * <p>
@@ -104,7 +99,7 @@
      */
     public final Group getGroup( String name ) throws NoSuchPrincipalException
     {
-        Group group = (Group) m_groups.get( new GroupPrincipal( name ) );
+        Group group = m_groups.get( new GroupPrincipal( name ) );
         if ( group != null )
         {
             return group;
@@ -189,7 +184,7 @@
      */
     public final Principal[] getRoles()
     {
-        return (Principal[]) m_groups.keySet().toArray( new Principal[m_groups.size()] );
+        return m_groups.keySet().toArray( new Principal[m_groups.size()] );
     }
 
     /**
@@ -267,7 +262,7 @@
         }
 
         // Get the group we're examining
-        Group group = (Group) m_groups.get( role );
+        Group group = m_groups.get( role );
         if ( group == null )
         {
             return false;
@@ -354,10 +349,10 @@
             group.setCreated( existingGroup.getCreated() );
             group.setModifier( existingGroup.getModifier() );
             group.setLastModified( existingGroup.getLastModified() );
-            Principal[] existingMembers = existingGroup.members();
-            for( int i = 0; i < existingMembers.length; i++ )
+            List<Principal> existingMembers = existingGroup.getMembers();
+            for( Principal member : existingMembers )
             {
-                group.add( existingMembers[i] );
+                group.add( member );
             }
         }
         catch( NoSuchPrincipalException e )
@@ -423,7 +418,7 @@
         Group group = parseGroup( name, memberLine, create );
 
         // If no members, add the current user by default
-        if ( group.members().length == 0 )
+        if ( group.getMembers().size() == 0 )
         {
             group.add( context.getWikiSession().getUserPrincipal() );
         }
@@ -451,7 +446,7 @@
             throw new IllegalArgumentException( "Group cannot be null." );
         }
 
-        Group group = (Group) m_groups.get( new GroupPrincipal( index ) );
+        Group group = m_groups.get( new GroupPrincipal( index ) );
         if ( group == null )
         {
             throw new NoSuchPrincipalException( "Group " + index + " not found" );
@@ -512,7 +507,7 @@
         // TODO: check for appropriate permissions
 
         // If group already exists, delete it; fire GROUP_REMOVE event
-        Group oldGroup = (Group) m_groups.get( group.getPrincipal() );
+        Group oldGroup = m_groups.get( group.getPrincipal() );
         if ( oldGroup != null )
         {
             fireEvent( WikiSecurityEvent.GROUP_REMOVE, oldGroup );
@@ -588,10 +583,9 @@
         }
 
         // Member names must be "safe" strings
-        Principal[] members = group.members();
-        for( int i = 0; i < members.length; i++ )
+        for( Principal member: group.getMembers() )
         {
-            validator.validateNotNull( members[i].getName(), "Full name", InputValidator.ID );
+            validator.validateNotNull( member.getName(), "Full name", InputValidator.ID );
         }
     }
 
@@ -602,7 +596,7 @@
      */
     protected final String[] extractMembers( String memberLine )
     {
-        Set members = new HashSet();
+        Set<String> members = new HashSet<String>();
         if ( memberLine != null )
         {
             StringTokenizer tok = new StringTokenizer( memberLine, "\n" );
@@ -615,7 +609,7 @@
                 }
             }
         }
-        return (String[]) members.toArray( new String[members.size()] );
+        return members.toArray( new String[members.size()] );
     }
 
     /**

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/JDBCGroupDatabase.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/JDBCGroupDatabase.java?rev=630506&r1=630505&r2=630506&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/JDBCGroupDatabase.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/JDBCGroupDatabase.java Sat Feb 23 11:04:59 2008
@@ -262,7 +262,7 @@
      */
     public Group[] groups() throws WikiSecurityException
     {
-        Set groups = new HashSet();
+        Set<Group> groups = new HashSet<Group>();
         Connection conn = null;
         try
         {
@@ -300,7 +300,7 @@
             try { conn.close(); } catch (Exception e) {}
         }
 
-        return (Group[])groups.toArray( new Group[groups.size()] );
+        return groups.toArray( new Group[groups.size()] );
     }
 
     /**
@@ -376,10 +376,8 @@
             
             // Insert group member records
             ps = conn.prepareStatement( m_insertGroupMembers );
-            Principal[] members = group.members();
-            for ( int i = 0; i < members.length; i++ )
+            for ( Principal member : group.getMembers() )
             {
-                Principal member = members[i];
                 ps.setString( 1, group.getName() );
                 ps.setString( 2, member.getName() );
                 ps.execute();

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/WebContainerAuthorizer.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/WebContainerAuthorizer.java?rev=630506&r1=630505&r2=630506&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/WebContainerAuthorizer.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/WebContainerAuthorizer.java Sat Feb 23 11:04:59 2008
@@ -24,6 +24,8 @@
 
 import javax.servlet.http.HttpServletRequest;
 
+import net.sourceforge.stripes.mock.MockServletContext;
+
 import org.apache.log4j.Logger;
 import org.jdom.Document;
 import org.jdom.Element;
@@ -308,7 +310,7 @@
      */
     public Principal[] getRoles()
     {
-        return (Principal[]) m_containerRoles.clone();
+        return m_containerRoles.clone();
     }
 
     /**
@@ -322,7 +324,7 @@
      */
     protected Role[] getRoles( Document webxml ) throws JDOMException
     {
-        Set roles = new HashSet();
+        Set<Role> roles = new HashSet<Role>();
         Element root = webxml.getRootElement();
 
         // Get roles referred to by constraints
@@ -347,7 +349,7 @@
             roles.add( new Role( role ) );
         }
 
-        return (Role[]) roles.toArray( new Role[roles.size()] );
+        return roles.toArray( new Role[roles.size()] );
     }
 
     /**
@@ -379,6 +381,12 @@
         else
         {
             url = m_engine.getServletContext().getResource( "/WEB-INF/web.xml" );
+            // Hack in case we're using Stripes mock servlet context
+            // See bug [STS-376] at http://stripesframework.org/jira/browse/STS-376. Will be fixed in Stripes 1.5.
+            if ( url == null && m_engine.getServletContext() instanceof MockServletContext )
+            {
+                url = m_engine.getServletContext().getResource( "WEB-INF/web.xml" );
+            }
             if( url != null )
                 log.info( "Examining " + url.toExternalForm() );
         }

Modified: incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/XMLGroupDatabase.java
URL: http://svn.apache.org/viewvc/incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/XMLGroupDatabase.java?rev=630506&r1=630505&r2=630506&view=diff
==============================================================================
--- incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/XMLGroupDatabase.java (original)
+++ incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth/authorize/XMLGroupDatabase.java Sat Feb 23 11:04:59 2008
@@ -113,7 +113,7 @@
 
     private WikiEngine            m_engine         = null;
 
-    private Map                   m_groups         = new HashMap();
+    private Map<String,Group>     m_groups         = new HashMap<String,Group>();
 
     /**
      * No-op method that in previous versions of JSPWiki was intended to
@@ -165,8 +165,8 @@
     public Group[] groups() throws WikiSecurityException
     {
         buildDOM();
-        Collection groups = m_groups.values();
-        return (Group[])groups.toArray( new Group[groups.size()] );
+        Collection<Group> groups = m_groups.values();
+        return groups.toArray( new Group[groups.size()] );
     }
 
     /**