Merge pull request #323 from adityachandelgit/develop

Merge Develop into Master for Release
This commit is contained in:
Aditya Chandel
2025-05-19 22:09:34 -06:00
committed by GitHub
17 changed files with 65 additions and 30 deletions
+7 -17
View File
@@ -113,18 +113,17 @@ While the integration has been tested with **Authentik**, it should work with ot
For detailed instructions on setting up OIDC authentication with **Authentik**, refer to the [YouTube guide on configuring OIDC in BookLore](https://www.youtube.com/watch?v=r6Ufh9ldF9M), which provides step-by-step walkthroughs. For detailed instructions on setting up OIDC authentication with **Authentik**, refer to the [YouTube guide on configuring OIDC in BookLore](https://www.youtube.com/watch?v=r6Ufh9ldF9M), which provides step-by-step walkthroughs.
## 🔧 Configuration ## 🔐 Remote Authentication (Trusted Header SSO, Forward Auth)
The following environment variables can be configured: If you run BookLore behind a reverse proxy with remote authentication (middleware),
you can enable automatic login by setting `REMOTE_AUTH_ENABLED` to `true`.
This allows you to use your existing authentication system (e.g., OAuth, SAML) to log in to BookLore.
The following remote auth environment variables can be configured:
| Variable Name | Description | Default Value | | Variable Name | Description | Default Value |
|------------------------------|-----------------------------------------|---------------------------------------------------------------------| |------------------------------|-----------------------------------------|---------------------------------------------------------------------|
| DATABASE_URL | JDBC connection URL | `jdbc:mariadb://${DATABASE_HOST}:${DATABASE_PORT}/${DATABASE_NAME}` |
| DATABASE_HOST | Database hostname | `mariadb` |
| DATABASE_PORT | Database port | `3306` |
| DATABASE_NAME | Database name | `booklore` |
| DATABASE_USERNAME | Database username for app | `root` |
| DATABASE_PASSWORD | Database password for app | **required** |
| REMOTE_AUTH_ENABLED | Enable remote authentication | `false` | | REMOTE_AUTH_ENABLED | Enable remote authentication | `false` |
| REMOTE_AUTH_CREATE_NEW_USERS | Auto-create users from remote auth | `true` | | REMOTE_AUTH_CREATE_NEW_USERS | Auto-create users from remote auth | `true` |
| REMOTE_AUTH_HEADER_NAME | HTTP header containing user's name | `Remote-Name` | | REMOTE_AUTH_HEADER_NAME | HTTP header containing user's name | `Remote-Name` |
@@ -132,15 +131,6 @@ The following environment variables can be configured:
| REMOTE_AUTH_HEADER_EMAIL | HTTP header containing user's email | `Remote-Email` | | REMOTE_AUTH_HEADER_EMAIL | HTTP header containing user's email | `Remote-Email` |
| REMOTE_AUTH_HEADER_GROUPS | HTTP header containing user's groups | `Remote-Groups` | | REMOTE_AUTH_HEADER_GROUPS | HTTP header containing user's groups | `Remote-Groups` |
| REMOTE_AUTH_ADMIN_GROUP | Group name that grants admin privileges | - | | REMOTE_AUTH_ADMIN_GROUP | Group name that grants admin privileges | - |
| LOG_LEVEL | Log level for the application | `INFO` |
| ROOT_LOG_LEVEL | If you want to see all Spring logs | `INFO` |
### Remote Authentication (Trusted Header SSO, Forward Auth)
If you run BookLore behind a reverse proxy with remote authentication (middleware),
you can enable automatic login by setting `REMOTE_AUTH_ENABLED` to `true`.
This allows you to use your existing authentication system (e.g., OAuth, SAML) to log in to BookLore.
Example implementations: Example implementations:
- https://www.authelia.com/integration/trusted-header-sso/introduction/ - https://www.authelia.com/integration/trusted-header-sso/introduction/
@@ -60,6 +60,14 @@ public class DualJwtAuthenticationFilter extends OncePerRequestFilter {
@Override @Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws IOException, ServletException {
String token = extractToken(request); String token = extractToken(request);
String path = request.getRequestURI();
if (path.equals("/api/v1/auth/refresh")) {
chain.doFilter(request, response);
return;
}
if (token == null) { if (token == null) {
chain.doFilter(request, response); chain.doFilter(request, response);
return; return;
@@ -70,11 +78,14 @@ public class DualJwtAuthenticationFilter extends OncePerRequestFilter {
} else if (appSettingService.getAppSettings().isOidcEnabled()) { } else if (appSettingService.getAppSettings().isOidcEnabled()) {
authenticateOidcUser(token, request); authenticateOidcUser(token, request);
} else { } 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) { } catch (Exception ex) {
log.error("Authentication error: {}", ex.getMessage(), ex); log.error("Authentication error: {}", ex.getMessage(), ex);
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return;
} }
chain.doFilter(request, response); chain.doFilter(request, response);
} }
@@ -55,7 +55,6 @@ public class SecurityConfig {
).permitAll() ).permitAll()
.anyRequest().authenticated() .anyRequest().authenticated()
) )
.httpBasic(customizer -> customizer.realmName("Booklore OPDS"))
.addFilterBefore(dualJwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); .addFilterBefore(dualJwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class);
return http.build(); return http.build();
@@ -33,7 +33,7 @@ public enum ApiError {
USERNAME_ALREADY_TAKEN(HttpStatus.BAD_REQUEST, "Username already taken: %s"), USERNAME_ALREADY_TAKEN(HttpStatus.BAD_REQUEST, "Username already taken: %s"),
USER_NOT_FOUND(HttpStatus.BAD_REQUEST, "User not found: %s"), USER_NOT_FOUND(HttpStatus.BAD_REQUEST, "User not found: %s"),
CANNOT_DELETE_ADMIN(HttpStatus.FORBIDDEN, "Admin user cannot be deleted"), CANNOT_DELETE_ADMIN(HttpStatus.FORBIDDEN, "Admin user cannot be deleted"),
UNAUTHORIZED(HttpStatus.FORBIDDEN, "%s"), UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "%s"),
BAD_REQUEST(HttpStatus.BAD_REQUEST, "%s"), BAD_REQUEST(HttpStatus.BAD_REQUEST, "%s"),
INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "%s"), INTERNAL_SERVER_ERROR(HttpStatus.INTERNAL_SERVER_ERROR, "%s"),
PASSWORD_INCORRECT(HttpStatus.BAD_REQUEST, "Incorrect current password"), PASSWORD_INCORRECT(HttpStatus.BAD_REQUEST, "Incorrect current password"),
@@ -16,6 +16,7 @@ public class EmailProvider {
private Integer port; private Integer port;
private String username; private String username;
private String password; private String password;
private String fromAddress;
private Boolean auth; private Boolean auth;
private Boolean startTls; private Boolean startTls;
private Boolean defaultProvider; private Boolean defaultProvider;
@@ -15,6 +15,7 @@ public class CreateEmailProviderRequest {
private Integer port; private Integer port;
private String username; private String username;
private String password; private String password;
private String fromAddress;
private Boolean auth; private Boolean auth;
private Boolean startTls; private Boolean startTls;
} }
@@ -31,6 +31,9 @@ public class EmailProviderEntity {
@Column(name = "password", nullable = false) @Column(name = "password", nullable = false)
private String password; private String password;
@Column(name = "from_address")
private String fromAddress;
@Column(name = "auth", nullable = false) @Column(name = "auth", nullable = false)
private boolean auth; private boolean auth;
@@ -14,6 +14,7 @@ import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage; import jakarta.mail.internet.MimeMessage;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.mail.javamail.JavaMailSenderImpl; import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -73,7 +74,7 @@ public class EmailService {
JavaMailSenderImpl dynamicMailSender = setupMailSender(emailProvider); JavaMailSenderImpl dynamicMailSender = setupMailSender(emailProvider);
MimeMessage message = dynamicMailSender.createMimeMessage(); MimeMessage message = dynamicMailSender.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(message, true); MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom(emailProvider.getUsername()); helper.setFrom(StringUtils.firstNonEmpty(emailProvider.getFromAddress(), emailProvider.getUsername()));
helper.setTo(recipientEmail); helper.setTo(recipientEmail);
helper.setSubject("Your Book from Booklore: " + book.getMetadata().getTitle()); helper.setSubject("Your Book from Booklore: " + book.getMetadata().getTitle());
helper.setText(generateEmailBody(book.getMetadata().getTitle())); helper.setText(generateEmailBody(book.getMetadata().getTitle()));
@@ -0,0 +1,12 @@
${AnsiColor.BLUE}
▀█████████▄ ▄██████▄ ▄██████▄ ▄█ ▄█▄ ▄█ ▄██████▄ ▄████████ ▄████████
███ ███ ███ ███ ███ ███ ███ ▄███▀ ███ ███ ███ ███ ███ ███ ███
███ ███ ███ ███ ███ ███ ███▐██▀ ███ ███ ███ ███ ███ ███ █▀
▄███▄▄▄██▀ ███ ███ ███ ███ ▄█████▀ ███ ███ ███ ▄███▄▄▄▄██▀ ▄███▄▄▄
▀▀███▀▀▀██▄ ███ ███ ███ ███ ▀▀█████▄ ███ ███ ███ ▀▀███▀▀▀▀▀ ▀▀███▀▀▀
███ ██▄ ███ ███ ███ ███ ███▐██▄ ███ ███ ███ ▀███████████ ███ █▄
███ ███ ███ ███ ███ ███ ███ ▀███▄ ███▌ ▄ ███ ███ ███ ███ ███ ███
▄█████████▀ ▀██████▀ ▀██████▀ ███ ▀█▀ █████▄▄██ ▀██████▀ ███ ███ ██████████
▀ ▀ ███ ███ (${app.version})
${AnsiStyle.NORMAL}
Powered By Spring Boot : ${spring-boot.version}
@@ -0,0 +1,2 @@
ALTER TABLE email_provider
ADD COLUMN from_address VARCHAR(255) NULL AFTER password;
@@ -41,7 +41,7 @@ export class BookSenderComponent implements OnInit {
this.emailProviderService.getEmailProviders().subscribe({ this.emailProviderService.getEmailProviders().subscribe({
next: (emailProviders: EmailProvider[]) => { next: (emailProviders: EmailProvider[]) => {
this.emailProviders = emailProviders.map(provider => ({ this.emailProviders = emailProviders.map(provider => ({
label: `${provider.name} | ${provider.host}`, label: `${provider.name} | ${provider.fromAddress || provider.host}`,
value: provider value: provider
})); }));
} }
@@ -321,7 +321,7 @@ export class EpubViewerComponent implements OnInit, OnDestroy {
private trackProgress(): void { private trackProgress(): void {
if (!this.book || !this.rendition) return; if (!this.book || !this.rendition) return;
this.rendition.on('relocated', (location: any) => { this.rendition.on('relocated', (location: any) => {
const cfi = location.start.cfi; const cfi = location.end.cfi;
const currentIndex = location.start.index; const currentIndex = location.start.index;
const totalSpineItems = this.book.spine.items.length; const totalSpineItems = this.book.spine.items.length;
let percentage: number; let percentage: number;
@@ -42,6 +42,7 @@
<ng-container *ngIf="metadata.amazonRating || metadata.goodreadsRating; else legacyRating"> <ng-container *ngIf="metadata.amazonRating || metadata.goodreadsRating; else legacyRating">
<p *ngIf="metadata.amazonRating" class="font-semibold">Amazon: {{ metadata.amazonRating }}</p> <p *ngIf="metadata.amazonRating" class="font-semibold">Amazon: {{ metadata.amazonRating }}</p>
<p-rating <p-rating
*ngIf="metadata.amazonRating"
[(ngModel)]="metadata.amazonRating" [(ngModel)]="metadata.amazonRating"
readonly readonly
stars="5" stars="5"
@@ -53,6 +54,7 @@
<p *ngIf="metadata.goodreadsRating" class="font-semibold">Goodreads: {{ metadata.goodreadsRating }}</p> <p *ngIf="metadata.goodreadsRating" class="font-semibold">Goodreads: {{ metadata.goodreadsRating }}</p>
<p-rating <p-rating
*ngIf="metadata.goodreadsRating"
[(ngModel)]="metadata.goodreadsRating" [(ngModel)]="metadata.goodreadsRating"
readonly readonly
stars="5" stars="5"
@@ -34,6 +34,11 @@
<input type="password" pInputText formControlName="password" placeholder="Enter password..." class="w-full md:w-80"/> <input type="password" pInputText formControlName="password" placeholder="Enter password..." class="w-full md:w-80"/>
</div> </div>
<div class="flex items-center gap-4">
<label class="w-40 text-right font-medium">From Address:</label>
<input type="text" pInputText formControlName="fromAddress" placeholder="Enter from address... " class="w-full md:w-80"/>
</div>
<div class="flex items-center gap-4"> <div class="flex items-center gap-4">
<label class="w-40 text-right font-medium">Auth:</label> <label class="w-40 text-right font-medium">Auth:</label>
<p-checkbox formControlName="auth" [binary]="true"></p-checkbox> <p-checkbox formControlName="auth" [binary]="true"></p-checkbox>
@@ -35,6 +35,7 @@ export class CreateEmailProviderDialogComponent implements OnInit {
port: [null, [Validators.required, Validators.min(1)]], port: [null, [Validators.required, Validators.min(1)]],
username: [''], username: [''],
password: [''], password: [''],
fromAddress: ['', [Validators.email]],
auth: [false], auth: [false],
startTls: [false] startTls: [false]
}); });
@@ -12,16 +12,17 @@
<p-table [value]="emailProviders"> <p-table [value]="emailProviders">
<ng-template pTemplate="header"> <ng-template pTemplate="header">
<tr> <tr>
<th style="width: 5%;">Default</th> <th style="width: 6%;">Default</th>
<th style="width: 15%;">Name</th> <th style="width: 10%;">Name</th>
<th style="width: 15%;">Host</th> <th style="width: 15%;">Host</th>
<th style="width: 10%;">Port</th> <th style="width: 6%;">Port</th>
<th style="width: 15%;">Username</th> <th style="width: 14%;">Username</th>
<th style="width: 15%;">Password</th> <th style="width: 12%;">Password</th>
<th style="width: 12%;">From Address</th>
<th style="width: 5%;">Auth</th> <th style="width: 5%;">Auth</th>
<th style="width: 5%;">StartTLS</th> <th style="width: 5%;">StartTLS</th>
<th style="width: 10%;">Edit</th> <th style="width: 7%;">Edit</th>
<th style="width: 10%;">Delete</th> <th style="width: 8%;">Delete</th>
</tr> </tr>
</ng-template> </ng-template>
@@ -61,6 +62,11 @@
<span *ngIf="!provider.isEditing" class="text-gray-400 italic">Hidden</span> <span *ngIf="!provider.isEditing" class="text-gray-400 italic">Hidden</span>
</td> </td>
<td>
<input *ngIf="provider.isEditing" type="text" [(ngModel)]="provider.fromAddress" class="p-inputtext w-full"/>
<span *ngIf="!provider.isEditing">{{ provider.fromAddress }}</span>
</td>
<td class="text-center"> <td class="text-center">
<p-checkbox <p-checkbox
[(ngModel)]="provider.auth" [(ngModel)]="provider.auth"
@@ -6,6 +6,7 @@ export interface EmailProvider {
port: number; port: number;
username: string; username: string;
password: string; password: string;
fromAddress: string;
auth: boolean; auth: boolean;
startTls: boolean; startTls: boolean;
defaultProvider: boolean; defaultProvider: boolean;