2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2022 Nordix Foundation. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.fe.filters;
23 import java.io.IOException;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
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.HttpServletResponse;
32 import org.apache.commons.lang3.StringUtils;
33 import org.openecomp.sdc.common.filters.DataValidatorFilterAbstract;
34 import org.openecomp.sdc.exception.NotAllowedSpecialCharsException;
35 import org.openecomp.sdc.fe.config.Configuration;
36 import org.openecomp.sdc.fe.config.ConfigurationManager;
39 * Implement DataValidatorFilter for front-end.
40 * Extends {@link DataValidatorFilterAbstract}
42 public class DataValidatorFilter extends DataValidatorFilterAbstract {
45 public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain)
46 throws IOException, ServletException, NotAllowedSpecialCharsException {
48 super.doFilter(request, response, chain);
49 } catch (final NotAllowedSpecialCharsException e) {
50 // error handing to show 'Error: Special characters not allowed.'
51 ((HttpServletResponse) response).sendError(400, DataValidatorFilter.ERROR_SPECIAL_CHARACTERS_NOT_ALLOWED);
57 protected List<String> getDataValidatorFilterExcludedUrls() {
58 final ConfigurationManager configurationManager = ConfigurationManager.getConfigurationManager();
59 if (configurationManager != null) {
60 final Configuration configuration = configurationManager.getConfiguration();
61 if (configuration != null) {
62 final String dataValidatorFilterExcludedUrls = configuration.getDataValidatorFilterExcludedUrls();
63 if (StringUtils.isNotBlank(dataValidatorFilterExcludedUrls)) {
64 return Arrays.asList(dataValidatorFilterExcludedUrls.split(","));
68 return new ArrayList<>();