Author: ffang
Date: Mon Jul 29 09:38:14 2013
New Revision: 1507985

URL: http://svn.apache.org/r1507985
Log:
Merged revisions 1507984 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r1507984 | ffang | 2013-07-29 17:31:48 +0800 (δΈ€, 29  7 2013) | 1 line
  
  [CXF-5165]add a JAAS authenticator for ServiceListPage
........

Added:
    
cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListJAASAuthenticator.java
      - copied unchanged from r1507984, 
cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListJAASAuthenticator.java
Modified:
    cxf/branches/2.7.x-fixes/   (props changed)
    
cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
    
cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java
    
cxf/branches/2.7.x-fixes/rt/transports/http/src/main/resources/OSGI-INF/blueprint/osgiservlet.xml

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
  Merged /cxf/trunk:r1507984

Propchange: cxf/branches/2.7.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: 
cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
URL: 
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java?rev=1507985&r1=1507984&r2=1507985&view=diff
==============================================================================
--- 
cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
 (original)
+++ 
cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/ServletController.java
 Mon Jul 29 09:38:14 2013
@@ -44,12 +44,17 @@ import org.apache.cxf.transports.http.Qu
 import org.apache.cxf.transports.http.QueryHandlerRegistry;
 
 public class ServletController {
+    
+    public static final String AUTH_SERVICE_LIST = "auth.service.list";
+    public static final String AUTH_SERVICE_LIST_REALM = 
"auth.service.list.realm";
     protected static final String DEFAULT_LISTINGS_CLASSIFIER = "/services";
     private static final Logger LOG = 
LogUtils.getL7dLogger(ServletController.class);
     private static final String HTTP_PREFIX = "http";
-    
+        
     protected boolean isHideServiceList;
+    protected boolean isAuthServiceListPage;
     protected boolean disableAddressUpdates;
+    protected String authServiceListPageRealm;
     protected String forcedBaseAddress;
     protected String serviceListRelativePath = DEFAULT_LISTINGS_CLASSIFIER;
     protected ServletConfig servletConfig;
@@ -112,6 +117,17 @@ public class ServletController {
         if (!StringUtils.isEmpty(hideServiceList)) {
             this.isHideServiceList = Boolean.valueOf(hideServiceList);
         }
+        
+        String authServiceListPage = 
servletConfig.getInitParameter("service-list-page-authenticate");
+        if (!StringUtils.isEmpty(authServiceListPage)) {
+            this.isAuthServiceListPage = Boolean.valueOf(authServiceListPage);
+        }
+        
+        String authServiceListRealm = 
servletConfig.getInitParameter("service-list-page-authenticate-realm");
+        if (!StringUtils.isEmpty(authServiceListRealm)) {
+            this.authServiceListPageRealm = authServiceListRealm;
+        }
+        
         String isDisableAddressUpdates = 
servletConfig.getInitParameter("disable-address-updates");
         if (!StringUtils.isEmpty(isDisableAddressUpdates)) {
             this.disableAddressUpdates = 
Boolean.valueOf(isDisableAddressUpdates);
@@ -147,6 +163,9 @@ public class ServletController {
                     || 
request.getRequestURI().endsWith(serviceListRelativePath + "/")
                     || StringUtils.isEmpty(pathInfo)
                     || "/".equals(pathInfo))) {
+                    if (isAuthServiceListPage) {
+                        setAuthServiceListPageAttribute(request);
+                    }
                     setBaseURLAttribute(request);
                     serviceListGenerator.service(request, res);
                 } else {
@@ -213,6 +232,12 @@ public class ServletController {
         return true;
     }
 
+    private void setAuthServiceListPageAttribute(HttpServletRequest request) {
+        request.setAttribute(ServletController.AUTH_SERVICE_LIST, 
this.isAuthServiceListPage);
+        request.setAttribute(ServletController.AUTH_SERVICE_LIST_REALM, 
this.authServiceListPageRealm);
+        
+    }
+
     public void invokeDestination(final HttpServletRequest request, 
HttpServletResponse response,
                                   AbstractHTTPDestination d) throws 
ServletException {
         if (LOG.isLoggable(Level.FINE)) {

Modified: 
cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java
URL: 
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java?rev=1507985&r1=1507984&r2=1507985&view=diff
==============================================================================
--- 
cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java
 (original)
+++ 
cxf/branches/2.7.x-fixes/rt/transports/http/src/main/java/org/apache/cxf/transport/servlet/servicelist/ServiceListGeneratorServlet.java
 Mon Jul 29 09:38:14 2013
@@ -39,6 +39,7 @@ import org.apache.cxf.message.Message;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.AbstractDestination;
 import org.apache.cxf.transport.http.DestinationRegistry;
+import org.apache.cxf.transport.servlet.ServletController;
 
 public class ServiceListGeneratorServlet extends HttpServlet {
     private static final long serialVersionUID = -113918058557537996L;
@@ -67,6 +68,19 @@ public class ServiceListGeneratorServlet
     @Override
     public void service(HttpServletRequest request, 
                         HttpServletResponse response) throws ServletException, 
IOException {
+        Object obj = request.getAttribute(ServletController.AUTH_SERVICE_LIST);
+        boolean isAuthServiceList = false;
+        if (obj != null) {
+            isAuthServiceList = Boolean.valueOf(obj.toString());
+        }
+        if (isAuthServiceList) {
+            String authServiceListRealm = 
(String)request.getAttribute(ServletController.AUTH_SERVICE_LIST_REALM);
+            ServiceListJAASAuthenticator authenticator = new 
ServiceListJAASAuthenticator();
+            authenticator.setRealm(authServiceListRealm);
+            if (!authenticator.authenticate(request, response)) {
+                return;
+            }
+        }
         PrintWriter writer = response.getWriter();
         AbstractDestination[] destinations = 
destinationRegistry.getSortedDestinations();
         if (request.getParameter("stylesheet") != null) {

Modified: 
cxf/branches/2.7.x-fixes/rt/transports/http/src/main/resources/OSGI-INF/blueprint/osgiservlet.xml
URL: 
http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/transports/http/src/main/resources/OSGI-INF/blueprint/osgiservlet.xml?rev=1507985&r1=1507984&r2=1507985&view=diff
==============================================================================
--- 
cxf/branches/2.7.x-fixes/rt/transports/http/src/main/resources/OSGI-INF/blueprint/osgiservlet.xml
 (original)
+++ 
cxf/branches/2.7.x-fixes/rt/transports/http/src/main/resources/OSGI-INF/blueprint/osgiservlet.xml
 Mon Jul 29 09:38:14 2013
@@ -39,7 +39,8 @@ under the License.
       <cm:property name="org.apache.cxf.servlet.redirect-servlet-name" 
value=""/>
       <cm:property name="org.apache.cxf.servlet.redirect-servlet-path" 
value=""/>
       <cm:property name="org.apache.cxf.servlet.service-list-all-contexts" 
value=""/>
-
+      <cm:property 
name="org.apache.cxf.servlet.service-list-page-authenticate" value="false"/>
+      <cm:property 
name="org.apache.cxf.servlet.service-list-page-authenticate-realm" 
value="karaf"/>
     </cm:default-properties>
 
   </cm:property-placeholder>
@@ -64,6 +65,8 @@ under the License.
       <entry key="redirect-servlet-name" 
value="${org.apache.cxf.servlet.redirect-servlet-name}"/>
       <entry key="redirect-servlet-path" 
value="${org.apache.cxf.servlet.redirect-servlet-path}"/>
       <entry key="service-list-all-contexts" 
value="${org.apache.cxf.servlet.service-list-all-contexts}"/>
+      <entry key="service-list-page-authenticate" 
value="${org.apache.cxf.servlet.service-list-page-authenticate}"/>
+      <entry key="service-list-page-authenticate-realm" 
value="${org.apache.cxf.servlet.service-list-page-authenticate-realm}"/>
     </service-properties>
   </service>
 


Reply via email to