9d3b28ca73d3414a43f571f404a142c3ab6eea6d
[aaf/authz.git] / cadi / core / src / main / java / org / onap / aaf / cadi / taf / TrustTafResp.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 java.io.IOException;
25
26 import org.onap.aaf.cadi.Access;
27 import org.onap.aaf.cadi.principal.TaggedPrincipal;
28 import org.onap.aaf.cadi.util.Timing;
29
30 public class TrustTafResp implements TafResp {
31         private final TafResp delegate;
32         private final TaggedPrincipal principal;
33         private final String desc;
34         private float timing;
35         
36         public TrustTafResp(final TafResp delegate, final TaggedPrincipal principal, final String desc) {
37                 this.delegate = delegate;
38                 this.principal = principal;
39                 this.desc = desc + ' ' + delegate.desc();
40         }
41         
42         @Override
43         public boolean isValid() {
44                 return delegate.isValid();
45         }
46
47         @Override
48         public String desc() {
49                 return desc;
50         }
51
52         @Override
53         public RESP isAuthenticated() {
54                 return delegate.isAuthenticated();
55         }
56
57         @Override
58         public RESP authenticate() throws IOException {
59                 return delegate.authenticate();
60         }
61
62         @Override
63         public TaggedPrincipal getPrincipal() {
64                 return principal;
65         }
66
67         @Override
68         public Access getAccess() {
69                 return delegate.getAccess();
70         }
71
72         @Override
73         public boolean isFailedAttempt() {
74                 return delegate.isFailedAttempt();
75         }
76         @Override
77         public float timing() {
78                 return timing;
79         }
80
81         @Override
82         public void timing(long start) {
83                 timing = Timing.millis(start);
84         }
85         
86         public String toString() {
87                 return principal.getName() + " by trust of " + desc();
88         }
89         
90         @Override
91         public String taf() {
92                 return "Trust";
93         }
94
95 }