added .env and login endpoint
This commit is contained in:
@@ -31,3 +31,5 @@ build/
|
|||||||
|
|
||||||
### VS Code ###
|
### VS Code ###
|
||||||
.vscode/
|
.vscode/
|
||||||
|
|
||||||
|
.env
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,4 +22,9 @@ app:
|
|||||||
username: lr-vpn
|
username: lr-vpn
|
||||||
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}
|
||||||
Reference in New Issue
Block a user