3815bc678dd4bbbf04325e9212ad2ad84c15ec7a
[aaf/authz.git] / cadi / client / src / main / java / org / onap / aaf / cadi / client / AbsTransferSS.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.client;
23
24 import java.security.Principal;
25
26 import org.onap.aaf.cadi.SecuritySetter;
27 import org.onap.aaf.cadi.config.SecurityInfoC;
28 import org.onap.aaf.cadi.principal.TaggedPrincipal;
29
30 /**
31  * This client represents the ability to Transfer the Identity of the caller to the authenticated
32  * user being transferred to.  This ability is critical for App-to-App communication to ensure that 
33  * Authorization can happen on the End-Users' credentials when appropriate, even though Authentication
34  * to App1 by App2 must be by App2's credentials.
35  *  
36  * @author Jonathan
37  *
38  * @param <CLIENT>
39  */
40 public abstract class AbsTransferSS<CLIENT> implements SecuritySetter<CLIENT> {
41         protected String value;
42         protected SecurityInfoC<CLIENT> securityInfo;
43         protected SecuritySetter<CLIENT> defSS;
44         private Principal principal;
45
46         //Format:<ID>:<APP>:<protocol>[:AS][,<ID>:<APP>:<protocol>]*
47         public AbsTransferSS(TaggedPrincipal principal, String app) {
48                 init(principal, app);
49         }
50
51         public AbsTransferSS(TaggedPrincipal principal, String app, SecurityInfoC<CLIENT> si) {
52                 init(principal,app);
53                 securityInfo = si;
54                 this.defSS = si.defSS;
55         }
56
57         private void init(TaggedPrincipal principal, String app)  {
58                 this.principal=principal;
59                 if(principal==null) {
60                         return;
61                 } else  {
62                         value = principal.getName() + ':' + 
63                                         app + ':' + 
64                                         principal.tag() + ':' +
65                                         "AS";
66                 }
67         }
68
69         /* (non-Javadoc)
70          * @see org.onap.aaf.cadi.SecuritySetter#getID()
71          */
72         @Override
73         public String getID() {
74                 return principal==null?"":principal.getName();
75         }
76 }