1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * ===========================================================================
\r
7 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * * you may not use this file except in compliance with the License.
\r
9 * * You may obtain a copy of the License at
\r
11 * * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * * Unless required by applicable law or agreed to in writing, software
\r
14 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * * See the License for the specific language governing permissions and
\r
17 * * limitations under the License.
\r
18 * * ============LICENSE_END====================================================
\r
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
23 package com.att.cadi.aaf.v2_0;
\r
25 import javax.servlet.http.HttpServletRequest ;
\r
27 import com.att.cadi.Lur;
\r
28 import com.att.cadi.TrustChecker;
\r
29 import com.att.cadi.aaf.AAFPermission;
\r
30 import com.att.cadi.principal.TrustPrincipal;
\r
31 import com.att.cadi.taf.TafResp;
\r
32 import com.att.cadi.taf.TrustNotTafResp;
\r
33 import com.att.cadi.taf.TrustTafResp;
\r
34 import com.att.inno.env.util.Split;
\r
36 public class AAFTrustChecker implements TrustChecker {
\r
37 private final String tag,type,instance,action;
\r
42 * Instance will be replaced by Identity
\r
48 public AAFTrustChecker(final String tag, final String perm) {
\r
50 String[] split = Split.split('|', perm);
\r
51 this.type = split[0];
\r
52 this.instance = split[1];
\r
53 this.action = split[2];
\r
57 * @see com.att.cadi.TrustChecker#setLur(com.att.cadi.Lur)
\r
60 public void setLur(Lur lur) {
\r
65 public TafResp mayTrust(TafResp tresp, HttpServletRequest req) {
\r
66 String user_info = req.getHeader(tag);
\r
67 if(user_info !=null ) {
\r
68 String[] info = Split.split(',', user_info);
\r
70 String[] flds = Split.split(':',info[0]);
\r
71 if(flds.length>3 && "AS".equals(flds[3])) { // is it set for "AS"
\r
72 if(!tresp.getPrincipal().getName().equals(flds[0])) { // We do trust ourselves, if a trust entry is made with self
\r
73 if(lur.fish(tresp.getPrincipal(), new AAFPermission(type,instance,action))) {
\r
74 return new TrustTafResp(tresp,
\r
75 new TrustPrincipal(tresp.getPrincipal(), flds[0]),
\r
76 " " + flds[0] + " validated using " + flds[2] + " by " + flds[1] + ','
\r
79 return new TrustNotTafResp(tresp, " " + tresp.getPrincipal().getName() +
\r
80 " requested identity change to " + flds[0] + ", but does not have Authorization");
\r