Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 71d284b
Author: Patrick Huang <pahuang@redhat.com>
Date:   Thu Jun 18 16:42:49 2015 +1000

    minor change

commit 5e95215
Merge: 772525a b817e15
Author: Patrick Huang <pahuang@redhat.com>
Date:   Thu Jun 18 13:55:21 2015 +1000

    Merge branch 'integration/master' into resteasy3

    Conflicts:
    	zanata-war/src/main/webapp-jboss/WEB-INF/jboss-deployment-structure.xml
    	zanata-war/src/test/java/org/zanata/rest/RestLimitingSynchronousDispatcherTest.java
    	zanata-war/src/test/java/org/zanata/rest/editor/dto/TransUnitTest.java

commit 772525a
Author: Patrick Huang <pahuang@redhat.com>
Date:   Thu Jun 18 13:49:01 2015 +1000

    use jboss module instead of packaging the jar (javax.inject-api)

commit 11e8fca
Author: Patrick Huang <pahuang@redhat.com>
Date:   Thu Jun 18 11:59:46 2015 +1000

    fix functional test

commit 1c34b8b
Author: Patrick Huang <pahuang@redhat.com>
Date:   Wed Jun 17 14:15:11 2015 +1000

    fix all static analysis error and added enforcer rule for stax-api conflict

commit 459b17f
Author: Patrick Huang <pahuang@redhat.com>
Date:   Wed Jun 17 12:54:03 2015 +1000

    fix duplicate class finder error

commit 9c0b497
Author: Patrick Huang <pahuang@redhat.com>
Date:   Wed Jun 17 12:08:52 2015 +1000

    fix dependency check

commit 20f4ce8
Author: Patrick Huang <pahuang@redhat.com>
Date:   Wed Jun 17 11:36:11 2015 +1000

    override built-in RESTEasy Jackson provider to NOT use JAXB annotation

commit 5a15bcc
Author: Patrick Huang <pahuang@redhat.com>
Date:   Tue Jun 16 15:01:46 2015 +1000

    fix integration test

commit f1a74e9
Author: Carlos A. Munoz <camunoz@redhat.com>
Date:   Thu Jun 11 11:48:47 2015 +1000

    Fix a failing test.

commit efabd4e
Author: Carlos A. Munoz <camunoz@redhat.com>
Date:   Fri Jun 5 11:03:50 2015 +1000

    Fixes for Resteasy3

    Disble Java EE modules from EAP/Wildfly
    Enable Providers via Seam2
    Adjust Arquillian packaging.

commit 2b08324
Author: Sean Flanigan <sflaniga@redhat.com>
Date:   Fri May 29 14:51:58 2015 +1000

    Make enforcer happy

commit f1e8935
Author: Sean Flanigan <sflaniga@redhat.com>
Date:   Fri May 29 13:08:31 2015 +1000

    Upgrade to RESTEasy 3
  • Loading branch information
Patrick Huang committed Jun 26, 2015
1 parent 9988b4b commit 766cfc0
Show file tree
Hide file tree
Showing 36 changed files with 2,484 additions and 109 deletions.
23 changes: 22 additions & 1 deletion pom.xml
Expand Up @@ -97,7 +97,7 @@
<jdbc.version>5.1.26</jdbc.version>

<resteasy.scope>compile</resteasy.scope>
<resteasy.version>2.3.7.Final</resteasy.version>
<resteasy.version>3.0.11.Final</resteasy.version>

<cargo.extract.dir>${project.build.directory}/cargo/installs</cargo.extract.dir>
<!-- This URL must be set by a profile (wildfly), settings.xml or mvn command line -->
Expand Down Expand Up @@ -187,6 +187,12 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.sun.xml.fastinfoset</groupId>
<artifactId>FastInfoset</artifactId>
<version>1.2.12</version>
</dependency>

<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam</artifactId>
Expand Down Expand Up @@ -248,6 +254,12 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.4</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
Expand Down Expand Up @@ -494,6 +506,12 @@
<groupId>org.zanata</groupId>
<artifactId>zanata-adapter-xliff</artifactId>
<version>${zanata.common.version}</version>
<exclusions>
<exclusion>
<groupId>javax.xml.bind</groupId>
<artifactId>jsr173_api</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- zanata client -->
Expand Down Expand Up @@ -1244,6 +1262,9 @@

<!-- use org.jboss.spec.javax.annotation:jboss-annotations-api_1.1_spec -->
<exclude>org.jboss.spec.javax.annotation:jboss-annotations-api_1.2_spec</exclude>

