/* * Copyright 2014-2016 CyberVision, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.kaaproject.kaa.server.admin.services.entity; import org.hibernate.annotations.Fetch; import org.hibernate.annotations.FetchMode; import java.util.Collection; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.xml.bind.annotation.XmlTransient; @Entity @Table(name = "admin_user") public class User { public static final int TEMPORARY_PASSWORD_LENGTH = 12; @Id @GeneratedValue private Long id; @Column(unique = true) private String username; private String password; private boolean enabled; private String firstName; private String lastName; private String mail; private boolean tempPassword; private String passwordResetHash; @OneToMany(cascade = CascadeType.ALL, mappedBy = "user") @Fetch(FetchMode.JOIN) private Collection<Authority> authorities; public User() { } /** * Create new instance of <code>User</code>. * * @param username is username * @param password is password * @param enabled is enabled user or not * @param firstName is user's firstName * @param lastName is user's lastName * @param mail is user's mail */ public User(String username, String password, boolean enabled, String firstName, String lastName, String mail) { super(); this.username = username; this.password = password; this.enabled = enabled; this.firstName = firstName; this.lastName = lastName; this.mail = mail; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public boolean isEnabled() { return enabled; } public void setEnabled(boolean enabled) { this.enabled = enabled; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getMail() { return mail; } public void setMail(String mail) { this.mail = mail; } public boolean isTempPassword() { return tempPassword; } public void setTempPassword(boolean tempPassword) { this.tempPassword = tempPassword; } public String getPasswordResetHash() { return passwordResetHash; } public void setPasswordResetHash(String passwordResetHash) { this.passwordResetHash = passwordResetHash; } @XmlTransient public Collection<Authority> getAuthorities() { return authorities; } public void setAuthorities(Collection<Authority> authorities) { this.authorities = authorities; } @Override public String toString() { return "User [id=" + id + ", username=" + username + ", password=" + password + ", enabled=" + enabled + ", firstName=" + firstName + ", lastName=" + lastName + ", mail=" + mail + ", authorities=" + authorities + "]"; } public boolean isAccountNonExpired() { return true; } public boolean isAccountNonLocked() { return true; } public boolean isCredentialsNonExpired() { return true; } }