Update shiro logging and sl4j init
[aaf/cadi.git] / shiro / src / main / java / org / onap / aaf / cadi / shiro / AAFAuthorizationInfo.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
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.onap.aaf.cadi.shiro;
22
23 import java.security.Principal;
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.List;
27
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;
34 /**
35  * We treat "roles" and "permissions" in a similar way for first pass.
36  * 
37  * @author JonathanGathman
38  *
39  */
40 public class AAFAuthorizationInfo implements AuthorizationInfo {
41         private static final long serialVersionUID = -4805388954462426018L;
42         
43         final static Logger logger =  LoggerFactory.getLogger(AAFAuthorizationInfo.class);
44         
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;
50
51         public AAFAuthorizationInfo(Access access, Principal bait, List<org.onap.aaf.cadi.Permission> pond) {
52                 this.access = access;
53                 this.bait = bait;
54                 this.pond = pond;
55                 sPerms=null;
56                 oPerms=null;
57
58         }
59         
60         public Principal principal() {
61                 return bait;
62         }
63         
64         @Override
65         public Collection<Permission> getObjectPermissions() {
66 //              access.log(Level.DEBUG, "AAFAuthorizationInfo.getObjectPermissions");
67                 synchronized(bait) {
68                         if(oPerms == null) {
69                                 oPerms = new ArrayList<Permission>(); 
70                                 for(final org.onap.aaf.cadi.Permission p : pond) {
71                                         oPerms.add(new AAFShiroPermission(p));
72                                 }
73                         }
74                 }
75                 return oPerms;
76         }
77
78         @Override
79         public Collection<String> getRoles() {
80                 // Until we decide to make Roles available, tie into String based permissions.
81                 return getStringPermissions();
82         }
83
84         @Override
85         public Collection<String> getStringPermissions() {
86                 synchronized(bait) {
87                         if(sPerms == null) {
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("|",":")); 
92                                 }
93                         }
94                 }
95                 return sPerms;
96         }
97
98 }