Przeglądaj źródła

Tidying up generics and removing warnings from portlet module.

Luke Taylor 16 lat temu
rodzic
commit
56c9117484

+ 5 - 3
portlet/src/main/java/org/springframework/security/portlet/PortletAuthenticationDetails.java

@@ -8,13 +8,15 @@ import javax.portlet.PortletRequest;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-public class PortletAuthenticationDetails implements Serializable {    
+@SuppressWarnings("unchecked")
+public class PortletAuthenticationDetails implements Serializable {
     //~ Instance fields ================================================================================================
     protected final Log logger = LogFactory.getLog(PortletAuthenticationDetails.class);
+
     protected Map userInfo;
 
     //~ Constructors ===================================================================================================
-        
+
     public PortletAuthenticationDetails(PortletRequest request) {
         try {
             userInfo = (Map)request.getAttribute(PortletRequest.USER_INFO);
@@ -26,7 +28,7 @@ public class PortletAuthenticationDetails implements Serializable {
     public Map getUserInfo() {
         return userInfo;
     }
-    
+
     public String toString() {
         return "User info: " + userInfo;
     }

+ 1 - 2
portlet/src/main/java/org/springframework/security/portlet/PortletPreAuthenticatedAuthenticationDetails.java

@@ -1,6 +1,5 @@
 package org.springframework.security.portlet;
 
-import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
@@ -30,7 +29,7 @@ public class PortletPreAuthenticatedAuthenticationDetails extends PortletAuthent
     public String toString() {
         StringBuffer sb = new StringBuffer();
         sb.append(super.toString() + "; ");
-        sb.append("preAuthenticatedGrantedAuthorities: " + Arrays.asList(preAuthenticatedGrantedAuthorities));
+        sb.append("preAuthenticatedGrantedAuthorities: " + preAuthenticatedGrantedAuthorities);
         return sb.toString();
     }
 }

+ 15 - 5
portlet/src/main/java/org/springframework/security/portlet/PortletProcessingInterceptor.java

@@ -22,9 +22,21 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import javax.portlet.*;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.EventRequest;
+import javax.portlet.EventResponse;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.PortletSession;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
 
-import org.springframework.security.web.authentication.AbstractProcessingFilter;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.springframework.beans.factory.InitializingBean;
 import org.springframework.security.authentication.AuthenticationDetailsSource;
 import org.springframework.security.authentication.AuthenticationDetailsSourceImpl;
 import org.springframework.security.authentication.AuthenticationManager;
@@ -34,9 +46,6 @@ import org.springframework.security.core.AuthenticationException;
 import org.springframework.security.core.context.SecurityContext;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.web.authentication.AbstractProcessingFilter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.springframework.beans.factory.InitializingBean;
 import org.springframework.util.Assert;
 import org.springframework.web.portlet.HandlerInterceptor;
 import org.springframework.web.portlet.ModelAndView;
@@ -72,6 +81,7 @@ import org.springframework.web.portlet.ModelAndView;
  * @since 2.0
  * @version $Id$
  */
+@SuppressWarnings("unchecked")
 public class PortletProcessingInterceptor implements HandlerInterceptor, InitializingBean {
 
     //~ Static fields/initializers =====================================================================================

+ 9 - 11
portlet/src/test/java/org/springframework/security/portlet/PortletSessionContextIntegrationInterceptorTests.java

@@ -20,18 +20,16 @@ import javax.portlet.PortletSession;
 
 import junit.framework.TestCase;
 
+import org.springframework.mock.web.portlet.MockActionRequest;
+import org.springframework.mock.web.portlet.MockActionResponse;
+import org.springframework.mock.web.portlet.MockRenderRequest;
+import org.springframework.mock.web.portlet.MockRenderResponse;
 import org.springframework.security.authentication.preauth.PreAuthenticatedAuthenticationToken;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.authority.GrantedAuthorityImpl;
+import org.springframework.security.core.authority.AuthorityUtils;
 import org.springframework.security.core.context.SecurityContext;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.security.core.context.SecurityContextImpl;
 import org.springframework.security.core.userdetails.User;
-import org.springframework.security.portlet.PortletSessionContextIntegrationInterceptor;
-import org.springframework.mock.web.portlet.MockActionRequest;
-import org.springframework.mock.web.portlet.MockActionResponse;
-import org.springframework.mock.web.portlet.MockRenderRequest;
-import org.springframework.mock.web.portlet.MockRenderResponse;
 
 /**
  * Tests {@link PortletSessionContextIntegrationInterceptor}.
@@ -169,10 +167,10 @@ public class PortletSessionContextIntegrationInterceptorTests extends TestCase {
         // Perform updates to principal
         sessionPrincipal = PortletTestUtils.createAuthenticatedToken(
                 new User(PortletTestUtils.TESTUSER, PortletTestUtils.TESTCRED, true, true, true, true,
-                        new GrantedAuthority[] {new GrantedAuthorityImpl("UPDATEDROLE1")}));
+                        AuthorityUtils.createAuthorityList("UPDATEDROLE1")));
         baselinePrincipal = PortletTestUtils.createAuthenticatedToken(
                 new User(PortletTestUtils.TESTUSER, PortletTestUtils.TESTCRED, true, true, true, true,
-                        new GrantedAuthority[] {new GrantedAuthorityImpl("UPDATEDROLE1")}));
+                        AuthorityUtils.createAuthorityList("UPDATEDROLE1")));
 
         // Store updated principal into SecurityContextHolder
         SecurityContextHolder.getContext().setAuthentication(sessionPrincipal);
@@ -323,10 +321,10 @@ public class PortletSessionContextIntegrationInterceptorTests extends TestCase {
         // Perform updates to principal
         sessionPrincipal = PortletTestUtils.createAuthenticatedToken(
                 new User(PortletTestUtils.TESTUSER, PortletTestUtils.TESTCRED, true, true, true, true,
-                        new GrantedAuthority[] {new GrantedAuthorityImpl("UPDATEDROLE1")}));
+                        AuthorityUtils.createAuthorityList("UPDATEDROLE1")));
         baselinePrincipal = PortletTestUtils.createAuthenticatedToken(
                 new User(PortletTestUtils.TESTUSER, PortletTestUtils.TESTCRED, true, true, true, true,
-                        new GrantedAuthority[] {new GrantedAuthorityImpl("UPDATEDROLE1")}));
+                        AuthorityUtils.createAuthorityList("UPDATEDROLE1")));
 
         // Store updated principal into SecurityContextHolder
         SecurityContextHolder.getContext().setAuthentication(sessionPrincipal);

+ 7 - 9
portlet/src/test/java/org/springframework/security/portlet/PortletTestUtils.java

@@ -18,18 +18,16 @@ package org.springframework.security.portlet;
 
 import javax.portlet.PortletRequest;
 
-import org.springframework.security.authentication.TestingAuthenticationToken;
-import org.springframework.security.authentication.preauth.PreAuthenticatedAuthenticationToken;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.authority.GrantedAuthorityImpl;
-import org.springframework.security.core.userdetails.User;
-import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.security.portlet.PortletAuthenticationDetails;
 import org.springframework.mock.web.portlet.MockActionRequest;
 import org.springframework.mock.web.portlet.MockActionResponse;
 import org.springframework.mock.web.portlet.MockPortletRequest;
 import org.springframework.mock.web.portlet.MockRenderRequest;
 import org.springframework.mock.web.portlet.MockRenderResponse;
+import org.springframework.security.authentication.TestingAuthenticationToken;
+import org.springframework.security.authentication.preauth.PreAuthenticatedAuthenticationToken;
+import org.springframework.security.core.authority.AuthorityUtils;
+import org.springframework.security.core.userdetails.User;
+import org.springframework.security.core.userdetails.UserDetails;
 
 /**
  * Utilities for testing Portlet (JSR 168) based security.
@@ -54,7 +52,7 @@ public class PortletTestUtils {
 
     public static UserDetails createUser() {
         return new User(PortletTestUtils.TESTUSER, "dummy", true, true, true, true,
-            new GrantedAuthority[] {new GrantedAuthorityImpl(TESTROLE1), new GrantedAuthorityImpl(TESTROLE2)});
+            AuthorityUtils.createAuthorityList(TESTROLE1, TESTROLE2));
     }
 
     public static void applyPortletRequestSecurity(MockPortletRequest request) {
@@ -100,7 +98,7 @@ public class PortletTestUtils {
 
     public static PreAuthenticatedAuthenticationToken createAuthenticatedToken(UserDetails user) {
         PreAuthenticatedAuthenticationToken result = new PreAuthenticatedAuthenticationToken(
-                user, user.getPassword(), user.getAuthorities().toArray(new GrantedAuthority[0]));
+                user, user.getPassword(), user.getAuthorities());
         result.setAuthenticated(true);
         return result;
     }