/** * Copyright 2013 Tommi S.E. Laukkanen * * 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.bubblecloud.ilves.model; import org.eclipse.persistence.annotations.Index; import javax.persistence.*; import java.io.Serializable; import java.util.Date; /** * Authentication device. * * @author Tommi S.E. Laukkanen */ @Entity @Table(name = "authenticationdevice") public final class AuthenticationDevice implements Serializable { /** Java serialization version UID. */ private static final long serialVersionUID = 1L; /** Unique UUID of the entity. */ @Id @GeneratedValue(generator = "uuid") private String authenticationDeviceId; @Column(nullable = false) private AuthenticationDeviceType type; @Column(nullable = false) private String key; @Column(nullable = false) private String name; @Column(nullable = false, length = 2048) private String encryptedSecret; /** Code of the product or service sold. */ @ManyToOne(cascade = { CascadeType.DETACH, CascadeType.MERGE, CascadeType.REFRESH }, optional = false) private User user; /** Created time of the task. */ @Temporal(TemporalType.TIMESTAMP) @Column(nullable = false) private Date created; /** Created time of the task. */ @Temporal(TemporalType.TIMESTAMP) @Column(nullable = false) private Date modified; public String getAuthenticationDeviceId() { return authenticationDeviceId; } public void setAuthenticationDeviceId(String authenticationDeviceId) { this.authenticationDeviceId = authenticationDeviceId; } public Date getCreated() { return created; } public void setCreated(Date created) { this.created = created; } public Date getModified() { return modified; } public void setModified(Date modified) { this.modified = modified; } public String getEncryptedSecret() { return encryptedSecret; } public void setEncryptedSecret(String encryptedSecret) { this.encryptedSecret = encryptedSecret; } public String getKey() { return key; } public void setKey(String key) { this.key = key; } public String getName() { return name; } public void setName(String name) { this.name = name; } public AuthenticationDeviceType getType() { return type; } public void setType(AuthenticationDeviceType type) { this.type = type; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } @Override public String toString() { return "User session for: " + user.toString() + " started at " + created; } @Override public int hashCode() { return authenticationDeviceId.hashCode(); } @Override public boolean equals(final Object obj) { return obj != null && obj instanceof AuthenticationDevice && authenticationDeviceId.equals(((AuthenticationDevice) obj).getAuthenticationDeviceId()); } }