This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
36 changed files
with
2,484 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
zanata-war/src/main/java/org/zanata/rest/ZanataJacksonJsonProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
38 changes: 17 additions & 21 deletions
38
zanata-war/src/main/java/org/zanata/rest/ZanataRestSecurityInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
} | ||
} |
54 changes: 29 additions & 25 deletions
54
zanata-war/src/main/java/org/zanata/rest/ZanataRestVersionInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.