[AAF-21] Updated Copyright Headers for AAF
[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.aaf\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
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \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
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package com.att.cadi.aaf.v2_0;\r
24 \r
25 import javax.servlet.http.HttpServletRequest ;\r
26 \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
35 \r
36 public class AAFTrustChecker implements TrustChecker {\r
37         private final String tag,type,instance,action;\r
38         private Lur lur;\r
39 \r
40         /**\r
41          * \r
42          * Instance will be replaced by Identity\r
43          * @param lur \r
44          *    \r
45          * @param tag\r
46          * @param perm\r
47          */\r
48         public AAFTrustChecker(final String tag, final String perm) {\r
49                 this.tag = tag;\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
54         }\r
55         \r
56         /* (non-Javadoc)\r
57          * @see com.att.cadi.TrustChecker#setLur(com.att.cadi.Lur)\r
58          */\r
59         @Override\r
60         public void setLur(Lur lur) {\r
61                 this.lur = lur;\r
62         }\r
63 \r
64         @Override\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
69                         if(info.length>0) {\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
77                                                                 );\r
78                                                 } else {\r
79                                                         return new TrustNotTafResp(tresp, "  " + tresp.getPrincipal().getName() + \r
80                                                                         " requested identity change to " + flds[0] + ", but does not have Authorization");\r
81                                                 }\r
82                                         }\r
83                                 }\r
84                         }\r
85                 }\r
86 \r
87                 return tresp;\r
88         }\r
89 \r
90 }\r