optimierungen auth-Modul und cache-Modul
This commit is contained in:
@@ -9,6 +9,21 @@ plugins {
|
||||
alias(libs.plugins.spring.dependencyManagement)
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(21))
|
||||
}
|
||||
}
|
||||
|
||||
tasks.test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
java {
|
||||
withJavadocJar()
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
// Stellt sicher, dass alle Versionen aus der zentralen BOM kommen.
|
||||
|
||||
+14
-14
@@ -5,37 +5,37 @@ import com.benasher44.uuid.Uuid
|
||||
import java.time.LocalDateTime
|
||||
|
||||
/**
|
||||
* Service for user authentication and password management.
|
||||
* Service für Benutzerauthentifizierung und Passwortverwaltung.
|
||||
*/
|
||||
interface AuthenticationService {
|
||||
/**
|
||||
* Authenticates a user with the given username and password.
|
||||
* Authentifiziert einen Benutzer mit Benutzernamen und Passwort.
|
||||
*
|
||||
* @param username The username
|
||||
* @param password The password
|
||||
* @return The authentication result
|
||||
* @param username Der Benutzername
|
||||
* @param password Das Passwort
|
||||
* @return Das Authentifizierungsergebnis
|
||||
*/
|
||||
suspend fun authenticate(username: String, password: String): AuthResult
|
||||
|
||||
/**
|
||||
* Changes a user's password.
|
||||
* Ändert das Passwort eines Benutzers.
|
||||
*
|
||||
* @param userId The user ID
|
||||
* @param currentPassword The current password
|
||||
* @param newPassword The new password
|
||||
* @return The password change result
|
||||
* @param userId Die Benutzer-ID
|
||||
* @param currentPassword Das aktuelle Passwort
|
||||
* @param newPassword Das neue Passwort
|
||||
* @return Das Ergebnis der Passwortänderung
|
||||
*/
|
||||
suspend fun changePassword(userId: Uuid, currentPassword: String, newPassword: String): PasswordChangeResult
|
||||
|
||||
/**
|
||||
* Possible results of an authentication attempt.
|
||||
* Mögliche Ergebnisse eines Authentifizierungsversuchs.
|
||||
*/
|
||||
sealed class AuthResult {
|
||||
/**
|
||||
* Authentication was successful.
|
||||
* Authentifizierung war erfolgreich.
|
||||
*
|
||||
* @param token The JWT token
|
||||
* @param user The authenticated user
|
||||
* @param token Das JWT-Token
|
||||
* @param user Der authentifizierte Benutzer
|
||||
*/
|
||||
data class Success(val token: String, val user: AuthenticatedUser) : AuthResult()
|
||||
|
||||
|
||||
+6
@@ -23,6 +23,12 @@ class JwtService(
|
||||
) {
|
||||
private val logger = KotlinLogging.logger {}
|
||||
|
||||
init {
|
||||
require(secret.length >= 32) { "JWT secret must be at least 32 characters for HMAC512" }
|
||||
require(issuer.isNotBlank()) { "JWT issuer must not be blank" }
|
||||
require(audience.isNotBlank()) { "JWT audience must not be blank" }
|
||||
}
|
||||
|
||||
private val algorithm = Algorithm.HMAC512(secret)
|
||||
private val verifier = JWT.require(algorithm)
|
||||
.withIssuer(issuer)
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ class JwtServiceTest {
|
||||
@Test
|
||||
fun `validateToken should return false for token with wrong secret`() {
|
||||
// Arrange
|
||||
val otherService = JwtService("a-different-wrong-secret", testIssuer, testAudience)
|
||||
val otherService = JwtService("a-different-wrong-secret-that-is-long-enough-1234567890", testIssuer, testAudience)
|
||||
val token = otherService.generateToken("user-123", "test", emptyList())
|
||||
|
||||
// Act & Assert
|
||||
|
||||
Reference in New Issue
Block a user