2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.cadi.taf;
24 import org.onap.aaf.cadi.Access;
25 import org.onap.aaf.cadi.principal.TaggedPrincipal;
26 import org.onap.aaf.cadi.util.Timing;
31 * Base class for TafResp (TAF Response Objects)
36 public abstract class AbsTafResp implements TafResp {
38 protected final Access access;
39 protected final String tafName;
40 // Note: Valid Resp is based on Principal being non-null
41 protected final TaggedPrincipal principal;
42 protected final String target;
43 protected final String desc;
50 * Description (for logging)
51 * Principal (as created by derived class)
52 * Access (for access to underlying container, i.e. for Logging, auditing, ClassLoaders, etc)
59 public AbsTafResp(Access access, String tafname, TaggedPrincipal principal, String description) {
61 this.tafName = tafname;
62 this.principal = principal;
63 this.target = principal==null?"unknown":principal.getName();
64 this.desc = description;
71 * Description (for logging)
72 * Principal (as created by derived class)
73 * Access (for access to underlying container, i.e. for Logging, auditing, ClassLoaders, etc)
80 public AbsTafResp(Access access, String tafname, String target, String description) {
82 this.tafName = tafname;
83 this.principal = null;
85 this.desc = description;
91 * Respond in the affirmative if the TAF was able to Authenticate
93 public boolean isValid() {
94 return principal != null;
100 * Respond with description of response as given by the TAF
102 public String desc() {
109 * Respond with the TAF's code of whether Authenticated, or suggested next steps
110 * default is either IS_AUTHENTICATED, or TRY_ANOTHER_TAF. The TAF can overload
111 * and suggest others, such as "NO_FURTHER_PROCESSING", if it can detect that this
112 * is some sort of security breach (i.e. Denial of Service)
114 public RESP isAuthenticated() {
115 return principal==null?RESP.TRY_ANOTHER_TAF:RESP.IS_AUTHENTICATED;
121 * Return the principal created by the TAF based on Authentication.
123 * Returns "null" if Authentication failed (no principal)
125 public TaggedPrincipal getPrincipal() {
130 * @see org.onap.aaf.cadi.taf.TafResp#getTarget()
133 public String getTarget() {
140 * Get the Access object from the TAF, so that appropriate Logging, etc can be coordinated.
142 public Access getAccess() {
147 * @see org.onap.aaf.cadi.taf.TafResp#isFailedAttempt()
149 public boolean isFailedAttempt() {
154 public float timing() {
159 public void timing(final long start) {
160 timing = Timing.millis(start);
164 public String taf() {