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