2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. 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.onap.aaf.cadi.shiro;
23 import java.security.Principal;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
28 import org.apache.shiro.authz.AuthorizationInfo;
29 import org.apache.shiro.authz.Permission;
30 import org.onap.aaf.cadi.Access;
31 import org.onap.aaf.cadi.Access.Level;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 * We treat "roles" and "permissions" in a similar way for first pass.
37 * @author JonathanGathman
40 public class AAFAuthorizationInfo implements AuthorizationInfo {
41 private static final long serialVersionUID = -4805388954462426018L;
43 final static Logger logger = LoggerFactory.getLogger(AAFAuthorizationInfo.class);
45 private Access access;
46 private Principal bait;
47 private List<org.onap.aaf.cadi.Permission> pond;
48 private ArrayList<String> sPerms;
49 private ArrayList<Permission> oPerms;
51 public AAFAuthorizationInfo(Access access, Principal bait, List<org.onap.aaf.cadi.Permission> pond) {
60 public Principal principal() {
65 public Collection<Permission> getObjectPermissions() {
66 // access.log(Level.DEBUG, "AAFAuthorizationInfo.getObjectPermissions");
69 oPerms = new ArrayList<Permission>();
70 for(final org.onap.aaf.cadi.Permission p : pond) {
71 oPerms.add(new AAFShiroPermission(p));
79 public Collection<String> getRoles() {
80 // Until we decide to make Roles available, tie into String based permissions.
81 return getStringPermissions();
85 public Collection<String> getStringPermissions() {
88 sPerms = new ArrayList<String>();
89 for(org.onap.aaf.cadi.Permission p : pond) {
90 sPerms.add(p.getKey().replace("|",":"));
91 // System.out.println("Replacing | to :" + p.getKey().replace("|",":"));