6a7f15e37dc92974147cb72e9b685173ea66ec34
[aaf/cadi.git] / core / src / main / java / org / onap / aaf / cadi / taf / AbsTafResp.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 java.security.Principal;\r
26 \r
27 import org.onap.aaf.cadi.Access;\r
28 \r
29 /**\r
30  * AbsTafResp\r
31  * \r
32  * Base class for TafResp (TAF Response Objects)\r
33  *\r
34  */\r
35 public abstract class AbsTafResp implements TafResp {\r
36 \r
37         protected final String desc;\r
38         protected final Principal principal;\r
39         protected final Access access;\r
40 \r
41         /**\r
42          * AbsTafResp\r
43          * \r
44          * Set and hold\r
45          * Description (for logging)\r
46          * Principal (as created by derived class)\r
47          * Access (for access to underlying container, i.e. for Logging, auditing, ClassLoaders, etc)\r
48          *  \r
49          * @param access\r
50          * @param principal\r
51          * @param description\r
52          */\r
53         public AbsTafResp(Access access, Principal principal, String description) {\r
54                 this.access = access;\r
55                 this.principal = principal;\r
56                 this.desc = description;\r
57         }\r
58 \r
59         /**\r
60          * isValid()\r
61          * \r
62          * Respond in the affirmative if the TAF was able to Authenticate\r
63          */\r
64         public boolean isValid() {\r
65                 return principal!=null;\r
66         }\r
67 \r
68         /**\r
69          * desc()\r
70          * \r
71          * Respond with description of response as given by the TAF  \r
72          */\r
73         public String desc() {\r
74                 return desc;\r
75         }\r
76 \r
77         /**\r
78          * isAuthenticated()\r
79          * \r
80          * Respond with the TAF's code of whether Authenticated, or suggested next steps\r
81          * default is either IS_AUTHENTICATED, or TRY_ANOTHER_TAF.  The TAF can overload\r
82          * and suggest others, such as "NO_FURTHER_PROCESSING", if it can detect that this\r
83          * is some sort of security breach (i.e. Denial of Service)  \r
84          */\r
85         public RESP isAuthenticated() {\r
86                 return principal==null?RESP.TRY_ANOTHER_TAF:RESP.IS_AUTHENTICATED;\r
87         }\r
88 \r
89         /**\r
90          * getPrincipal()\r
91          * \r
92          * Return the principal created by the TAF based on Authentication. \r
93          * \r
94          * Returns "null" if Authentication failed (no principal)\r
95          */\r
96         public Principal getPrincipal() {\r
97                 return principal;\r
98         }\r
99 \r
100         /**\r
101          * getAccess()\r
102          * \r
103          * Get the Access object from the TAF, so that appropriate Logging, etc can be coordinated.\r
104          */\r
105         public Access getAccess() {\r
106                 return access;\r
107         }\r
108 \r
109         /* (non-Javadoc)\r
110          * @see com.att.cadi.taf.TafResp#isFailedAttempt()\r
111          */\r
112         public boolean isFailedAttempt() {\r
113                 return false;\r
114         }\r
115 \r
116 }\r