Fix security risk 'Improper Input Validation'
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / filters / 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.be.filters;
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 org.apache.commons.lang3.StringUtils;
32 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
33 import org.openecomp.sdc.be.config.ConfigurationManager;
34 import org.openecomp.sdc.be.dao.api.ActionStatus;
35 import org.openecomp.sdc.common.filters.DataValidatorFilterAbstract;
36 import org.openecomp.sdc.common.util.DataValidator;
37 import org.openecomp.sdc.exception.NotAllowedSpecialCharsException;
38
39 /**
40  * Implement DataValidatorFilter for back-end.
41  * Extends {@link DataValidatorFilterAbstract}
42  */
43 public class DataValidatorFilter extends DataValidatorFilterAbstract {
44
45     @Override
46     public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException {
47         try {
48             super.doFilter(request, response, chain);
49         } catch (NotAllowedSpecialCharsException e) {
50             throw new ByActionStatusComponentException(ActionStatus.NOT_PERMITTED_SPECIAL_CHARS);
51         }
52     }
53
54     @Override
55     protected List<String> getDataValidatorFilterExcludedUrls() {
56         final String dataValidatorFilterExcludedUrls = ConfigurationManager.getConfigurationManager().getConfiguration()
57             .getDataValidatorFilterExcludedUrls();
58         if (StringUtils.isNotBlank(dataValidatorFilterExcludedUrls)) {
59             return Arrays.asList(dataValidatorFilterExcludedUrls.split(","));
60         }
61         return new ArrayList<>();
62     }
63
64 }