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