c064f3e08f949962018a9d2a06950cc6b6c772dc
[sdc.git] /
1 package org.openecomp.sdc.securityutil;
2
3 import java.util.Set;
4
5
6 public class AuthenticationCookie  {
7
8     private String userID;
9     private Set<String> roles;
10     private long maxSessionTime;
11     private long currentSessionTime;
12
13     public AuthenticationCookie(){ }
14
15     public AuthenticationCookie(AuthenticationCookie authenticationCookie){
16         this.userID = authenticationCookie.userID;
17         this.roles = authenticationCookie.roles;
18         this.maxSessionTime = authenticationCookie.maxSessionTime;
19         this.currentSessionTime = authenticationCookie.currentSessionTime;
20     }
21
22     /**
23      * Create new cookie with max_session_time and current_session_time started with same value
24      * @param userId
25      */
26     public AuthenticationCookie(String userId) {
27         this.userID =userId;
28         long currentTimeMilliSec = System.currentTimeMillis();
29         this.maxSessionTime = currentTimeMilliSec;
30         this.currentSessionTime = currentTimeMilliSec;
31     }
32
33     public String getUserID() {
34         return userID;
35     }
36
37     public void setUserID(String userID) {
38         this.userID = userID;
39     }
40
41     public Set getRoles() {
42         return roles;
43     }
44
45     public void setRoles(Set<String> roles) {
46         this.roles = roles;
47     }
48
49     public long getMaxSessionTime() {
50         return maxSessionTime;
51     }
52
53     public void setMaxSessionTime(long maxSessionTime) {
54         this.maxSessionTime = maxSessionTime;
55     }
56
57
58     public long getCurrentSessionTime() {
59         return currentSessionTime;
60     }
61
62     public void setCurrentSessionTime(long currentSessionTime) {
63         this.currentSessionTime = currentSessionTime;
64     }
65
66     @Override
67     public boolean equals(Object o) {
68         if (this == o) return true;
69         if (!(o instanceof AuthenticationCookie)) return false;
70
71         AuthenticationCookie that = (AuthenticationCookie) o;
72
73         if (getMaxSessionTime() != that.getMaxSessionTime()) return false;
74         if (getCurrentSessionTime() != that.getCurrentSessionTime()) return false;
75         if (getUserID() != null ? !getUserID().equals(that.getUserID()) : that.getUserID() != null) return false;
76         return getRoles() != null ? getRoles().containsAll(that.getRoles()) : that.getRoles() == null;
77     }
78
79     @Override
80     public int hashCode() {
81         int result = getUserID() != null ? getUserID().hashCode() : 0;
82         result = 31 * result + (getRoles() != null ? getRoles().hashCode() : 0);
83         result = 31 * result + (int) (getMaxSessionTime() ^ (getMaxSessionTime() >>> 32));
84         result = 31 * result + (int) (getCurrentSessionTime() ^ (getCurrentSessionTime() >>> 32));
85         return result;
86     }
87
88     @Override
89     public String toString() {
90         return "AuthenticationCookie{" +
91                 "userID='" + userID + '\'' +
92                 ", roles=" + roles +
93                 ", maxSessionTime=" + maxSessionTime +
94                 ", currentSessionTime=" + currentSessionTime +
95                 '}';
96     }
97 }