Browse Source

Update to current Spring JAR dependencies.

Ben Alex 20 years ago
parent
commit
9f66c0eae9

+ 12 - 11
.classpath

@@ -26,15 +26,15 @@
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 	<classpathentry kind="var" path="MAVEN_REPO/resin/jars/resin-3.0.9.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/retroweaver/jars/retroweaver-1.0fcs.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-aop-1.1.3.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-context-1.1.3.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-core-1.1.3.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-dao-1.1.3.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-mock-1.1.3.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-orm-1.1.3.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-web-1.1.3.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-webmvc-1.1.3.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/log4j/jars/log4j-1.2.8.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-aop-1.1.5.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-context-1.1.5.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-core-1.1.5.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-dao-1.1.5.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-mock-1.1.5.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-orm-1.1.5.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-web-1.1.5.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/springframework/jars/spring-webmvc-1.1.5.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/log4j/jars/log4j-1.2.9.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/aopalliance/jars/aopalliance-1.0.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/aspectj/jars/aspectjrt-1.2.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/cas/jars/casclient-2.0.11.jar"/>
@@ -43,8 +43,8 @@
 	<classpathentry kind="var" path="MAVEN_REPO/commons-collections/jars/commons-collections-3.1.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/commons-logging/jars/commons-logging-1.0.4.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/hsqldb/jars/hsqldb-1.7.3.0.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/oro/jars/oro-2.0.7.jar"/>
-	<classpathentry kind="var" path="MAVEN_REPO/servletapi/jars/servletapi-2.3.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/oro/jars/oro-2.0.8.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/servletapi/jars/servletapi-2.4.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/tomcat/jars/catalina-4.1.9.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/jetty/jars/org.mortbay.jetty-4.2.22.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/jboss/jars/jboss-common-3.2.3.jar"/>
@@ -52,5 +52,6 @@
 	<classpathentry kind="var" path="MAVEN_REPO/jboss/jars/jbosssx-3.2.3.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/junit/jars/junit-3.8.1.jar"/>
 	<classpathentry kind="var" path="MAVEN_REPO/ehcache/jars/ehcache-1.1.jar"/>
+	<classpathentry kind="var" path="MAVEN_REPO/jspapi/jars/jsp-api-2.0.jar"/>
 	<classpathentry kind="output" path="target/eclipseclasses"/>
 </classpath>

+ 22 - 4
core/src/test/java/org/acegisecurity/MockHttpServletRequest.java

