2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (c) 2017 AT&T Intellectual Property
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.
19 * ============LICENSE_END=============================================
20 * ====================================================================
23 package org.onap.music;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.regex.Matcher;
27 import java.util.regex.Pattern;
29 import javax.servlet.FilterConfig;
30 import javax.servlet.ServletException;
31 import javax.servlet.ServletRequest;
32 import javax.servlet.http.HttpServletRequest;
34 import com.att.eelf.configuration.EELFLogger;
35 import org.onap.aaf.cadi.CadiWrap;
36 import org.onap.aaf.cadi.Permission;
37 import org.onap.aaf.cadi.PropAccess;
38 import org.onap.aaf.cadi.aaf.AAFPermission;
39 import org.onap.aaf.cadi.filter.CadiFilter;
40 import org.onap.music.eelf.logging.EELFLoggerDelegate;
41 import org.onap.music.main.MusicCore;
43 public class CadiAuthFilter extends CadiFilter {
45 private static final EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(CadiAuthFilter.class);
47 public CadiAuthFilter(PropAccess access) throws ServletException {
51 public void init(FilterConfig filterConfig) throws ServletException {
52 super.init(filterConfig);
56 private boolean matchPattern(String requestedPath, String includeUrl) {
57 includeUrl = includeUrl.substring(1);
58 String[] path = requestedPath.split("/");
59 if (path.length > 1) {
60 String[] roleFunctionArray = includeUrl.split("/");
62 for (int i = 0; i < roleFunctionArray.length; i++) {
64 if (!"*".equals(roleFunctionArray[i])) {
65 Pattern p = Pattern.compile(Pattern.quote(path[i]), Pattern.CASE_INSENSITIVE);
66 Matcher m = p.matcher(roleFunctionArray[i]);
68 } else if (roleFunctionArray[i].equals("*")) {
77 if (requestedPath.matches(includeUrl))
79 else if ("*".equals(includeUrl))
86 public static List<AAFPermission> getAAFPermissions(HttpServletRequest request) {
87 CadiWrap wrapReq = (CadiWrap) request;
88 List<Permission> perms = wrapReq.getPermissions(wrapReq.getUserPrincipal());
89 List<AAFPermission> aafPermsList = new ArrayList<>();
90 for (Permission perm : perms) {
91 AAFPermission aafPerm = (AAFPermission) perm;
92 aafPermsList.add(aafPerm);
93 logger.info(aafPerm.toString());
94 logger.info(aafPerm.getType());
99 public static List<AAFPermission> getAAFPermissions(ServletRequest request) {
100 CadiWrap wrapReq = (CadiWrap) request;
101 List<Permission> perms = wrapReq.getPermissions(wrapReq.getUserPrincipal());
102 List<AAFPermission> aafPermsList = new ArrayList<>();
103 for (Permission perm : perms) {
104 AAFPermission aafPerm = (AAFPermission) perm;
105 aafPermsList.add(aafPerm);