Re-enable ForwardAuth and have ForwardAuth work using email address (#1426)
* Fallback to using email for auth if user not defined by forwardauth * Re-enable RemoteAuth * Update build env
This commit is contained in:
+13
@@ -6,6 +6,8 @@ import com.adityachandel.booklore.exception.ApiError;
|
||||
import com.adityachandel.booklore.model.dto.UserCreateRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.RefreshTokenRequest;
|
||||
import com.adityachandel.booklore.model.dto.request.UserLoginRequest;
|
||||
import com.adityachandel.booklore.model.entity.BookLoreUserEntity;
|
||||
import com.adityachandel.booklore.repository.UserRepository;
|
||||
import com.adityachandel.booklore.service.user.UserProvisioningService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -21,6 +23,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Tag(name = "Authentication", description = "Endpoints for user authentication, registration, and token management")
|
||||
@Slf4j
|
||||
@@ -32,6 +35,7 @@ public class AuthenticationController {
|
||||
private final AppProperties appProperties;
|
||||
private final UserProvisioningService userProvisioningService;
|
||||
private final AuthenticationService authenticationService;
|
||||
private final UserRepository userRepository;
|
||||
|
||||
@Operation(summary = "Register a new user", description = "Register a new user. Only admins can register users.")
|
||||
@ApiResponses({
|
||||
@@ -81,6 +85,15 @@ public class AuthenticationController {
|
||||
log.debug("Remote-Auth: retrieved values from headers: name: {}, username: {}, email: {}, groups: {}", name, username, email, groups);
|
||||
log.debug("Remote-Auth: remote auth settings: {}", appProperties.getRemoteAuth());
|
||||
|
||||
if ((username == null || username.isEmpty()) && (email != null && !email.isEmpty())) {
|
||||
log.debug("Remote-Auth: username is empty, trying to find user by email: {}", email);
|
||||
Optional<BookLoreUserEntity> user = userRepository.findByEmail(email);
|
||||
if (user.isPresent()) {
|
||||
username = user.get().getUsername();
|
||||
log.debug("Remote-Auth: found user by email, username: {}", username);
|
||||
}
|
||||
}
|
||||
|
||||
return authenticationService.loginRemote(name, username, email, groups);
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -8,5 +8,6 @@ import lombok.*;
|
||||
@NoArgsConstructor
|
||||
public class PublicAppSetting {
|
||||
private boolean oidcEnabled;
|
||||
private boolean remoteAuthEnabled;
|
||||
private OidcProviderDetails oidcProviderDetails;
|
||||
}
|
||||
@@ -12,6 +12,8 @@ public interface UserRepository extends JpaRepository<BookLoreUserEntity, Long>
|
||||
|
||||
Optional<BookLoreUserEntity> findByUsername(String username);
|
||||
|
||||
Optional<BookLoreUserEntity> findByEmail(String email);
|
||||
|
||||
Optional<BookLoreUserEntity> findById(Long id);
|
||||
|
||||
List<BookLoreUserEntity> findAllByLibraries_Id(Long libraryId);
|
||||
|
||||
+2
-1
@@ -73,6 +73,7 @@ public class AppSettingService {
|
||||
PublicAppSetting.PublicAppSettingBuilder builder = PublicAppSetting.builder();
|
||||
|
||||
builder.oidcEnabled(Boolean.parseBoolean(settingPersistenceHelper.getOrCreateSetting(AppSettingKey.OIDC_ENABLED, "false")));
|
||||
builder.remoteAuthEnabled(appProperties.getRemoteAuth().isEnabled());
|
||||
builder.oidcProviderDetails(settingPersistenceHelper.getJsonSetting(settingsMap, AppSettingKey.OIDC_PROVIDER_DETAILS, OidcProviderDetails.class, null, false));
|
||||
|
||||
return builder.build();
|
||||
@@ -111,4 +112,4 @@ public class AppSettingService {
|
||||
|
||||
return builder.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user