Add Notice of aaf/cadi source moving to aaf/authz
[aaf/cadi.git] / core / src / main / java / org / onap / aaf / cadi / taf / EpiTaf.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 org.onap.aaf.cadi.taf;\r
24 \r
25 import org.onap.aaf.cadi.CadiException;\r
26 import org.onap.aaf.cadi.Taf;\r
27 \r
28 /**\r
29  * EpiTAF\r
30  * \r
31  * Short for "Epic TAF". Be able to run through a series of TAFs to obtain the validation needed.\r
32  * \r
33  * OK, the name could probably be better as "Tafs", like it was originally, but the pun was too\r
34  * irresistible for this author to pass up.\r
35  * \r
36  *\r
37  */\r
38 public class EpiTaf implements Taf {\r
39         private Taf[] tafs;\r
40         \r
41         /**\r
42          * EpiTaf constructor\r
43          * \r
44          * Construct the EpiTaf from variable TAF parameters\r
45          * @param tafs\r
46          * @throws CadiException\r
47          */\r
48         public EpiTaf(Taf ... tafs) throws CadiException{\r
49                 this.tafs = tafs;\r
50                 if(tafs.length==0) throw new CadiException("Need at least one Taf implementation in constructor");\r
51         }\r
52 \r
53         /**\r
54          * validate\r
55          * \r
56          * Respond with the first TAF to authenticate user based on variable info and "LifeForm" (is it \r
57          * a human behind an interface, or a server behind a protocol).\r
58          * \r
59          * If there is no TAF that can authenticate, respond with the first TAF that suggests it can\r
60          * establish an Authentication conversation (TRY_AUTHENTICATING).\r
61          * \r
62          * If no TAF declares either, respond with NullTafResp (which denies all questions)\r
63          */\r
64         public TafResp validate(LifeForm reading, String... info) {\r
65                 TafResp tresp,firstTryAuth=null;\r
66                 for(Taf taf : tafs) {\r
67                         tresp = taf.validate(reading, info);\r
68                         switch(tresp.isAuthenticated()) {\r
69                                 case TRY_ANOTHER_TAF:\r
70                                         break;\r
71                                 case TRY_AUTHENTICATING:\r
72                                         if(firstTryAuth==null)firstTryAuth=tresp;\r
73                                         break;\r
74                                 default:\r
75                                         return tresp;\r
76                         }\r
77                 }\r
78 \r
79                 // No TAFs configured, at this point.  It is safer at this point to be "not validated", \r
80                 // rather than "let it go"\r
81                 return firstTryAuth == null?NullTafResp.singleton():firstTryAuth;\r
82         }\r
83 \r
84 }\r