2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.securityutil;
26 public class AuthenticationCookie {
28 private String userID;
29 private Set<String> roles;
30 private long maxSessionTime;
31 private long currentSessionTime;
33 public AuthenticationCookie(){ }
35 public AuthenticationCookie(AuthenticationCookie authenticationCookie){
36 this.userID = authenticationCookie.userID;
37 this.roles = authenticationCookie.roles;
38 this.maxSessionTime = authenticationCookie.maxSessionTime;
39 this.currentSessionTime = authenticationCookie.currentSessionTime;
43 * Create new cookie with max_session_time and current_session_time started with same value
46 public AuthenticationCookie(String userId) {
48 long currentTimeMilliSec = System.currentTimeMillis();
49 this.maxSessionTime = currentTimeMilliSec;
50 this.currentSessionTime = currentTimeMilliSec;
53 public String getUserID() {
57 public void setUserID(String userID) {
61 public Set getRoles() {
65 public void setRoles(Set<String> roles) {
69 public long getMaxSessionTime() {
70 return maxSessionTime;
73 public void setMaxSessionTime(long maxSessionTime) {
74 this.maxSessionTime = maxSessionTime;
78 public long getCurrentSessionTime() {
79 return currentSessionTime;
82 public void setCurrentSessionTime(long currentSessionTime) {
83 this.currentSessionTime = currentSessionTime;
87 public boolean equals(Object o) {
88 if (this == o) return true;
89 if (!(o instanceof AuthenticationCookie)) return false;
91 AuthenticationCookie that = (AuthenticationCookie) o;
93 if (getMaxSessionTime() != that.getMaxSessionTime()) return false;
94 if (getCurrentSessionTime() != that.getCurrentSessionTime()) return false;
95 if (getUserID() != null ? !getUserID().equals(that.getUserID()) : that.getUserID() != null) return false;
96 return getRoles() != null ? getRoles().containsAll(that.getRoles()) : that.getRoles() == null;
100 public int hashCode() {
101 int result = getUserID() != null ? getUserID().hashCode() : 0;
102 result = 31 * result + (getRoles() != null ? getRoles().hashCode() : 0);
103 result = 31 * result + (int) (getMaxSessionTime() ^ (getMaxSessionTime() >>> 32));
104 result = 31 * result + (int) (getCurrentSessionTime() ^ (getCurrentSessionTime() >>> 32));
109 public String toString() {
110 return "AuthenticationCookie{" +
111 "userID='" + userID + '\'' +
113 ", maxSessionTime=" + maxSessionTime +
114 ", currentSessionTime=" + currentSessionTime +