Return-Path: Delivered-To: apmail-incubator-jspwiki-commits-archive@locus.apache.org Received: (qmail 31690 invoked from network); 23 Feb 2008 19:05:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Feb 2008 19:05:34 -0000 Received: (qmail 61283 invoked by uid 500); 23 Feb 2008 19:05:30 -0000 Delivered-To: apmail-incubator-jspwiki-commits-archive@incubator.apache.org Received: (qmail 61272 invoked by uid 500); 23 Feb 2008 19:05:30 -0000 Mailing-List: contact jspwiki-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: jspwiki-dev@incubator.apache.org Delivered-To: mailing list jspwiki-commits@incubator.apache.org Received: (qmail 61263 invoked by uid 99); 23 Feb 2008 19:05:29 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Feb 2008 11:05:29 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 23 Feb 2008 19:04:43 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 852CD1A9832; Sat, 23 Feb 2008 11:05:02 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r630506 - in /incubator/jspwiki/branches/JSPWIKI_2_9_STRIPES_BRANCH/src/com/ecyrd/jspwiki/auth: acl/ authorize/ Date: Sat, 23 Feb 2008 19:05:01 -0000 To: jspwiki-commits@incubator.apache.org From: ajaquith@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080223190502.852CD1A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 m_entries = new Vector(); /** * Constructs a new AclImpl instance. @@ -52,7 +52,7 @@ */ public Principal[] findPrincipals( Permission permission ) { - Vector principals = new Vector(); + Vector principals = new Vector(); 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> permissionPrincipals = new TreeMap>(); 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 principals = permissionPrincipals.get( permission.getActions() ); if ( principals == null ) { - principals = new ArrayList(); + principals = new ArrayList(); 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> 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 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 m_members = new ArrayList(); 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 (e.g., MyWiki:MyGroup). + * @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 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 m_groups = new HashMap(); /** *

@@ -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 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 members = new HashSet(); 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 groups = new HashSet(); 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 roles = new HashSet(); 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 m_groups = new HashMap(); /** * 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 groups = m_groups.values(); + return groups.toArray( new Group[groups.size()] ); } /**