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====================================================
22 package org.onap.aaf.cadi.oauth;
24 import java.security.Principal;
25 import java.util.List;
27 import org.onap.aaf.cadi.Lur;
28 import org.onap.aaf.cadi.Permission;
29 import org.onap.aaf.cadi.aaf.AAFPermission;
30 import org.onap.aaf.cadi.lur.LocalPermission;
31 import org.onap.aaf.cadi.principal.BearerPrincipal;
32 import org.onap.aaf.misc.env.util.Split;
34 public class OAuth2Lur implements Lur {
37 public OAuth2Lur(TokenMgr tm) {
42 public Permission createPerm(String p) {
43 String[] params = Split.split('|', p);
44 switch(params.length) {
46 return new AAFPermission(null,params[0],params[1],params[2]);
48 return new AAFPermission(params[0],params[1],params[2],params[3]);
50 return new LocalPermission(p);
55 public boolean fish(Principal bait, Permission ... pond) {
58 if (bait instanceof OAuth2Principal) {
59 OAuth2Principal oap = (OAuth2Principal)bait;
60 for (Permission p : pond ) {
61 AAFPermission apond = (AAFPermission)p;
63 TokenPerm tp = oap.tokenPerm();
66 for (Permission perm : tp.perms()) {
67 if (perm.match(apond)) {
78 public void fishAll(Principal bait, List<Permission> permissions) {
79 OAuth2Principal oap = (OAuth2Principal)bait;
80 TokenPerm tp = oap.tokenPerm();
82 for (AAFPermission p : tp.perms()) {
89 public void destroy() {
93 public boolean handlesExclusively(Permission ... pond) {
98 public boolean handles(Principal p) {
99 if (p!=null && p instanceof BearerPrincipal) {
100 return ((BearerPrincipal)p).getBearer()!=null;
106 public void clear(Principal p, StringBuilder report) {