Repository: cxf
Updated Branches:
refs/heads/3.1.x-fixes e49ef9dbd -> 20d0fa3ec
Finalizing XmlSecInInterceptor updates
Conflicts:
rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptor.java
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/20d0fa3e
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/20d0fa3e
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/20d0fa3e
Branch: refs/heads/3.1.x-fixes
Commit: 20d0fa3ec41c16c52b74dcc006f9d9ea212fa80f
Parents: e49ef9d
Author: Sergey Beryozkin <[email protected]>
Authored: Mon Mar 27 22:10:55 2017 +0100
Committer: Sergey Beryozkin <[email protected]>
Committed: Mon Mar 27 22:16:07 2017 +0100
----------------------------------------------------------------------
.../security/xml/ClientXmlSecInInterceptor.java | 46 ------------------
.../rs/security/xml/XmlSecInInterceptor.java | 51 ++++++++++++++------
2 files changed, 35 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/20d0fa3e/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/ClientXmlSecInInterceptor.java
----------------------------------------------------------------------
diff --git
a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/ClientXmlSecInInterceptor.java
b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/ClientXmlSecInInterceptor.java
deleted file mode 100644
index cfbc508..0000000
---
a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/ClientXmlSecInInterceptor.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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.rs.security.xml;
-
-import java.io.IOException;
-
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.ext.ReaderInterceptor;
-import javax.ws.rs.ext.ReaderInterceptorContext;
-
-import org.apache.cxf.jaxrs.utils.JAXRSUtils;
-import org.apache.cxf.message.Message;
-
-public class ClientXmlSecInInterceptor extends XmlSecInInterceptor implements
ReaderInterceptor {
-
- @Override
- public Object aroundReadFrom(ReaderInterceptorContext ctx) throws
IOException, WebApplicationException {
- Message message = JAXRSUtils.getCurrentMessage();
- handleMessage(message);
- Object object = ctx.proceed();
- new StaxActionInInterceptor(super.isRequireSignature(),
-
super.isRequireEncryption()).handleMessage(message);
- return object;
- }
-
- @Override
- protected void registerStaxActionInInterceptor(Message inMsg) {
- // complete
- }
-}
http://git-wip-us.apache.org/repos/asf/cxf/blob/20d0fa3e/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptor.java
----------------------------------------------------------------------
diff --git
a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptor.java
b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptor.java
index aefecb3..3ce1047 100644
---
a/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptor.java
+++
b/rt/rs/security/xml/src/main/java/org/apache/cxf/rs/security/xml/XmlSecInInterceptor.java
@@ -34,7 +34,10 @@ import java.util.regex.PatternSyntaxException;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
+import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.ReaderInterceptorContext;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
@@ -44,6 +47,7 @@ import org.apache.cxf.interceptor.StaxInInterceptor;
import org.apache.cxf.jaxrs.utils.ExceptionUtils;
import org.apache.cxf.jaxrs.utils.JAXRSUtils;
import org.apache.cxf.message.Message;
+import org.apache.cxf.message.MessageUtils;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.apache.cxf.rs.security.common.CryptoLoader;
@@ -72,8 +76,8 @@ import
org.apache.xml.security.stax.securityToken.SecurityToken;
/**
* A new StAX-based interceptor for processing messages with XML Signature +
Encryption content.
*/
-public class XmlSecInInterceptor extends AbstractPhaseInterceptor<Message> {
-
+public class XmlSecInInterceptor extends AbstractPhaseInterceptor<Message>
implements ReaderInterceptor {
+
private static final Logger LOG =
LogUtils.getL7dLogger(XmlSecInInterceptor.class);
private EncryptionProperties encryptionProperties;
@@ -94,13 +98,15 @@ public class XmlSecInInterceptor extends
AbstractPhaseInterceptor<Message> {
}
public void handleMessage(Message message) throws Fault {
- String method = (String)message.get(Message.HTTP_REQUEST_METHOD);
- if ("GET".equals(method)) {
+ if (isServerGet(message)) {
return;
}
-
- Message outMs = message.getExchange().getOutMessage();
- Message inMsg = outMs == null ? message :
outMs.getExchange().getInMessage();
+ prepareMessage(message);
+ message.getInterceptorChain().add(
+ new StaxActionInInterceptor(requireSignature,
requireEncryption));
+ }
+
+ private void prepareMessage(Message inMsg) throws Fault {
XMLStreamReader originalXmlStreamReader =
inMsg.getContent(XMLStreamReader.class);
if (originalXmlStreamReader == null) {
@@ -110,8 +116,6 @@ public class XmlSecInInterceptor extends
AbstractPhaseInterceptor<Message> {
}
}
- registerStaxActionInInterceptor(inMsg);
-
try {
XMLSecurityProperties properties = new XMLSecurityProperties();
configureDecryptionKeys(inMsg, properties);
@@ -137,12 +141,12 @@ public class XmlSecInInterceptor extends
AbstractPhaseInterceptor<Message> {
}
}
- protected void registerStaxActionInInterceptor(Message inMsg) {
- inMsg.getInterceptorChain().add(
- new StaxActionInInterceptor(requireSignature, requireEncryption));
-
+ private boolean isServerGet(Message message) {
+ String method = (String)message.get(Message.HTTP_REQUEST_METHOD);
+ return "GET".equals(method) && !MessageUtils.isRequestor(message);
}
+
private void configureDecryptionKeys(Message message,
XMLSecurityProperties properties)
throws IOException,
UnsupportedCallbackException, WSSecurityException {
@@ -399,14 +403,29 @@ public class XmlSecInInterceptor extends
AbstractPhaseInterceptor<Message> {
}
return subjectDNPatterns;
}
+
+ @Override
+ public Object aroundReadFrom(ReaderInterceptorContext ctx) throws
IOException, WebApplicationException {
+ Message message = JAXRSUtils.getCurrentMessage();
+ if (isServerGet(message)) {
+ return ctx.proceed();
+ } else {
+ prepareMessage(message);
+ Object object = ctx.proceed();
+ new StaxActionInInterceptor(requireSignature,
+
requireEncryption).handleMessage(message);
+ return object;
+ }
+
+ }
/**
* This interceptor handles parsing the StaX results (events) + checks to
see whether the
* required (if any) Actions (signature or encryption) were fulfilled.
*/
- protected static class StaxActionInInterceptor extends
AbstractPhaseInterceptor<Message> {
-
- private static final Logger LOG =
+ private static class StaxActionInInterceptor extends
AbstractPhaseInterceptor<Message> {
+
+ private static final Logger LOG =
LogUtils.getL7dLogger(StaxActionInInterceptor.class);
private final boolean signatureRequired;