<!-- use jdk and javax.xml.stream:stax-api -->
<exclude>javax.xml.bind:jsr173_api</exclude>
</excludes>
</bannedDependencies>
<requireNoRepositories>
Expand Down
18 changes: 4 additions & 14 deletions zanata-war/pom.xml
Expand Up @@ -154,8 +154,6 @@
<usedDependency>org.hibernate:hibernate-testing</usedDependency>
<usedDependency>org.jboss.arquillian.junit:arquillian-junit-container</usedDependency>
<usedDependency>org.jboss.arquillian.protocol:arquillian-protocol-servlet</usedDependency>
<!-- Used by JSON (RestEasy) -->
<usedDependency>org.jboss.resteasy:resteasy-jackson-provider</usedDependency>
<usedDependency>org.codehaus.jackson:jackson-xc</usedDependency>
<!-- Used in arquillian test - zanata-war/arquillian/components.properties -->
<usedDependency>org.jboss.seam:jboss-seam-debug</usedDependency>
Expand Down Expand Up @@ -1409,10 +1407,6 @@

<!-- RestEasy dependencies -->

<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam-resteasy</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
Expand Down Expand Up @@ -1455,6 +1449,10 @@
<artifactId>resteasy-multipart-provider</artifactId>
<scope>${resteasy.scope}</scope>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
Expand Down Expand Up @@ -2148,18 +2146,10 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.2.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.2.5</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- openid4java -->
Expand Down
Expand Up @@ -31,7 +31,6 @@
import org.jboss.resteasy.spi.HttpResponse;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.UnhandledException;
import org.jboss.seam.resteasy.SeamResteasyProviderFactory;
import org.jboss.seam.security.management.JpaIdentityStore;
import org.jboss.seam.web.ServletContexts;
import org.zanata.dao.AccountDAO;
Expand All @@ -42,6 +41,7 @@
import com.google.common.base.Throwables;
import lombok.extern.slf4j.Slf4j;

import org.zanata.seam.resteasy.SeamResteasyProviderFactory;
import org.zanata.security.SecurityFunctions;
import org.zanata.util.HttpUtil;
import org.zanata.util.ServiceLocator;
Expand Down Expand Up @@ -100,7 +100,7 @@ public void invoke(final HttpRequest request, final HttpResponse response) {
}

