Author: sergeyb
Date: Fri Feb 27 17:04:45 2009
New Revision: 748597
URL: http://svn.apache.org/viewvc?rev=748597&view=rev
Log:
CXF-2073 : fix plus tests
Added:
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/Injectable.java
(with props)
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/SecurityContextImpl.java
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStore.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/client/JAXRSClientFactory.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java?rev=748597&r1=748596&r2=748597&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/JAXRSClientFactory.java
Fri Feb 27 17:04:45 2009
@@ -24,6 +24,8 @@
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
+import org.apache.cxf.Bus;
+import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.common.util.ProxyHelper;
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
import org.apache.cxf.jaxrs.utils.AnnotationUtils;
@@ -72,10 +74,30 @@
return create(baseURI, cls, inheritHeaders, false);
}
+
+ /**
+ * Creates a proxy
+ * @param baseURI baseURI
+ * @param cls proxy class, if not interface then a CGLIB proxy will be
created
+ * @param config Spring configuration file location
+ * @return typed proxy
+ */
+ public static <T> T create(URI baseURI, Class<T> cls, String
configLocation) {
+ SpringBusFactory bf = new SpringBusFactory();
+ Bus bus = bf.createBus(configLocation);
+ JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+ bean.setAddress(baseURI.toString());
+ bean.setServiceClass(cls);
+ bean.setBus(bus);
+ return bean.create(cls);
+ }
+
/**
* Creates a proxy
* @param baseURI baseURI
* @param cls proxy class, if not interface then a CGLIB proxy will be
created
+ * @param inheritHeaders if true then existing proxy headers will be
inherited by
+ * subresource proxies if any
* @param direct if true then no bus and chains will be created
* @return typed proxy
*/
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java?rev=748597&r1=748596&r2=748597&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/client/WebClient.java
Fri Feb 27 17:04:45 2009
@@ -38,6 +38,8 @@
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
+import org.apache.cxf.Bus;
+import org.apache.cxf.bus.spring.SpringBusFactory;
import org.apache.cxf.interceptor.AbstractOutDatabindingInterceptor;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.jaxrs.ext.form.Form;
@@ -215,8 +217,8 @@
* @param path new relative path segment
* @return updated WebClient
*/
- public WebClient path(String path) {
- getCurrentBuilder().path(path);
+ public WebClient path(Object path) {
+ getCurrentBuilder().path(path.toString());
return this;
}
@@ -289,15 +291,27 @@
* @return proxy as a Client
*/
public static Client client(Object proxy) {
- return (Client)proxy;
+ if (proxy instanceof Client) {
+ return (Client)proxy;
+ }
+ return null;
}
- public static WebClient createClient(String baseAddress) {
+
+ public static WebClient createClient(String baseAddress, String
configLocation) {
+ SpringBusFactory bf = new SpringBusFactory();
+ Bus bus = bf.createBus(configLocation);
JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+ bean.setBus(bus);
bean.setAddress(baseAddress);
return bean.createWebClient();
}
+ public static WebClient createClient(String baseAddress) {
+ JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean();
+ bean.setAddress(baseAddress);
+ return bean.createWebClient();
+ }
@Override
public WebClient type(MediaType ct) {
Modified:
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/SecurityContextImpl.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/SecurityContextImpl.java?rev=748597&r1=748596&r2=748597&view=diff
==============================================================================
---
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/SecurityContextImpl.java
(original)
+++
cxf/trunk/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/SecurityContextImpl.java
Fri Feb 27 17:04:45 2009
@@ -44,7 +44,7 @@
public Principal getUserPrincipal() {
org.apache.cxf.security.SecurityContext sc =
-
(org.apache.cxf.security.SecurityContext)m.get(SecurityContext.class);
+
(org.apache.cxf.security.SecurityContext)m.get(org.apache.cxf.security.SecurityContext.class);
return sc == null ? null : sc.getUserPrincipal();
}
@@ -57,7 +57,7 @@
public boolean isUserInRole(String role) {
org.apache.cxf.security.SecurityContext sc =
-
(org.apache.cxf.security.SecurityContext)m.get(SecurityContext.class);
+
(org.apache.cxf.security.SecurityContext)m.get(org.apache.cxf.security.SecurityContext.class);
return sc == null ? false : sc.isUserInRole(role);
}
Modified:
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java?rev=748597&r1=748596&r2=748597&view=diff
==============================================================================
---
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
(original)
+++
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/BookStore.java
Fri Feb 27 17:04:45 2009
@@ -47,6 +47,7 @@
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.PathSegment;
import javax.ws.rs.core.Response;
+import javax.ws.rs.core.SecurityContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.adapters.XmlAdapter;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@@ -68,6 +69,8 @@
private String currentCdId;
@Context
private HttpHeaders httpHeaders;
+ @Context
+ private SecurityContext securityContext;
public BookStore() {
init();
@@ -179,6 +182,16 @@
}
@GET
+ @Path("/securebooks/{bookId}/")
+ @Produces("application/xml")
+ public Book getSecureBook(@PathParam("bookId") String id) throws
BookNotFoundFault {
+ if (!securityContext.isSecure()) {
+ throw new
WebApplicationException(Response.status(403).entity("Unsecure link").build());
+ }
+ return doGetBook(id);
+ }
+
+ @GET
@Path("/books/{bookId}/")
@Produces("application/xml")
public Book getBook(@PathParam("bookId") String id) throws
BookNotFoundFault {
Modified:
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java?rev=748597&r1=748596&r2=748597&view=diff
==============================================================================
---
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
(original)
+++
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerBookTest.java
Fri Feb 27 17:04:45 2009
@@ -45,7 +45,7 @@
@BeforeClass
public static void startServers() throws Exception {
assertTrue("server did not launch correctly",
- launchServer(BookServer.class, true));
+ launchServer(BookServer.class));
}
@Test
Modified:
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java?rev=748597&r1=748596&r2=748597&view=diff
==============================================================================
---
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
(original)
+++
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/JAXRSClientServerResourceCreatedSpringProviderTest.java
Fri Feb 27 17:04:45 2009
@@ -37,7 +37,7 @@
@BeforeClass
public static void startServers() throws Exception {
assertTrue("server did not launch correctly",
-
launchServer(BookServerResourceCreatedSpringProviders.class, true));
+
launchServer(BookServerResourceCreatedSpringProviders.class));
}
@Test
@@ -65,7 +65,7 @@
public void testGetBookNotFound() throws Exception {
String endpointAddress =
- "http://localhost:9081/webapp/bookstore/books/12345";
+ "http://localhost:9080/webapp/bookstore/books/12345";
URL url = new URL(endpointAddress);
HttpURLConnection connect = (HttpURLConnection)url.openConnection();
connect.addRequestProperty("Accept", "text/plain,application/xml");
Added:
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/Injectable.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/Injectable.java?rev=748597&view=auto
==============================================================================
---
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/Injectable.java
(added)
+++
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/Injectable.java
Fri Feb 27 17:04:45 2009
@@ -0,0 +1,25 @@
+/**
+ * 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.security;
+
+import javax.ws.rs.core.SecurityContext;
+
+public interface Injectable {
+ void setSecurityContext(SecurityContext sc);
+}
Propchange:
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/Injectable.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/Injectable.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified:
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java?rev=748597&r1=748596&r2=748597&view=diff
==============================================================================
---
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java
(original)
+++
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/JAXRSHttpsBookTest.java
Fri Feb 27 17:04:45 2009
@@ -55,7 +55,7 @@
BookStore bs = JAXRSClientFactory.create("https://localhost:9095",
BookStore.class);
// just to verify the interface call goes through CGLIB proxy too
assertEquals("https://localhost:9095",
WebClient.client(bs).getBaseURI().toString());
- Book b = bs.getBook("123");
+ Book b = bs.getSecureBook("123");
assertEquals(b.getId(), 123);
}
@@ -71,7 +71,7 @@
WebClient client = bean.createWebClient();
assertEquals("https://localhost:9095", client.getBaseURI().toString());
-
client.path("/bookstore/books/123").accept(MediaType.APPLICATION_XML_TYPE);
+
client.path("/bookstore/securebooks/123").accept(MediaType.APPLICATION_XML_TYPE);
Book b = client.get(Book.class);
assertEquals(123, b.getId());
}
Modified:
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStore.java
URL:
http://svn.apache.org/viewvc/cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStore.java?rev=748597&r1=748596&r2=748597&view=diff
==============================================================================
---
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStore.java
(original)
+++
cxf/trunk/systests/src/test/java/org/apache/cxf/systest/jaxrs/security/SecureBookStore.java
Fri Feb 27 17:04:45 2009
@@ -24,14 +24,18 @@
import javax.annotation.Resource;
import javax.ws.rs.Path;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.SecurityContext;
import org.apache.cxf.systest.jaxrs.Book;
import org.apache.cxf.systest.jaxrs.BookNotFoundFault;
@Path("/bookstorestorage/")
-public class SecureBookStore implements SecureBookInterface {
+public class SecureBookStore implements SecureBookInterface, Injectable {
private Map<Long, Book> books = new HashMap<Long, Book>();
private SecureBookInterface subresource;
+ private SecurityContext securityContext;
public SecureBookStore() {
Book book = new Book();
@@ -40,6 +44,11 @@
books.put(book.getId(), book);
}
+ @Context
+ public void setSecurityContext(SecurityContext sc) {
+ securityContext = sc;
+ }
+
@Resource
public void setBookStore(SecureBookInterface sb) {
subresource = sb;
@@ -57,7 +66,11 @@
}
public Book getThatBook() throws BookNotFoundFault {
- return books.get(123L);
+ if (securityContext.isUserInRole("ROLE_ADMIN")
+ && !securityContext.isUserInRole("ROLE_BAZ")) {
+ return books.get(123L);
+ }
+ throw new WebApplicationException(403);
}
public SecureBookInterface getBookSubResource() throws BookNotFoundFault {
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=748597&r1=748596&r2=748597&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 Fri
Feb 27 17:04:45 2009
@@ -69,6 +69,7 @@
<security:user-service>
<security:user name="bob" password="bobspassword"
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>
</security:authentication-provider>
</beans>