diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/config/security/DualJwtAuthenticationFilter.java b/booklore-api/src/main/java/com/adityachandel/booklore/config/security/DualJwtAuthenticationFilter.java index 70ada6df5..8bb93bf95 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/config/security/DualJwtAuthenticationFilter.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/config/security/DualJwtAuthenticationFilter.java @@ -60,6 +60,14 @@ public class DualJwtAuthenticationFilter extends OncePerRequestFilter { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { String token = extractToken(request); + + String path = request.getRequestURI(); + + if (path.equals("/api/v1/auth/refresh")) { + chain.doFilter(request, response); + return; + } + if (token == null) { chain.doFilter(request, response); return; @@ -70,11 +78,14 @@ public class DualJwtAuthenticationFilter extends OncePerRequestFilter { } else if (appSettingService.getAppSettings().isOidcEnabled()) { authenticateOidcUser(token, request); } else { - log.debug("OIDC is disabled. Skipping OIDC authentication."); + log.debug("OIDC is disabled and token is invalid. Rejecting request."); + response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + return; } } catch (Exception ex) { log.error("Authentication error: {}", ex.getMessage(), ex); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); + return; } chain.doFilter(request, response); } diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/config/security/SecurityConfig.java b/booklore-api/src/main/java/com/adityachandel/booklore/config/security/SecurityConfig.java index 4d66bdb55..4be4b8b1a 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/config/security/SecurityConfig.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/config/security/SecurityConfig.java @@ -55,7 +55,6 @@ public class SecurityConfig { ).permitAll() .anyRequest().authenticated() ) - .httpBasic(customizer -> customizer.realmName("Booklore OPDS")) .addFilterBefore(dualJwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); return http.build(); diff --git a/booklore-api/src/main/java/com/adityachandel/booklore/exception/ApiError.java b/booklore-api/src/main/java/com/adityachandel/booklore/exception/ApiError.java index 2ed100f1d..3a54440f5 100644 --- a/booklore-api/src/main/java/com/adityachandel/booklore/exception/ApiError.java +++ b/booklore-api/src/main/java/com/adityachandel/booklore/exception/ApiError.java @@ -33,7 +33,7 @@ public enum ApiError { USERNAME_ALREADY_TAKEN(HttpStatus.BAD_REQUEST, "Username already taken: %s"), USER_NOT_FOUND(HttpStatus.BAD_REQUEST, "User not found: %s"), CANNOT_DELETE_ADMIN(HttpStatus.FORBIDDEN, "Admin user cannot be deleted"), - UNAUTHORIZED(HttpStatus.FORBIDDEN, "%s"), + UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "%s"), BAD_REQUEST(HttpStatus.BAD_REQUEST, "%s"), INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "%s"), PASSWORD_INCORRECT(HttpStatus.BAD_REQUEST, "Incorrect current password"), diff --git a/booklore-ui/src/app/book/components/epub-viewer/component/epub-viewer.component.ts b/booklore-ui/src/app/book/components/epub-viewer/component/epub-viewer.component.ts index 27ddb078b..bb4fbb21a 100644 --- a/booklore-ui/src/app/book/components/epub-viewer/component/epub-viewer.component.ts +++ b/booklore-ui/src/app/book/components/epub-viewer/component/epub-viewer.component.ts @@ -321,7 +321,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy { private trackProgress(): void { if (!this.book || !this.rendition) return; this.rendition.on('relocated', (location: any) => { - const cfi = location.start.cfi; + const cfi = location.end.cfi; const currentIndex = location.start.index; const totalSpineItems = this.book.spine.items.length; let percentage: number;