Self‑registration has been added
CI - Frontend Quality Thresholds / Frontend Lint Threshold Check (push) Canceled after 0s
Reusable - Flyway Migration Check / Flyway DB Migration Preview (push) Canceled after 0s
Reusable - Flyway Migration Check / Check for DB Migrations (push) Canceled after 0s
Release - Semantic Stable / Flyway Migration Check (push) Canceled after 0s
Release - Semantic Stable / Resolve release ref (push) Canceled after 0s
Release - Semantic Stable / Test Suite (push) Canceled after 0s
Release - Semantic Stable / Generate Notes (push) Canceled after 0s
Release - Semantic Stable / Build frontend (push) Canceled after 0s
Release - Semantic Stable / Build backend (push) Canceled after 0s
Release - Semantic Stable / Build OpenAPI document (push) Canceled after 0s
Release - Semantic Stable / Create Draft Release (push) Canceled after 0s
CI - Frontend Quality Thresholds / Frontend Lint Threshold Check (push) Canceled after 0s
Reusable - Flyway Migration Check / Flyway DB Migration Preview (push) Canceled after 0s
Reusable - Flyway Migration Check / Check for DB Migrations (push) Canceled after 0s
Release - Semantic Stable / Flyway Migration Check (push) Canceled after 0s
Release - Semantic Stable / Resolve release ref (push) Canceled after 0s
Release - Semantic Stable / Test Suite (push) Canceled after 0s
Release - Semantic Stable / Generate Notes (push) Canceled after 0s
Release - Semantic Stable / Build frontend (push) Canceled after 0s
Release - Semantic Stable / Build backend (push) Canceled after 0s
Release - Semantic Stable / Build OpenAPI document (push) Canceled after 0s
Release - Semantic Stable / Create Draft Release (push) Canceled after 0s
This commit is contained in:
@@ -58,6 +58,7 @@ public class SecurityConfig {
|
||||
"/api/docs", // API documentation UI
|
||||
"/api/openapi.json", // OpenAPI spec (used by API documentation UI)
|
||||
"/api/v1/auth/login", // Login endpoint (must remain public)
|
||||
"/api/v1/auth/register", // <--- ДОБАВЛЕНО: Registration endpoint
|
||||
"/api/v1/auth/refresh", // Token refresh endpoint (must remain public)
|
||||
"/api/v1/auth/remote", // Remote auth endpoint (must remain public)
|
||||
"/api/v1/auth/oidc/**", // OIDC authentication endpoints
|
||||
|
||||
@@ -20,7 +20,6 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Optional;
|
||||
@@ -37,15 +36,23 @@ public class AuthenticationController {
|
||||
private final AuthenticationService authenticationService;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Operation(summary = "Register a new user", description = "Register a new user. Only admins can register users.")
|
||||
@Operation(summary = "Register a new user", description = "Register a new user. Now open to the public.")
|
||||
@ApiResponses({
|
||||
@ApiResponse(responseCode = "204", description = "User registered successfully"),
|
||||
@ApiResponse(responseCode = "403", description = "Forbidden")
|
||||
@ApiResponse(responseCode = "400", description = "Username already exists"),
|
||||
@ApiResponse(responseCode = "403", description = "Forbidden") // Оставляем на случай, если логика внутри сервиса выкинет ошибку
|
||||
})
|
||||
@PostMapping("/register")
|
||||
@PreAuthorize("@securityUtil.isAdmin()")
|
||||
// УДАЛЕНО: @PreAuthorize("@securityUtil.isAdmin()") - теперь регистрация открыта для всех
|
||||
public ResponseEntity<?> registerUser(
|
||||
@Parameter(description = "User registration request") @RequestBody @Valid UserCreateRequest userCreateRequest) {
|
||||
|
||||
// Дополнительная проверка: не занято ли имя пользователя
|
||||
// (UserProvisioningService может делать это сам, но лучше перестраховаться)
|
||||
if (userRepository.findByUsername(userCreateRequest.getUsername()).isPresent()) {
|
||||
return ResponseEntity.badRequest().body("Username already exists");
|
||||
}
|
||||
|
||||
userProvisioningService.provisionInternalUser(userCreateRequest);
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public class UserProvisioningService {
|
||||
|
||||
BookLoreUserEntity user = new BookLoreUserEntity();
|
||||
user.setUsername(request.getUsername());
|
||||
user.setDefaultPassword(true);
|
||||
user.setDefaultPassword(false);
|
||||
user.setPasswordHash(passwordEncoder.encode(request.getPassword()));
|
||||
user.setName(request.getName());
|
||||
user.setEmail(request.getEmail());
|
||||
|
||||
Reference in New Issue
Block a user