Update AAF Version 1.0.0
[aaf/cadi.git] / core / src / main / java / org / onap / aaf / cadi / principal / TGuardPrincipal.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package org.onap.aaf.cadi.principal;\r
24 \r
25 public class TGuardPrincipal extends BearerPrincipal {\r
26 \r
27         private String name, tresp;\r
28 \r
29         public TGuardPrincipal(String tresp) {\r
30                 this.tresp=tresp;\r
31         }\r
32 \r
33         /**\r
34          * TODO Need to figure out what Organizations TGuard entities should be part of.  \r
35          * \r
36          */\r
37         public String getName() {\r
38                 if(name==null) {\r
39                         String temp = get("iv-user");\r
40                         if(temp==null)return null;\r
41                         StringBuilder sb = new StringBuilder();\r
42                         int at = temp.indexOf('@');\r
43                         if(at<0) {\r
44                                 sb.append(temp);\r
45                         } else {\r
46                                 sb.append(temp.substring(0, at));\r
47                         }\r
48                         if(temp.endsWith("@uverse.com"))sb.append("@uverse.tguard.att.com");\r
49                         else if(temp.endsWith("@att.com"))sb.append("@com.tguard.att.com");\r
50                         else if(temp.endsWith("@att.net"))sb.append("@net.tguard.att.com");\r
51                         else sb.append("@tguard.att.com");\r
52                         name = sb.toString();\r
53                 }\r
54                 return name;\r
55         }\r
56 \r
57         /**\r
58          * Get a value from a named TGuard Property\r
59          * \r
60          * TGuard response info is very dynamic.  They can add new properties at any time, so we dare not code field names for these values.\r
61          * @param key\r
62          * @return\r
63          */\r
64         public String get(String key) {\r
65                 if(key==null)return null;\r
66                 int idx=0,equal=0,amp=0;\r
67                 while(idx>=0 && (equal = tresp.indexOf('=',idx))>=0) {\r
68                         amp = tresp.indexOf('&',equal);\r
69                         if(key.regionMatches(0, tresp, idx, equal-idx)) {\r
70                                 return amp>=0?tresp.substring(equal+1, amp):tresp.substring(equal+1); \r
71                         }\r
72                         idx=amp+(amp>0?1:0);\r
73                 }\r
74                 return null;\r
75         }\r
76 \r
77         public String info() {\r
78                 return tresp;\r
79         }\r
80 }\r