added .env and login endpoint

This commit is contained in:
litoral05
2026-05-11 17:26:34 +01:00
parent 8363926ec8
commit 8af8f9952a
8 changed files with 86 additions and 1 deletions
+2
View File
@@ -0,0 +1,2 @@
LR_LOGIN_USERNAME=admin
LR_LOGIN_PASSWORD=hidroteklr2026
+2
View File
@@ -31,3 +31,5 @@ build/
### VS Code ### ### VS Code ###
.vscode/ .vscode/
.env
+5
View File
@@ -62,6 +62,11 @@
<artifactId>jsch</artifactId> <artifactId>jsch</artifactId>
<version>0.2.21</version> <version>0.2.21</version>
</dependency> </dependency>
<dependency>
<groupId>me.paulschwarz</groupId>
<artifactId>spring-dotenv</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
@@ -0,0 +1,38 @@
package com.litoralregas.vpnorchestrator.login;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/login")
public class LoginController {
private final LoginService loginService;
public LoginController(
LoginService loginService
) {
this.loginService = loginService;
}
@PostMapping
public ResponseEntity<LoginResponse> login(
@RequestBody LoginRequest request
) {
boolean authenticated =
loginService.authenticate(
request.username(),
request.password()
);
if (!authenticated) {
return ResponseEntity
.status(HttpStatus.UNAUTHORIZED)
.body(new LoginResponse(false));
}
return ResponseEntity.ok(
new LoginResponse(true)
);
}
}
@@ -0,0 +1,6 @@
package com.litoralregas.vpnorchestrator.login;
public record LoginRequest(
String username,
String password
) {}
@@ -0,0 +1,5 @@
package com.litoralregas.vpnorchestrator.login;
public record LoginResponse(
boolean authenticated
) {}
@@ -0,0 +1,22 @@
package com.litoralregas.vpnorchestrator.login;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service
public class LoginService {
@Value("${lr.login.username}")
private String expectedUsername;
@Value("${lr.login.password}")
private String expectedPassword;
public boolean authenticate(
String username,
String password
) {
return expectedUsername.equals(username)
&& expectedPassword.equals(password);
}
}
+5
View File
@@ -23,3 +23,8 @@ app:
password: hidrotek2026 password: hidrotek2026
connect-timeout-ms: 10000 connect-timeout-ms: 10000
command-timeout-ms: 15000 command-timeout-ms: 15000
lr:
login:
username: ${LR_LOGIN_USERNAME}
password: ${LR_LOGIN_PASSWORD}