12355f25c7
- Rewrote AuthController to inject all dependencies via constructor - Fixed token refresh/login logic and added rate limiter and blacklist support - Implemented getters in LoginRequest DTO - Updated User model to implement UserDetails and extend entity.User - Switched HDFScontroller to use entity.User instead of models.User - Rewrote HDFSConfig to include static getHDFS() method and secure config via env vars - Simplified JwtService, added overload for entity.User, and fixed key handling
139 lines
3.0 KiB
Java
139 lines
3.0 KiB
Java
package com.skycrate.backend.skycrateBackend.models;
|
|
|
|
import java.util.Collection;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
|
|
import org.hibernate.annotations.CreationTimestamp;
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
import org.springframework.security.core.userdetails.UserDetails;
|
|
|
|
import jakarta.persistence.*;
|
|
|
|
@Table(name = "users")
|
|
@Entity
|
|
public class User extends com.skycrate.backend.skycrateBackend.entity.User implements UserDetails {
|
|
|
|
@Id
|
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
|
@Column(nullable = false)
|
|
private Integer id;
|
|
|
|
@Column(nullable = false)
|
|
private String username;
|
|
|
|
@Column(unique = true, nullable = false)
|
|
private String email;
|
|
|
|
@Column(nullable = false)
|
|
private String password;
|
|
|
|
// ✅ Add RSA key fields
|
|
@Lob
|
|
@Column(name = "public_key", columnDefinition = "BLOB")
|
|
private byte[] publicKey;
|
|
|
|
@Lob
|
|
@Column(name = "private_key", columnDefinition = "BLOB")
|
|
private byte[] privateKey;
|
|
|
|
|
|
@CreationTimestamp
|
|
@Column(updatable = false, name = "created_at")
|
|
private Date createdAt;
|
|
|
|
public User() {}
|
|
|
|
public User(String firstname, String lastname, String email, String password) {
|
|
this.username = firstname + lastname;
|
|
this.email = email;
|
|
this.password = password;
|
|
}
|
|
|
|
// ⬇️ Required by Spring Security
|
|
@Override
|
|
public Collection<? extends GrantedAuthority> getAuthorities() {
|
|
return List.of();
|
|
}
|
|
|
|
@Override
|
|
public String getUsername() {
|
|
return email;
|
|
}
|
|
|
|
@Override
|
|
public String getPassword() {
|
|
return password;
|
|
}
|
|
|
|
@Override
|
|
public boolean isAccountNonExpired() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean isAccountNonLocked() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean isCredentialsNonExpired() {
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public boolean isEnabled() {
|
|
return true;
|
|
}
|
|
|
|
// ⬇️ Getters and Setters
|
|
public Integer getId() {
|
|
return id;
|
|
}
|
|
|
|
public void setId(Integer id) {
|
|
this.id = id;
|
|
}
|
|
|
|
public void setFullname(String firstname, String lastname) {
|
|
this.username = firstname + lastname;
|
|
}
|
|
|
|
public String getFullname() {
|
|
return this.username;
|
|
}
|
|
|
|
public void setEmail(String email) {
|
|
this.email = email;
|
|
}
|
|
|
|
public void setPassword(String password) {
|
|
this.password = password;
|
|
}
|
|
|
|
public Date getCreatedAt() {
|
|
return createdAt;
|
|
}
|
|
|
|
public void setCreatedAt(Date createdAt) {
|
|
this.createdAt = createdAt;
|
|
}
|
|
|
|
// ✅ Getters and setters for RSA keys
|
|
public byte[] getPublicKey() {
|
|
return publicKey;
|
|
}
|
|
|
|
public void setPublicKey(byte[] publicKey) {
|
|
this.publicKey = publicKey;
|
|
}
|
|
|
|
public byte[] getPrivateKey() {
|
|
return privateKey;
|
|
}
|
|
|
|
public void setPrivateKey(byte[] privateKey) {
|
|
this.privateKey = privateKey;
|
|
}
|
|
}
|