Add: full basic Huertos functionality
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package net.miarma.backlib.config;
|
||||
|
||||
import net.miarma.backlib.security.JwtService;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
@@ -20,4 +21,9 @@ public class SecurityCommonConfig {
|
||||
public PasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder(12);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JwtService jwtService() {
|
||||
return new JwtService();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package net.miarma.backlib.dto;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class CreateCredentialDto {
|
||||
private UUID userId;
|
||||
private Byte serviceId;
|
||||
private String username;
|
||||
private String email;
|
||||
private String password;
|
||||
private Byte status;
|
||||
|
||||
public CreateCredentialDto() {}
|
||||
|
||||
public CreateCredentialDto(UUID userId, Byte serviceId, String username, String email,
|
||||
String password, Byte status) {
|
||||
this.userId = userId;
|
||||
this.serviceId = serviceId;
|
||||
this.username = username;
|
||||
this.email = email;
|
||||
this.password = password;
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
// Getters y setters
|
||||
public UUID getUserId() {
|
||||
return userId;
|
||||
}
|
||||
public void setUserId(UUID userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
public Byte getServiceId() {
|
||||
return serviceId;
|
||||
}
|
||||
public void setServiceId(Byte serviceId) {
|
||||
this.serviceId = serviceId;
|
||||
}
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
public String getPassword() { return password; }
|
||||
public void setPassword(String password) { this.password = password; }
|
||||
public Byte getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(Byte status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
123
backlib/src/main/java/net/miarma/backlib/dto/FileDto.java
Normal file
123
backlib/src/main/java/net/miarma/backlib/dto/FileDto.java
Normal file
@@ -0,0 +1,123 @@
|
||||
package net.miarma.backlib.dto;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FileDto {
|
||||
|
||||
private FileDto() {}
|
||||
|
||||
public static class Request {
|
||||
private String fileName;
|
||||
private String filePath;
|
||||
private String mimeType;
|
||||
private Byte context;
|
||||
private UUID uploadedBy;
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getMimeType() {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
public void setMimeType(String mimeType) {
|
||||
this.mimeType = mimeType;
|
||||
}
|
||||
|
||||
public Byte getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void setContext(Byte context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public UUID getUploadedBy() {
|
||||
return uploadedBy;
|
||||
}
|
||||
|
||||
public void setUploadedBy(UUID uploadedBy) {
|
||||
this.uploadedBy = uploadedBy;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Response {
|
||||
private UUID fileId;
|
||||
private String fileName;
|
||||
private String filePath;
|
||||
private String mimeType;
|
||||
private UUID uploadedBy;
|
||||
private Instant uploadedAt;
|
||||
private Byte context;
|
||||
|
||||
public UUID getFileId() {
|
||||
return fileId;
|
||||
}
|
||||
|
||||
public void setFileId(UUID fileId) {
|
||||
this.fileId = fileId;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public String getFilePath() {
|
||||
return filePath;
|
||||
}
|
||||
|
||||
public void setFilePath(String filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
public String getMimeType() {
|
||||
return mimeType;
|
||||
}
|
||||
|
||||
public void setMimeType(String mimeType) {
|
||||
this.mimeType = mimeType;
|
||||
}
|
||||
|
||||
public UUID getUploadedBy() {
|
||||
return uploadedBy;
|
||||
}
|
||||
|
||||
public void setUploadedBy(UUID uploadedBy) {
|
||||
this.uploadedBy = uploadedBy;
|
||||
}
|
||||
|
||||
public Instant getUploadedAt() {
|
||||
return uploadedAt;
|
||||
}
|
||||
|
||||
public void setUploadedAt(Instant uploadedAt) {
|
||||
this.uploadedAt = uploadedAt;
|
||||
}
|
||||
|
||||
public Byte getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
public void setContext(Byte context) {
|
||||
this.context = context;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package net.miarma.backlib.dto;
|
||||
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import tools.jackson.databind.JsonNode;
|
||||
|
||||
public record LoginRequest(@NotBlank String username,
|
||||
@NotBlank String password,
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package net.miarma.backlib.dto;
|
||||
|
||||
public record LoginResponse(String token,
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public record LoginResponse(@JsonProperty("token") String token,
|
||||
UserDto user,
|
||||
CredentialDto account) {}
|
||||
@@ -0,0 +1,3 @@
|
||||
package net.miarma.backlib.dto;
|
||||
|
||||
public record UserWithCredentialDto(UserDto user, CredentialDto account) {}
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.miarma.backlib.security;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CoreAuthTokenHolder {
|
||||
private volatile String token;
|
||||
|
||||
public String getToken() {
|
||||
return token;
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
this.token = token;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import java.security.spec.PKCS8EncodedKeySpec;
|
||||
import java.security.spec.X509EncodedKeySpec;
|
||||
import java.util.Base64;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package net.miarma.backlib.security;
|
||||
|
||||
import jakarta.servlet.FilterChain;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Component
|
||||
public class ServiceAuthFilter extends OncePerRequestFilter {
|
||||
|
||||
private final JwtService jwtService;
|
||||
|
||||
public ServiceAuthFilter(JwtService jwtService) {
|
||||
this.jwtService = jwtService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFilterInternal(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
FilterChain filterChain)
|
||||
throws ServletException, IOException {
|
||||
|
||||
String path = request.getRequestURI();
|
||||
|
||||
if (path.startsWith("/users/service")) {
|
||||
String authHeader = request.getHeader("Authorization");
|
||||
if (authHeader == null || !authHeader.startsWith("Bearer ")) {
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
return;
|
||||
}
|
||||
|
||||
String token = authHeader.substring(7);
|
||||
if (!jwtService.validateToken(token)) {
|
||||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
filterChain.doFilter(request, response);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user