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=========================================================
20 package org.onap.dmaap.datarouter.node;
22 import com.att.eelf.configuration.EELFLogger;
23 import com.att.eelf.configuration.EELFManager;
24 import org.onap.aaf.cadi.PropAccess;
25 import org.onap.aaf.cadi.filter.CadiFilter;
27 import javax.servlet.FilterChain;
28 import javax.servlet.ServletException;
29 import javax.servlet.ServletRequest;
30 import javax.servlet.ServletResponse;
31 import javax.servlet.http.HttpServletRequest;
32 import javax.servlet.http.HttpServletResponse;
33 import java.io.IOException;
36 public class DRNodeCadiFilter extends CadiFilter {
37 private static EELFLogger logger = EELFManager.getInstance().getLogger(NodeServlet.class);
39 DRNodeCadiFilter(boolean init, PropAccess access) throws ServletException {
44 public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
45 HttpServletRequest httpRequest = (HttpServletRequest) request;
46 String path = httpRequest.getPathInfo();
47 if (!(path.startsWith("/internal"))) {
48 if (!(httpRequest.getMethod().equalsIgnoreCase("POST"))) {
49 if (httpRequest.getMethod().equalsIgnoreCase("DELETE") && path.startsWith("/delete")) {
50 chain.doFilter(request, response);
52 String feedId = getFeedId(request, response);
53 String aafDbInstance = NodeConfigManager.getInstance().getAafInstance(feedId);
54 if (aafDbInstance != null && !aafDbInstance.equals("") && !aafDbInstance.equalsIgnoreCase("legacy")) {
55 logger.info("DRNodeCadiFilter - doFilter: FeedId - " + feedId + ":" + "AAF Instance -" + aafDbInstance);
56 super.doFilter(request, response, chain);
58 logger.info("DRNodeCadiFilter - doFilter: FeedId - " + feedId + ":" + "Legacy Feed");
59 chain.doFilter(request, response);
64 chain.doFilter(request, response);
68 private String getFeedId(ServletRequest request, ServletResponse response) {
69 HttpServletRequest req = (HttpServletRequest) request;
70 HttpServletResponse resp = (HttpServletResponse) response;
71 String fileid = req.getPathInfo();
73 logger.error("NODE0105 Rejecting bad URI for PUT " + req.getPathInfo() + " from " + req.getRemoteAddr());
75 resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Invalid request URI. Expecting <feed-publishing-url>/<fileid>.");
76 } catch (IOException e) {
77 logger.error("NODE0541 DRNodeCadiFilter.getFeedId: ", e);
83 if (fileid.startsWith("/publish/")) {
84 fileid = fileid.substring(9);
85 int i = fileid.indexOf('/');
86 if (i == -1 || i == fileid.length() - 1) {
87 logger.error("NODE0105 Rejecting bad URI for PUT (publish) of " + req.getPathInfo() + " from " + req.getRemoteAddr());
89 resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Invalid request URI. Expecting <feed-publishing-url>/<fileid>. Possible missing fileid.");
90 } catch (IOException e) {
91 logger.error("NODE0542 DRNodeCadiFilter.getFeedId: ", e);
95 feedid = fileid.substring(0, i);