Improve tests in cadi-core
[aaf/authz.git] / cadi / core / src / main / java / org / onap / aaf / cadi / taf / AbsTafResp.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21
22 package org.onap.aaf.cadi.taf;
23
24 import org.onap.aaf.cadi.Access;
25 import org.onap.aaf.cadi.principal.TaggedPrincipal;
26
27 /**
28  * AbsTafResp
29  * 
30  * Base class for TafResp (TAF Response Objects)
31  * 
32  * @author Jonathan
33  *
34  */
35 public abstract class AbsTafResp implements TafResp {
36
37         protected final String desc;
38         protected final TaggedPrincipal principal;
39         protected final Access access;
40
41         /**
42          * AbsTafResp
43          * 
44          * Set and hold
45          * Description (for logging)
46          * Principal (as created by derived class)
47          * Access (for access to underlying container, i.e. for Logging, auditing, ClassLoaders, etc)
48          *  
49          * @param access
50          * @param principal
51          * @param description
52          */
53         public AbsTafResp(Access access, TaggedPrincipal principal, String description) {
54                 this.access = access;
55                 this.principal = principal;
56                 this.desc = description;
57         }
58
59         /**
60          * isValid()
61          * 
62          * Respond in the affirmative if the TAF was able to Authenticate
63          */
64         public boolean isValid() {
65                 return principal != null;
66         }
67
68         /**
69          * desc()
70          * 
71          * Respond with description of response as given by the TAF  
72          */
73         public String desc() {
74                 return desc;
75         }
76
77         /**
78          * isAuthenticated()
79          * 
80          * Respond with the TAF's code of whether Authenticated, or suggested next steps
81          * default is either IS_AUTHENTICATED, or TRY_ANOTHER_TAF.  The TAF can overload
82          * and suggest others, such as "NO_FURTHER_PROCESSING", if it can detect that this
83          * is some sort of security breach (i.e. Denial of Service)  
84          */
85         public RESP isAuthenticated() {
86                 return principal==null?RESP.TRY_ANOTHER_TAF:RESP.IS_AUTHENTICATED;
87         }
88
89         /**
90          * getPrincipal()
91          * 
92          * Return the principal created by the TAF based on Authentication. 
93          * 
94          * Returns "null" if Authentication failed (no principal)
95          */
96         public TaggedPrincipal getPrincipal() {
97                 return principal;
98         }
99
100         /**
101          * getAccess()
102          * 
103          * Get the Access object from the TAF, so that appropriate Logging, etc can be coordinated.
104          */
105         public Access getAccess() {
106                 return access;
107         }
108
109         /* (non-Javadoc)
110          * @see org.onap.aaf.cadi.taf.TafResp#isFailedAttempt()
111          */
112         public boolean isFailedAttempt() {
113                 return false;
114         }
115
116 }