if(!SecurityFunctions.canAccessRestPath(authenticatedUser,
request.getHttpMethod(), request.getPreprocessedPath())) {
request.getHttpMethod(), request.getUri().getMatchingPath())) {

/**
* Not using response.sendError because the app server will generate
Expand Down
@@ -0,0 +1,68 @@
/*
* Copyright 2015, Red Hat, Inc. and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.zanata.rest;

import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import javax.ws.rs.Consumes;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.ext.Provider;

import org.codehaus.jackson.jaxrs.Annotations;
import org.codehaus.jackson.jaxrs.JacksonJsonProvider;
import org.jboss.resteasy.annotations.providers.NoJackson;
import org.jboss.resteasy.util.FindAnnotation;

/**
* ResteasyJacksonProvider will use JAXB annotation as well as Jackson. This is
* different from RESTEasy 2 which only use Jackson annotations. We need to
* override this to make our REST api backward compatible.
*
* @author Patrick Huang <a
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
@Provider
@Consumes({ "application/*+json", "text/json" })
@Produces({ "application/*+json", "text/json" })
public class ZanataJacksonJsonProvider extends JacksonJsonProvider {
public ZanataJacksonJsonProvider() {
super(Annotations.JACKSON);
}

@Override
public boolean isReadable(Class<?> aClass, Type type,
Annotation[] annotations, MediaType mediaType) {
if (FindAnnotation
.findAnnotation(aClass, annotations, NoJackson.class) != null)
return false;
return super.isReadable(aClass, type, annotations, mediaType);
}

@Override
public boolean isWriteable(Class<?> aClass, Type type,
Annotation[] annotations, MediaType mediaType) {
if (FindAnnotation
.findAnnotation(aClass, annotations, NoJackson.class) != null)
return false;
return super.isWriteable(aClass, type, annotations, mediaType);
}
}
@@ -1,48 +1,44 @@
package org.zanata.rest;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.Provider;

import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang.StringUtils;
import org.jboss.resteasy.annotations.interception.SecurityPrecedence;
import org.jboss.resteasy.annotations.interception.ServerInterceptor;
import org.jboss.resteasy.core.ResourceMethod;
import org.jboss.resteasy.core.ServerResponse;
import org.jboss.resteasy.spi.Failure;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.interception.PreProcessInterceptor;
import org.zanata.security.SecurityFunctions;
import org.zanata.security.ZanataIdentity;
import org.zanata.util.HttpUtil;

import java.io.IOException;

@Provider
@SecurityPrecedence
@ServerInterceptor
@Slf4j
public class ZanataRestSecurityInterceptor implements PreProcessInterceptor {
public class ZanataRestSecurityInterceptor implements ContainerRequestFilter {

@Override
public ServerResponse
preProcess(HttpRequest request, ResourceMethod method)
throws Failure, WebApplicationException {

String username = HttpUtil.getUsername(request);
String apiKey = HttpUtil.getApiKey(request);
if (StringUtils.isNotEmpty(username)|| StringUtils.isNotEmpty(apiKey)) {
public void filter(ContainerRequestContext context)
throws IOException {
String username = HttpUtil.getUsername(context.getHeaders());
String apiKey = HttpUtil.getApiKey(context.getHeaders());
if (StringUtils.isNotEmpty(username) || StringUtils.isNotEmpty(apiKey)) {
ZanataIdentity.instance().getCredentials().setUsername(username);
ZanataIdentity.instance().setApiKey(apiKey);
ZanataIdentity.instance().tryLogin();
if (!SecurityFunctions.canAccessRestPath(ZanataIdentity.instance(),
request.getHttpMethod(), request.getPreprocessedPath())) {
context.getMethod(), context.getUriInfo().getPath())) {
log.info(InvalidApiKeyUtil.getMessage(username, apiKey));
return ServerResponse.copyIfNotServerResponse(Response.status(
Status.UNAUTHORIZED).entity(
InvalidApiKeyUtil.getMessage(username, apiKey))
.build());
context.abortWith(Response.status(Status.UNAUTHORIZED)
.entity(InvalidApiKeyUtil.getMessage(username, apiKey))
.build());
}
}
return null;

}
}
@@ -1,46 +1,50 @@
package org.zanata.rest;

import static org.jboss.seam.ScopeType.APPLICATION;

import javax.ws.rs.ConstrainedTo;
import javax.ws.rs.RuntimeType;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.Provider;
import javax.ws.rs.ext.ReaderInterceptor;
import javax.ws.rs.ext.ReaderInterceptorContext;

import org.jboss.resteasy.annotations.interception.HeaderDecoratorPrecedence;
import org.jboss.resteasy.annotations.interception.ServerInterceptor;
import org.jboss.resteasy.core.ResourceMethod;
import org.jboss.resteasy.core.ServerResponse;
import org.jboss.resteasy.spi.Failure;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.interception.PreProcessInterceptor;
import org.zanata.rest.service.RestUtils;
import org.zanata.service.impl.VersionManager;
import org.zanata.util.ServiceLocator;
import org.zanata.util.VersionUtility;

@ServerInterceptor
import java.io.IOException;

@ConstrainedTo(RuntimeType.SERVER)
@Provider
@HeaderDecoratorPrecedence
public class ZanataRestVersionInterceptor implements PreProcessInterceptor {
public class ZanataRestVersionInterceptor implements ReaderInterceptor {

@Override
public ServerResponse
preProcess(HttpRequest request, ResourceMethod method)
throws Failure, WebApplicationException {
public Object aroundReadFrom(ReaderInterceptorContext context)
throws IOException, WebApplicationException {
MultivaluedMap<String, String> headers = context.getHeaders();
String clientApiVer =
request.getHttpHeaders().getRequestHeaders()
.getFirst(RestConstant.HEADER_VERSION_NO);
headers.getFirst(RestConstant.HEADER_VERSION_NO);
String serverApiVer = VersionUtility.getAPIVersionInfo().getVersionNo();
VersionManager verManager =
ServiceLocator.instance().getInstance(VersionManager.class);

return verManager.checkVersion(clientApiVer, serverApiVer) ? null
: ServerResponse
.copyIfNotServerResponse(Response
.status(Status.PRECONDITION_FAILED)
.entity("Client API Version '"
+ clientApiVer
+ "' and Server API Version '"
+ serverApiVer
+ "' do not match. Please update your Zanata client")
.build());
// NB checkVersion doesn't actually reject outdated versions yet
return verManager.checkVersion(clientApiVer, serverApiVer) ?
context.proceed() :
RestUtils.copyIfNotServerResponse(Response
.status(Status.PRECONDITION_FAILED)
.entity("Client API Version '"
+ clientApiVer
+ "' and Server API Version '"
+ serverApiVer
+
"' do not match. Please update your Zanata client")
.build());
}

}
Expand Up @@ -15,8 +15,8 @@
import org.jboss.seam.annotations.Startup;
import org.jboss.seam.deployment.AnnotationDeploymentHandler;
import org.jboss.seam.deployment.HotDeploymentStrategy;
import org.jboss.seam.resteasy.ResteasyBootstrap;
import org.jboss.seam.resteasy.SeamResteasyProviderFactory;
import org.zanata.seam.resteasy.ResteasyBootstrap;
import org.zanata.seam.resteasy.SeamResteasyProviderFactory;

@Name("org.jboss.seam.resteasy.bootstrap")
@Scope(ScopeType.APPLICATION)
Expand Down Expand Up @@ -47,17 +47,6 @@ public void registerHotDeployedClasses() {
}
}

@Override
protected void initDispatcher() {
super.initDispatcher();
getDispatcher().getProviderFactory()
.getServerPreProcessInterceptorRegistry()
.register(ZanataRestSecurityInterceptor.class);
getDispatcher().getProviderFactory()
.getServerPreProcessInterceptorRegistry()
.register(ZanataRestVersionInterceptor.class);
}

@Override
protected Dispatcher createDispatcher(
SeamResteasyProviderFactory providerFactory) {
Expand Down

0 comments on commit 766cfc0

Please sign in to comment.