Fix security risk 'Improper Input Validation'
[sdc.git] / utils / webseal-simulator / src / main / java / org / openecomp / sdc / webseal / simulator / DataValidatorFilter.java
1 /*
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.webseal.simulator;
22
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.webseal.simulator.conf.Conf;
36
37 /**
38  * Implement DataValidatorFilter for webseal.
39  * Extends {@link DataValidatorFilterAbstract}
40  */
41 public class DataValidatorFilter extends DataValidatorFilterAbstract {
42
43     @Override
44     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
45         throws IOException, ServletException, NotAllowedSpecialCharsException {
46         try {
47             super.doFilter(request, response, chain);
48         } catch (final NotAllowedSpecialCharsException e) {
49             // error handing to show 'Error: Special characters not allowed.'
50             ((HttpServletResponse) response).sendError(400, ERROR_SPECIAL_CHARACTERS_NOT_ALLOWED);
51         }
52     }
53
54     @Override
55     protected List<String> getDataValidatorFilterExcludedUrls() {
56         String dataValidatorFilterExcludedUrls = Conf.getInstance().getDataValidatorFilterExcludedUrls();
57         if (StringUtils.isNotBlank(dataValidatorFilterExcludedUrls)) {
58             return Arrays.asList(dataValidatorFilterExcludedUrls.split(","));
59         }
60         return new ArrayList<>();
61     }
62 }