@@ -52,9 +52,9 @@ public class MockHttpServletRequest implements HttpServletRequest {
 
     private HttpSession session = new MockHttpSession();
     private Map attribMap = new HashMap();
+    private Map cookiesMap = new HashMap();
     private Map headersMap = new HashMap();
     private Map paramMap = new HashMap();
-    private Map cookiesMap = new HashMap();
     private Principal principal;
     private String contextPath = "";
     private String pathInfo; // null for no extra path
@@ -76,12 +76,14 @@ public class MockHttpServletRequest implements HttpServletRequest {
         this.queryString = queryString;
     }
 
-    public MockHttpServletRequest(Map headers, HttpSession session, String queryString, Cookie[] cookies) {
-    	this.queryString = queryString;
+    public MockHttpServletRequest(Map headers, HttpSession session,
+        String queryString, Cookie[] cookies) {
+        this.queryString = queryString;
         this.headersMap = headers;
         this.session = session;
+
         for (int i = 0; i < cookies.length; i++) {
-        	cookiesMap.put(cookies[i].getName(), cookies[i]);
+            cookiesMap.put(cookies[i].getName(), cookies[i]);
         }
     }
 
@@ -172,6 +174,18 @@ public class MockHttpServletRequest implements HttpServletRequest {
         throw new UnsupportedOperationException("mock method not implemented");
     }
 
+    public String getLocalAddr() {
+        throw new UnsupportedOperationException("mock method not implemented");
+    }
+
+    public String getLocalName() {
+        throw new UnsupportedOperationException("mock method not implemented");
+    }
+
+    public int getLocalPort() {
+        throw new UnsupportedOperationException("mock method not implemented");
+    }
+
     public Locale getLocale() {
         throw new UnsupportedOperationException("mock method not implemented");
     }
@@ -246,6 +260,10 @@ public class MockHttpServletRequest implements HttpServletRequest {
         throw new UnsupportedOperationException("mock method not implemented");
     }
 
+    public int getRemotePort() {
+        throw new UnsupportedOperationException("mock method not implemented");
+    }
+
     public String getRemoteUser() {
         throw new UnsupportedOperationException("mock method not implemented");
     }

+ 8 - 0
core/src/test/java/org/acegisecurity/MockHttpServletResponse.java

@@ -53,6 +53,10 @@ public class MockHttpServletResponse implements HttpServletResponse {
         throw new UnsupportedOperationException("mock method not implemented");
     }
 
+    public void setCharacterEncoding(String arg0) {
+        throw new UnsupportedOperationException("mock method not implemented");
+    }
+
     public String getCharacterEncoding() {
         throw new UnsupportedOperationException("mock method not implemented");
     }
@@ -73,6 +77,10 @@ public class MockHttpServletResponse implements HttpServletResponse {
         throw new UnsupportedOperationException("mock method not implemented");
     }
 
+    public String getContentType() {
+        throw new UnsupportedOperationException("mock method not implemented");
+    }
+
     public Cookie getCookieByName(String name) {
         return (Cookie) cookiesMap.get(name);
     }

+ 31 - 1
core/src/test/java/org/acegisecurity/intercept/web/FilterInvocationTests.java

@@ -1,4 +1,4 @@
-/* Copyright 2004 Acegi Technology Pty Limited
+/* Copyright 2004, 2005 Acegi Technology Pty Limited
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -244,6 +244,21 @@ public class FilterInvocationTests extends TestCase {
                 "mock method not implemented");
         }
 
+        public String getLocalAddr() {
+            throw new UnsupportedOperationException(
+                "mock method not implemented");
+        }
+
+        public String getLocalName() {
+            throw new UnsupportedOperationException(
+                "mock method not implemented");
+        }
+
+        public int getLocalPort() {
+            throw new UnsupportedOperationException(
+                "mock method not implemented");
+        }
+
         public Locale getLocale() {
             throw new UnsupportedOperationException(
                 "mock method not implemented");
@@ -299,6 +314,11 @@ public class FilterInvocationTests extends TestCase {
                 "mock method not implemented");
         }
 
+        public int getRemotePort() {
+            throw new UnsupportedOperationException(
+                "mock method not implemented");
+        }
+
         public RequestDispatcher getRequestDispatcher(String arg0) {
             throw new UnsupportedOperationException(
                 "mock method not implemented");
@@ -341,6 +361,11 @@ public class FilterInvocationTests extends TestCase {
                 "mock method not implemented");
         }
 
+        public void setCharacterEncoding(String arg0) {
+            throw new UnsupportedOperationException(
+                "mock method not implemented");
+        }
+
         public String getCharacterEncoding() {
             throw new UnsupportedOperationException(
                 "mock method not implemented");
@@ -361,6 +386,11 @@ public class FilterInvocationTests extends TestCase {
                 "mock method not implemented");
         }
 
+        public String getContentType() {
+            throw new UnsupportedOperationException(
+                "mock method not implemented");
+        }
+
         public void setLocale(Locale arg0) {
             throw new UnsupportedOperationException(
                 "mock method not implemented");

+ 4 - 1
doc/xdocs/changes.xml

@@ -31,7 +31,7 @@
       <action dev="benalex" type="update">ContextHolderAwareRequestWrapper methods return null if user is anonymous</action>
       <action dev="benalex" type="update">AbstractBasicAclEntry improved compatibility with Hibernate</action>
       <action dev="benalex" type="update">User now provides a more useful toString() method</action>
-      <action dev="benalex" type="update">Use Spring 1.1.5 JARs</action>
+      <action dev="benalex" type="update">Update to match Spring 1.1.5 official JAR dependencies (NB: now using Servlet 2.4 and related JSP/taglib JARs)</action>
       <action dev="benalex" type="fix">SecurityEnforcementFilter caused NullPointerException when anonymous authentication used with BasicProcessingFilterEntryPoint</action>
       <action dev="benalex" type="fix">FilterChainProxy now supports replacement of ServletRequest and ServetResponse by Filter beans</action>
       <action dev="fbos" type="fix">Corrected Authz parsing of whitespace in GrantedAuthoritys</action>
@@ -39,6 +39,9 @@
       <action dev="benalex" type="fix">HttpSessionContextIntegrationFilter now handles HttpSession invalidation without redirection</action>
       <action dev="benalex" type="fix">StringSplitUtils.split() ignored delimiter argument</action>
       <action dev="benalex" type="fix">DigestProcessingFilter now provides userCache getter and setter</action>
+      <action dev="benalex" type="fix">Contacts Sample made to work with UserDetails-based Principal</action>
+      <action dev="benalex" type="update">Documentation improvements</action>
+      <action dev="benalex" type="update">Test coverage improvements</action>
     </release>
     <release version="0.8.0" date="2005-03-03">
       <action dev="benalex" type="add">Added Digest Authentication support (RFC 2617 and RFC 2069)</action>

+ 16 - 5
project.xml

@@ -194,7 +194,7 @@
     <dependency>
       <groupId>jstl</groupId>
       <artifactId>jstl</artifactId>
-      <version>1.0.2</version>
+      <version>1.0.6</version>
       <type>jar</type>
       <properties>
         <war.bundle>true</war.bundle>
@@ -203,13 +203,14 @@
     <dependency>
       <groupId>servletapi</groupId>
       <artifactId>servletapi</artifactId>
-      <version>2.3</version>
+      <version>2.4</version>
       <type>jar</type>
+      <url>http://java.sun.com/products/servlet</url>
     </dependency>
     <dependency>
       <groupId>oro</groupId>
       <artifactId>oro</artifactId>
-      <version>2.0.7</version>
+      <version>2.0.8</version>
       <type>jar</type>
       <url>http://jakarta.apache.org/oro/</url>
       <properties>
@@ -229,7 +230,7 @@
     <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>
-      <version>1.2.8</version>
+      <version>1.2.9</version>
       <type>jar</type>
       <properties>
         <war.bundle>true</war.bundle>
@@ -338,7 +339,7 @@
     <dependency>
       <groupId>taglibs</groupId>
       <artifactId>standard</artifactId>
-      <version>1.0.4</version>
+      <version>1.0.6</version>
       <type>jar</type>
       <url>http://jakarta.apache.org/taglibs/</url>
       <properties>
@@ -377,6 +378,16 @@
       <version>2.5</version>
       <type>plugin</type>
     </dependency>
+    <dependency>
+      <groupId>jspapi</groupId>
+      <artifactId>jsp-api</artifactId>
+      <version>2.0</version>
+      <type>jar</type>
+      <url>http://java.sun.com/products/jsp</url>
+      <properties>
+        <war.bundle>false</war.bundle>
+      </properties>
+    </dependency>
   </dependencies>
   <build>
     <sourceDirectory>${basedir}/src/main/java</sourceDirectory>

+ 55 - 5
samples/contacts/src/main/java/sample/contact/ContactManagerBackend.java

@@ -15,15 +15,18 @@
 
 package sample.contact;
 
+import net.sf.acegisecurity.Authentication;
+import net.sf.acegisecurity.UserDetails;
 import net.sf.acegisecurity.acl.basic.AclObjectIdentity;
 import net.sf.acegisecurity.acl.basic.BasicAclExtendedDao;
 import net.sf.acegisecurity.acl.basic.NamedEntityObjectIdentity;
 import net.sf.acegisecurity.acl.basic.SimpleAclEntry;
-import net.sf.acegisecurity.context.ContextHolder;
-import net.sf.acegisecurity.context.security.SecureContext;
+import net.sf.acegisecurity.context.security.SecureContextUtils;
 
 import org.springframework.beans.factory.InitializingBean;
 
+import org.springframework.context.support.ApplicationObjectSupport;
+
 import java.util.List;
 import java.util.Random;
 
@@ -34,7 +37,8 @@ import java.util.Random;
  * @author Ben Alex
  * @version $Id$
  */
-public class ContactManagerBackend implements ContactManager, InitializingBean {
+public class ContactManagerBackend extends ApplicationObjectSupport
+    implements ContactManager, InitializingBean {
     //~ Instance fields ========================================================
 
     private BasicAclExtendedDao basicAclExtendedDao;
@@ -44,10 +48,18 @@ public class ContactManagerBackend implements ContactManager, InitializingBean {
     //~ Methods ================================================================
 
     public List getAll() {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Returning all contacts");
+        }
+
         return contactDao.findAll();
     }
 
     public List getAllRecipients() {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Returning all recipients");
+        }
+
         List list = contactDao.findAllPrincipals();
         list.addAll(contactDao.findAllRoles());
 
@@ -63,6 +75,10 @@ public class ContactManagerBackend implements ContactManager, InitializingBean {
     }
 
     public Contact getById(Integer id) {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Returning contact with id: " + id);
+        }
+
         return contactDao.getById(id);
     }
 
@@ -80,6 +96,10 @@ public class ContactManagerBackend implements ContactManager, InitializingBean {
      * @return DOCUMENT ME!
      */
     public Contact getRandomContact() {
+        if (logger.isDebugEnabled()) {
+            logger.debug("Returning random contact");
+        }
+
         Random rnd = new Random();
         List contacts = contactDao.findAll();
         int getNumber = rnd.nextInt(contacts.size());
@@ -94,6 +114,11 @@ public class ContactManagerBackend implements ContactManager, InitializingBean {
         simpleAclEntry.setMask(permission.intValue());
         simpleAclEntry.setRecipient(recipient);
         basicAclExtendedDao.create(simpleAclEntry);
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Added permission " + permission + " for recipient "
+                + recipient + " contact " + contact);
+        }
     }
 
     public void afterPropertiesSet() throws Exception {
@@ -114,6 +139,11 @@ public class ContactManagerBackend implements ContactManager, InitializingBean {
         // Grant the current principal access to the contact 
         addPermission(contact, getUsername(),
             new Integer(SimpleAclEntry.ADMINISTRATION));
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Created contact " + contact
+                + " and granted admin permission to recipient " + getUsername());
+        }
     }
 
     public void delete(Contact contact) {
@@ -121,19 +151,39 @@ public class ContactManagerBackend implements ContactManager, InitializingBean {
 
         // Delete the ACL information as well
         basicAclExtendedDao.delete(makeObjectIdentity(contact));
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Deleted contact " + contact
+                + " including ACL permissions");
+        }
     }
 
     public void deletePermission(Contact contact, String recipient) {
         basicAclExtendedDao.delete(makeObjectIdentity(contact), recipient);
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Deleted contact " + contact
+                + " ACL permissions for recipient " + recipient);
+        }
     }
 
     public void update(Contact contact) {
         contactDao.update(contact);
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("Updated contact " + contact);
+        }
     }
 
     protected String getUsername() {
-        return ((SecureContext) ContextHolder.getContext()).getAuthentication()
-                .getPrincipal().toString();
+        Authentication auth = SecureContextUtils.getSecureContext()
+                                                .getAuthentication();
+
+        if (auth.getPrincipal() instanceof UserDetails) {
+            return ((UserDetails) auth.getPrincipal()).getUsername();
+        } else {
+            return auth.getPrincipal().toString();
+        }
     }
 
     private AclObjectIdentity makeObjectIdentity(Contact contact) {

+ 1 - 0
samples/contacts/src/main/resources/log4j.properties

@@ -20,6 +20,7 @@ log4j.rootLogger=WARN, stdout, fileout
 #log4j.logger.net.sf.acegisecurity.ui.httpinvoker=DEBUG, stdout, fileout
 #log4j.logger.net.sf.acegisecurity.util=DEBUG, stdout, fileout
 #log4j.logger.net.sf.acegisecurity.providers.dao=DEBUG, stdout, fileout
+log4j.logger.sample.contact=DEBUG, stdout, fileout
 
 # Console output...
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender

+ 2 - 0
samples/contacts/src/main/resources/messages.properties

@@ -0,0 +1,2 @@
+err.name.webContact.name=Name 3-50 characters is required.
+err.name.webContact.email=Email 3-50 characters is required.

+ 4 - 0
samples/contacts/src/main/webapp/common/WEB-INF/contacts-servlet.xml

@@ -11,6 +11,10 @@
 
 	<!-- ========================== WEB DEFINITIONS ======================= -->
 
+	<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
+		<property name="basename"><value>messages</value></property>
+	</bean>
+
     <bean id="publicIndexController" class="sample.contact.PublicIndexController">
     	<property name="contactManager"><ref bean="contactManager"/></property>
  	</bean>