7e92aaca24906e1ae83d0939f09053cd08e57a1a
[aaf/authz.git] / cadi / core / src / main / java / org / onap / aaf / cadi / principal / TrustPrincipal.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.principal;
23
24 import java.security.Principal;
25
26 import org.onap.aaf.cadi.UserChain;
27
28 public class TrustPrincipal extends BearerPrincipal implements UserChain {
29     private final String name;
30     private final Principal original;
31     private String userChain;
32     
33     public TrustPrincipal(final Principal actual, final String asName) {
34         this.original = actual;
35         name = asName.trim();
36         if (actual instanceof UserChain) {
37             UserChain uc = (UserChain)actual;
38             userChain = uc.userChain();
39         } else if (actual instanceof TaggedPrincipal) {
40             userChain=((TaggedPrincipal)actual).tag();
41         } else {
42             userChain = actual.getClass().getSimpleName();
43         }
44     }
45     
46     @Override
47     public String getName() {
48         return name;
49     }
50     
51     @Override
52     public String userChain() {
53         return userChain;
54     }
55     
56     public Principal original() {
57         return original;
58     }
59
60     @Override
61     public String tag() {
62         return userChain;
63     }
64
65     @Override
66     public String personalName() {
67         return original.getName() + '[' + userChain + ']';
68     }
69     
70 }