[AAF-21] Initial code import
[aaf/cadi.git] / cass / src / main / java / com / att / cadi / aaf / cass / AAFAuthenticatedUser.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.aaf.cass;\r
25 \r
26 import java.security.Principal;\r
27 \r
28 import org.apache.cassandra.auth.AuthenticatedUser;\r
29 \r
30 import com.att.cadi.Access;\r
31 \r
32 public class AAFAuthenticatedUser extends AuthenticatedUser implements Principal {\r
33         private boolean anonymous = false, supr=false, local=false;\r
34         private String fullName;\r
35 //      private Access access;\r
36 \r
37         public AAFAuthenticatedUser(Access access, String name) {\r
38                 super(name);\r
39 //              this.access = access;\r
40             int endIndex = name.indexOf("@");\r
41             if(endIndex >= 0) {\r
42                 fullName = name;\r
43             } else {\r
44                 fullName = name + '@' + AAFBase.default_realm;\r
45             }\r
46         }\r
47         \r
48         public String getFullName() {\r
49                 return fullName;\r
50         }\r
51         \r
52         public String getName() {\r
53                 return fullName;\r
54         }\r
55         \r
56         /* (non-Javadoc)\r
57          * @see org.apache.cassandra.auth.AuthenticatedUser#isAnonymous()\r
58          */\r
59         @Override\r
60         public boolean isAnonymous() {\r
61                 return anonymous;\r
62         }\r
63 \r
64         public void setAnonymous(boolean anon) {\r
65                 anonymous = anon;\r
66         }\r
67 \r
68         public boolean getAnonymous() {\r
69                 return anonymous;\r
70         }\r
71 \r
72         /* (non-Javadoc)\r
73          * @see org.apache.cassandra.auth.AuthenticatedUser#isSuper()\r
74          */\r
75         @Override\r
76         public boolean isSuper() {\r
77                 return supr;\r
78         }\r
79 \r
80         public void setSuper(boolean supr) {\r
81                 this.supr = supr;\r
82         }\r
83 \r
84         public boolean getSuper() {\r
85                 return supr;\r
86         }\r
87 \r
88         /**\r
89          * We check Local so we can compare with the right Lur.  This is AAF Plugin only.\r
90          * @return\r
91          */\r
92         public boolean isLocal() {\r
93                 return local;\r
94         }\r
95         \r
96         public void setLocal(boolean val) {\r
97                 local = val;\r
98         }\r
99 \r
100         @Override\r
101           public boolean equals(Object o) {\r
102                   if (this == o) return true;\r
103               if (!(o instanceof AAFAuthenticatedUser)) return false;\r
104               return ((AuthenticatedUser)o).getName().equals(this.getName());\r
105           }\r
106 \r
107           @Override\r
108           public int hashCode() {\r
109                   //access.log(Level.DEBUG, "AAFAuthentication hashcode ",getName().hashCode());\r
110               return getName().hashCode();\r
111           }  \r
112 }\r