Fix security risk 'Improper Input Validation'
[sdc.git] / catalog-model / src / main / java / org / openecomp / sdc / be / model / User.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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 package org.openecomp.sdc.be.model;
21
22 import com.fasterxml.jackson.annotation.JsonInclude;
23 import lombok.EqualsAndHashCode;
24 import lombok.Getter;
25 import lombok.NoArgsConstructor;
26 import lombok.Setter;
27 import lombok.ToString;
28 import org.joda.time.DateTime;
29 import org.joda.time.DateTimeZone;
30 import org.openecomp.sdc.be.dao.utils.UserStatusEnum;
31 import org.openecomp.sdc.common.util.NoHtml;
32
33 @JsonInclude
34 @NoArgsConstructor
35 @Getter
36 @Setter
37 @ToString
38 @EqualsAndHashCode
39 public class User {
40
41     public static final String FORCE_DELETE_HEADER_FLAG = "FORCE_DELETE";
42     @NoHtml
43     private String firstName;
44     @NoHtml
45     private String lastName;
46     @NoHtml
47     private String userId;
48     @NoHtml
49     private String email;
50     @NoHtml
51     private String role;
52     private Long lastLoginTime;
53     @ToString.Exclude
54     @EqualsAndHashCode.Exclude
55     private UserStatusEnum status = UserStatusEnum.ACTIVE;
56
57     public User(String userId) {
58         this.userId = userId;
59     }
60
61     public User(String firstName, String lastName, String userId, String emailAddress, String role, Long lastLoginTime) {
62         this.firstName = firstName;
63         this.lastName = lastName;
64         this.userId = userId;
65         this.email = emailAddress;
66         this.role = role;
67         this.lastLoginTime = lastLoginTime;
68     }
69
70     public User(User aUser) {
71         this(aUser.getFirstName(), aUser.getLastName(), aUser.getUserId(), aUser.getEmail(), aUser.getRole(), aUser.getLastLoginTime());
72     }
73
74     public void copyData(User other) {
75         if (other == null) {
76             return;
77         }
78         this.firstName = other.getFirstName();
79         this.lastName = other.getLastName();
80         this.userId = other.getUserId();
81         this.email = other.getEmail();
82         this.role = other.getRole();
83         this.lastLoginTime = other.getLastLoginTime();
84     }
85
86     public String getFullName() {
87         return this.getFirstName() + " " + this.getLastName();
88     }
89
90     public void setLastLoginTime() {
91         DateTime now = new DateTime(DateTimeZone.UTC);
92         this.lastLoginTime = now.getMillis();
93     }
94
95 }