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 if(params.length==3) {
45 return new AAFPermission(params[0],params[1],params[2]);
47 return new LocalPermission(p);
52 public boolean fish(Principal bait, Permission pond) {
53 AAFPermission apond = (AAFPermission)pond;
55 if(bait instanceof OAuth2Principal) {
56 oap = (OAuth2Principal)bait;
58 // Here is the spot to put in Principal Conversions
62 TokenPerm tp = oap.tokenPerm();
65 for(Permission p : tp.perms()) {
75 public void fishAll(Principal bait, List<Permission> permissions) {
76 OAuth2Principal oap = (OAuth2Principal)bait;
77 TokenPerm tp = oap.tokenPerm();
79 for(AAFPermission p : tp.perms()) {
86 public void destroy() {
90 public boolean handlesExclusively(Permission pond) {
95 public boolean handles(Principal p) {
96 if(p!=null && p instanceof BearerPrincipal) {
97 return ((BearerPrincipal)p).getBearer()!=null;
103 public void clear(Principal p, StringBuilder report) {