You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by GitBox <gi...@apache.org> on 2018/12/15 17:36:12 UTC

[GitHub] rmannibucau commented on a change in pull request #462: Httpsig

rmannibucau commented on a change in pull request #462: Httpsig
URL: https://github.com/apache/cxf/pull/462#discussion_r241955830
 
 

 ##########
 File path: rt/rs/security/http-signature/src/main/java/org/apache/cxf/rs/security/httpsignature/VerifySignatureReaderInterceptor.java
 ##########
 @@ -0,0 +1,107 @@
+/**
+ * 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.httpsignature;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Scanner;
+import java.util.logging.Logger;
+
+import javax.annotation.Priority;
+import javax.ws.rs.Priorities;
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.ext.Provider;
+import javax.ws.rs.ext.ReaderInterceptor;
+import javax.ws.rs.ext.ReaderInterceptorContext;
+
+import org.apache.cxf.common.logging.LogUtils;
+
+
+/**
+ * RS CXF Reader Interceptor which extracts signature data from the message and sends it to the message verifier
+ */
+@Provider
+@Priority(Priorities.AUTHENTICATION)
+public final class VerifySignatureReaderInterceptor implements ReaderInterceptor {
+    private static final Logger LOG = LogUtils.getL7dLogger(VerifySignatureReaderInterceptor.class);
+
+    private MessageVerifier messageVerifier;
+
+    private boolean enabled;
+
+    public VerifySignatureReaderInterceptor() {
+        setEnabled(true);
+        setMessageVerifier(new MessageVerifier(true));
+    }
+
+    @Override
+    public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException, WebApplicationException {
+        if (!enabled) {
+            LOG.fine("Verify signature reader interceptor is disabled");
+            return context.proceed();
+        }
+        LOG.fine("Starting interceptor message verification process");
+
+        Map<String, List<String>> responseHeaders = context.getHeaders();
+
+        String messageBody = extractMessageBody(context);
 
 Review comment:
   maybe use bytes since string will not support all bodies and nothing in the algorithm requires this conversion (byte[] is ok worse case, InputStream with a piping algo is likely better, idea being to pass a stream verifying the digest when the body is read by the messagebodyreader if not a GET or HEAD where the payload must be read upfront)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services