2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.dmaap.datarouter.node;
23 import com.att.eelf.configuration.EELFLogger;
24 import com.att.eelf.configuration.EELFManager;
25 import java.io.IOException;
26 import javax.servlet.FilterChain;
27 import javax.servlet.ServletException;
28 import javax.servlet.ServletRequest;
29 import javax.servlet.ServletResponse;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import org.onap.aaf.cadi.PropAccess;
33 import org.onap.aaf.cadi.filter.CadiFilter;
36 public class DRNodeCadiFilter extends CadiFilter {
38 private static EELFLogger logger = EELFManager.getInstance().getLogger(NodeServlet.class);
40 DRNodeCadiFilter(boolean init, PropAccess access) throws ServletException {
45 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
46 throws IOException, ServletException {
47 HttpServletRequest httpRequest = (HttpServletRequest) request;
48 String path = httpRequest.getPathInfo();
49 if (!(path.startsWith("/internal"))) {
50 if (!("POST".equalsIgnoreCase(httpRequest.getMethod()))) {
51 if ("DELETE".equalsIgnoreCase(httpRequest.getMethod()) && path.startsWith("/delete")) {
52 chain.doFilter(request, response);
54 doFilterWithFeedId(request, response, chain);
58 chain.doFilter(request, response);
62 private String getFeedId(ServletRequest request, ServletResponse response) {
63 HttpServletRequest req = (HttpServletRequest) request;
64 HttpServletResponse resp = (HttpServletResponse) response;
65 String fileid = req.getPathInfo();
67 logger.error("NODE0105 Rejecting bad URI for PUT " + req.getPathInfo() + " from " + req.getRemoteAddr());
69 resp.sendError(HttpServletResponse.SC_NOT_FOUND,
70 "Invalid request URI. Expecting <feed-publishing-url>/<fileid>.");
71 } catch (IOException e) {
72 logger.error("NODE0541 DRNodeCadiFilter.getFeedId: ", e);
78 if (fileid.startsWith("/publish/")) {
79 fileid = fileid.substring(9);
80 int index = fileid.indexOf('/');
81 if (index == -1 || index == fileid.length() - 1) {
82 logger.error("NODE0105 Rejecting bad URI for PUT (publish) of " + req.getPathInfo() + " from " + req
85 resp.sendError(HttpServletResponse.SC_NOT_FOUND,
86 "Invalid request URI. Expecting <feed-publishing-url>/<fileid>. "
87 + "Possible missing fileid.");
88 } catch (IOException e) {
89 logger.error("NODE0542 DRNodeCadiFilter.getFeedId: ", e);
93 feedid = fileid.substring(0, index);
98 private void doFilterWithFeedId(ServletRequest request, ServletResponse response, FilterChain chain)
99 throws IOException, ServletException {
100 String feedId = getFeedId(request, response);
101 String aafDbInstance = NodeConfigManager.getInstance().getAafInstance(feedId);
102 if (aafDbInstance != null && !"".equals(aafDbInstance) && !"legacy".equalsIgnoreCase(aafDbInstance)) {
103 logger.info("DRNodeCadiFilter - doFilter: FeedId - " + feedId + ":" + "AAF Instance -" + aafDbInstance);
104 super.doFilter(request, response, chain);
106 logger.info("DRNodeCadiFilter - doFilter: FeedId - " + feedId + ":" + "Legacy Feed");
107 chain.doFilter(request, response);