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