cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r770220 - in /cxf/trunk: rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/ systests/src/test/java/org/apache/cxf/systest/jaxrs/ systests/src/test/java/org/apache/cxf/systest/jaxrs/security/ systests/src/test/resources/jaxrs_security/WEB...
Date Thu, 30 Apr 2009 13:38:26 GMT
Author: sergeyb
Date: Thu Apr 30 13:38:26 2009
New Revision: 770220

URL: http://svn.apache.org/viewvc?rev=770220&view=rev
Log:
JAXRS: support for custom invokers injected from Spring

Added:
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomJAXRSInvoker.java
  (with props)
Modified:
    cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
    cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java
    cxf/trunk/systests/src/test/resources/jaxrs_security/WEB-INF/beans.xml

Modified: cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java?rev=770220&r1=770219&r2=770220&view=diff
==============================================================================
--- cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
(original)
+++ cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/JAXRSServerFactoryBean.java
Thu Apr 30 13:38:26 2009
@@ -56,7 +56,6 @@
     protected Map<Class, ResourceProvider> resourceProviders = new HashMap<Class,
ResourceProvider>();
     
     private Server server;
-    private Invoker invoker;
     private boolean start = true;
     private Map<Object, Object> languageMappings;
     private Map<Object, Object> extensionMappings;
@@ -87,6 +86,7 @@
                                     getDestinationFactory(), 
                                     getBindingFactory());
 
+            Invoker invoker = serviceFactory.getInvoker(); 
             if (invoker == null) {
                 ep.getService().setInvoker(createInvoker());
             } else {
@@ -167,7 +167,7 @@
     }
 
     public void setInvoker(Invoker invoker) {
-        this.invoker = invoker;
+        serviceFactory.setInvoker(invoker);
     }
 
     public void setStart(boolean start) {

Added: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomJAXRSInvoker.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomJAXRSInvoker.java?rev=770220&view=auto
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomJAXRSInvoker.java
(added)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomJAXRSInvoker.java
Thu Apr 30 13:38:26 2009
@@ -0,0 +1,51 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.systest.jaxrs;
+
+import java.lang.reflect.Method;
+import java.security.Principal;
+
+import javax.ws.rs.core.Response;
+
+import org.apache.cxf.common.util.ClassHelper;
+import org.apache.cxf.jaxrs.JAXRSInvoker;
+import org.apache.cxf.jaxrs.impl.SecurityContextImpl;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.message.Exchange;
+import org.apache.cxf.message.MessageContentsList;
+import org.apache.cxf.systest.jaxrs.security.SecureBookStore;
+
+public class CustomJAXRSInvoker extends JAXRSInvoker {
+
+    @Override
+    public Object invoke(Exchange exchange, Object requestParams, Object resourceObject)
{
+        
+        OperationResourceInfo ori = exchange.get(OperationResourceInfo.class);
+        Method m = ori.getMethodToInvoke();
+        Class<?> realClass = ClassHelper.getRealClass(resourceObject);
+        
+        Principal p = new SecurityContextImpl(exchange.getInMessage()).getUserPrincipal();
+        if (realClass == SecureBookStore.class && "getThatBook".equals(m.getName())
+            && "baddy".equals(p.getName())) {
+            return new MessageContentsList(Response.status(Response.Status.FORBIDDEN).build());
+        }
+        
+        return super.invoke(exchange, requestParams, resourceObject);
+    }
+}

Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomJAXRSInvoker.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/CustomJAXRSInvoker.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java?rev=770220&r1=770219&r2=770220&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java
(original)
+++ cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSSpringSecurityInterfaceTest.java
Thu Apr 30 13:38:26 2009
@@ -58,6 +58,7 @@
             "http://localhost:9080/bookstorestorage/thosebooks/123/123"; 
         getBook(endpointAddress, "foo", "bar", 200);
         getBook(endpointAddress, "bob", "bobspassword", 200);
+        getBook(endpointAddress, "baddy", "baddyspassword", 403);
     }
     
     @Test

Modified: cxf/trunk/systests/src/test/resources/jaxrs_security/WEB-INF/beans.xml
URL: http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/resources/jaxrs_security/WEB-INF/beans.xml?rev=770220&r1=770219&r2=770220&view=diff
==============================================================================
--- cxf/trunk/systests/src/test/resources/jaxrs_security/WEB-INF/beans.xml (original)
+++ cxf/trunk/systests/src/test/resources/jaxrs_security/WEB-INF/beans.xml Thu Apr 30 13:38:26
2009
@@ -51,6 +51,10 @@
     <jaxrs:providers>
         <bean class="org.apache.cxf.systest.jaxrs.security.SecurityExceptionMapper"/>
     </jaxrs:providers>		   
+    <jaxrs:invoker>
+        <bean class="org.apache.cxf.systest.jaxrs.CustomJAXRSInvoker"/> 
+    </jaxrs:invoker>
+    
   </jaxrs:server>
 
   <bean id="bookstore" class="org.apache.cxf.systest.jaxrs.security.SecureBookStore">
@@ -68,6 +72,7 @@
   <security:authentication-provider>
     <security:user-service>
       <security:user name="bob" password="bobspassword" authorities="ROLE_USER" />
+      <security:user name="baddy" password="baddyspassword" authorities="ROLE_USER" />
       <security:user name="foo" password="bar" authorities="ROLE_USER, ROLE_ADMIN" />
       <security:user name="baz" password="baz" authorities="ROLE_BAZ" />
     </security:user-service>



Mime
View raw message