added .env and login endpoint
This commit is contained in:
@@ -31,3 +31,5 @@ build/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
.env
|
||||
@@ -62,6 +62,11 @@
|
||||
<artifactId>jsch</artifactId>
|
||||
<version>0.2.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.paulschwarz</groupId>
|
||||
<artifactId>spring-dotenv</artifactId>
|
||||
<version>4.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<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);
|
||||
}
|
||||
}
|
||||
@@ -23,3 +23,8 @@ app:
|
||||
password: hidrotek2026
|
||||
connect-timeout-ms: 10000
|
||||
command-timeout-ms: 15000
|
||||
|
||||
lr:
|
||||
login:
|
||||
username: ${LR_LOGIN_USERNAME}
|
||||
password: ${LR_LOGIN_PASSWORD}
|
||||
Reference in New Issue
Block a user