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