You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by di...@apache.org on 2019/08/22 16:45:28 UTC

[airavata-custos] 10/13: Adding a custom authorization filter

This is an automated email from the ASF dual-hosted git repository.

dimuthuupe pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git

commit 5c795999ad1bba7ad657f8b796f55e3bf862c6e7
Author: Dimuthu Wannipurage <di...@gmail.com>
AuthorDate: Thu Jul 11 01:19:02 2019 -0400

    Adding a custom authorization filter
---
 .../custos/credential/api/filters/AuthFilter.java  | 59 ++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/credential-store/credential-api/src/main/java/org/apache/custos/credential/api/filters/AuthFilter.java b/credential-store/credential-api/src/main/java/org/apache/custos/credential/api/filters/AuthFilter.java
new file mode 100644
index 0000000..b080142
--- /dev/null
+++ b/credential-store/credential-api/src/main/java/org/apache/custos/credential/api/filters/AuthFilter.java
@@ -0,0 +1,59 @@
+/*
+ *
+ * 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.custos.credential.api.filters;
+
+import org.springframework.core.Ordered;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Enumeration;
+
+@Component
+@Order(Ordered.HIGHEST_PRECEDENCE)
+public class AuthFilter implements Filter{
+
+    public AuthFilter() {}
+
+
+    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+        HttpServletResponse response = (HttpServletResponse) servletResponse;
+        HttpServletRequest request = (HttpServletRequest) servletRequest;
+
+        HttpServletRequest httpRequest = (HttpServletRequest) request;
+        Enumeration<String> headerNames = httpRequest.getHeaderNames();
+
+        if (headerNames != null) {
+            while (headerNames.hasMoreElements()) {
+                String name = headerNames.nextElement();
+                if ("authorization".equals(name)) {
+                    String headerValue = httpRequest.getHeader(name);
+                    // TODO Validate the authorization header
+                }
+            }
+        }
+
+
+        filterChain.doFilter(request, response);
+    }
+}