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