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.taf;
\r
25 import com.att.cadi.CadiException;
\r
26 import com.att.cadi.Taf;
\r
31 * Short for "Epic TAF". Be able to run through a series of TAFs to obtain the validation needed.
\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
38 public class EpiTaf implements Taf {
\r
42 * EpiTaf constructor
\r
44 * Construct the EpiTaf from variable TAF parameters
\r
46 * @throws CadiException
\r
48 public EpiTaf(Taf ... tafs) throws CadiException{
\r
50 if(tafs.length==0) throw new CadiException("Need at least one Taf implementation in constructor");
\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
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
62 * If no TAF declares either, respond with NullTafResp (which denies all questions)
\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
71 case TRY_AUTHENTICATING:
\r
72 if(firstTryAuth==null)firstTryAuth=tresp;
\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