felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject svn commit: r881057 - in /felix/trunk/http/base/src: main/java/org/apache/felix/http/base/internal/handler/ServletHandlerRequest.java test/java/org/apache/felix/http/base/internal/handler/ServletHandlerRequestTest.java
Date Mon, 16 Nov 2009 23:41:53 GMT
Author: srs
Date: Mon Nov 16 23:41:52 2009
New Revision: 881057

URL: http://svn.apache.org/viewvc?rev=881057&view=rev
Log:
FELIX-1860: Applied patch from Justin Edelson

Modified:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandlerRequest.java
    felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/ServletHandlerRequestTest.java

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandlerRequest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandlerRequest.java?rev=881057&r1=881056&r2=881057&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandlerRequest.java
(original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/handler/ServletHandlerRequest.java
Mon Nov 16 23:41:52 2009
@@ -19,6 +19,8 @@
 import javax.servlet.http.HttpServletRequestWrapper;
 import javax.servlet.http.HttpServletRequest;
 
+import org.osgi.service.http.HttpContext;
+
 final class ServletHandlerRequest
     extends HttpServletRequestWrapper
 {
@@ -31,6 +33,17 @@
         super(req);
         this.alias = alias;
     }
+    
+    @Override
+    public String getAuthType()
+    {
+        String authType = (String) getAttribute(HttpContext.AUTHENTICATION_TYPE);
+        if (authType != null) {
+            return authType;
+        }
+        
+        return super.getAuthType();
+    }
 
     @Override
     public String getPathInfo()
@@ -49,6 +62,17 @@
         final String info = getPathInfo();
         return (null == info) ? null : getRealPath(info);
     }
+        
+    @Override
+    public String getRemoteUser()
+    {
+        String remoteUser = (String) getAttribute(HttpContext.REMOTE_USER);
+        if (remoteUser != null) {
+            return remoteUser;
+        }
+        
+        return super.getRemoteUser();
+    }
 
     @Override
     public String getServletPath()

Modified: felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/ServletHandlerRequestTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/ServletHandlerRequestTest.java?rev=881057&r1=881056&r2=881057&view=diff
==============================================================================
--- felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/ServletHandlerRequestTest.java
(original)
+++ felix/trunk/http/base/src/test/java/org/apache/felix/http/base/internal/handler/ServletHandlerRequestTest.java
Mon Nov 16 23:41:52 2009
@@ -17,6 +17,7 @@
 package org.apache.felix.http.base.internal.handler;
 
 import org.mockito.Mockito;
+import org.osgi.service.http.HttpContext;
 import org.junit.Test;
 import org.junit.Assert;
 import org.junit.Before;
@@ -24,21 +25,30 @@
 
 public class ServletHandlerRequestTest
 {
+    private HttpServletRequest superReq1;
+    private HttpServletRequest superReq2;
+    
     private HttpServletRequest req1;
     private HttpServletRequest req2;
 
     @Before
     public void setUp()
     {
-        HttpServletRequest superReq = Mockito.mock(HttpServletRequest.class);
-        Mockito.when(superReq.getContextPath()).thenReturn("/mycontext");
-        Mockito.when(superReq.getRequestURI()).thenReturn("/mycontext/request/to/resource");
-        this.req1 = new ServletHandlerRequest(superReq, "/");
+        this.superReq1 = Mockito.mock(HttpServletRequest.class);
+        Mockito.when(this.superReq1.getContextPath()).thenReturn("/mycontext");
+        Mockito.when(this.superReq1.getRequestURI()).thenReturn("/mycontext/request/to/resource");
+        Mockito.when(this.superReq1.getAttribute(HttpContext.AUTHENTICATION_TYPE)).thenReturn(HttpServletRequest.BASIC_AUTH);
+        Mockito.when(this.superReq1.getAttribute(HttpContext.REMOTE_USER)).thenReturn("felix");
+        this.req1 = new ServletHandlerRequest(this.superReq1, "/");
 
-        superReq = Mockito.mock(HttpServletRequest.class);
-        Mockito.when(superReq.getContextPath()).thenReturn("/mycontext");
-        Mockito.when(superReq.getRequestURI()).thenReturn("/mycontext/myservlet/request/to/resource;jsession=123");
-        this.req2 = new ServletHandlerRequest(superReq, "/myservlet");
+        this.superReq2 = Mockito.mock(HttpServletRequest.class);
+        Mockito.when(this.superReq2.getContextPath()).thenReturn("/mycontext");
+        Mockito.when(this.superReq2.getRequestURI()).thenReturn("/mycontext/myservlet/request/to/resource;jsession=123");
+        Mockito.when(this.superReq2.getAttribute(HttpContext.AUTHENTICATION_TYPE)).thenReturn(null);
+        Mockito.when(this.superReq2.getAuthType()).thenReturn(HttpServletRequest.DIGEST_AUTH);
+        Mockito.when(this.superReq2.getAttribute(HttpContext.REMOTE_USER)).thenReturn(null);
+        Mockito.when(this.superReq2.getRemoteUser()).thenReturn("sling");
+        this.req2 = new ServletHandlerRequest(this.superReq2, "/myservlet");
     }
 
     @Test
@@ -54,4 +64,30 @@
         Assert.assertEquals("", this.req1.getServletPath());
         Assert.assertEquals("/myservlet", this.req2.getServletPath());
     }
+    
+    @Test
+    public void testGetAuthType()
+    {
+        Assert.assertEquals(HttpServletRequest.BASIC_AUTH, this.req1.getAuthType());
+        Mockito.verify(this.superReq1).getAttribute(HttpContext.AUTHENTICATION_TYPE);
+        Mockito.verifyNoMoreInteractions(this.superReq1);
+        
+        Assert.assertEquals(HttpServletRequest.DIGEST_AUTH, this.req2.getAuthType());
+        Mockito.verify(this.superReq2).getAttribute(HttpContext.AUTHENTICATION_TYPE);
+        Mockito.verify(this.superReq2).getAuthType();
+        Mockito.verifyNoMoreInteractions(this.superReq2);   
+    }
+    
+    @Test
+    public void testGetRemoteUser()
+    {
+        Assert.assertEquals("felix", this.req1.getRemoteUser());
+        Mockito.verify(this.superReq1).getAttribute(HttpContext.REMOTE_USER);
+        Mockito.verifyNoMoreInteractions(this.superReq1);
+        
+        Assert.assertEquals("sling", this.req2.getRemoteUser());
+        Mockito.verify(this.superReq2).getAttribute(HttpContext.REMOTE_USER);
+        Mockito.verify(this.superReq2).getRemoteUser();
+        Mockito.verifyNoMoreInteractions(this.superReq2);   
+    }
 }



Mime
View raw message