remove hardcoded passwords
This commit is contained in:
@@ -2,10 +2,11 @@ package com.storycove;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@SpringBootApplication
|
||||
@SpringBootApplication(exclude = {UserDetailsServiceAutoConfiguration.class})
|
||||
@EnableScheduling
|
||||
@EnableAsync
|
||||
public class StoryCoveApplication {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.storycove.config;
|
||||
|
||||
import com.storycove.service.LibraryService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -11,7 +12,6 @@ import org.springframework.stereotype.Component;
|
||||
import javax.sql.DataSource;
|
||||
import java.sql.Connection;
|
||||
import java.sql.Statement;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -28,20 +28,15 @@ public class DatabaseMigrationRunner implements CommandLineRunner {
|
||||
@Autowired
|
||||
private DataSource dataSource;
|
||||
|
||||
@Autowired
|
||||
private LibraryService libraryService;
|
||||
|
||||
@Value("${spring.datasource.username}")
|
||||
private String dbUsername;
|
||||
|
||||
@Value("${spring.datasource.password}")
|
||||
private String dbPassword;
|
||||
|
||||
// List of all library databases that need migrations
|
||||
private static final List<String> LIBRARY_DATABASES = Arrays.asList(
|
||||
"storycove", // default database
|
||||
"storycove_afterdark",
|
||||
"storycove_clas",
|
||||
"storycove_secret"
|
||||
);
|
||||
|
||||
// SQL for last_completed_at column migration (idempotent)
|
||||
private static final String LAST_COMPLETED_AT_MIGRATION =
|
||||
"ALTER TABLE stories ADD COLUMN IF NOT EXISTS last_completed_at TIMESTAMP;";
|
||||
@@ -78,7 +73,12 @@ public class DatabaseMigrationRunner implements CommandLineRunner {
|
||||
public void run(String... args) throws Exception {
|
||||
logger.info("🗄️ Starting database migrations...");
|
||||
|
||||
for (String database : LIBRARY_DATABASES) {
|
||||
List<String> databases = libraryService.getAllLibraries().stream()
|
||||
.map(lib -> libraryService.getDbNameForLibrary(lib.getId()))
|
||||
.filter(db -> db != null && !db.isBlank())
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
|
||||
for (String database : databases) {
|
||||
try {
|
||||
applyMigrations(database);
|
||||
logger.info("✅ Successfully applied migrations to database: {}", database);
|
||||
|
||||
@@ -33,12 +33,15 @@ public class LibraryService implements ApplicationContextAware {
|
||||
|
||||
@Value("${spring.datasource.url}")
|
||||
private String baseDbUrl;
|
||||
|
||||
|
||||
@Value("${spring.datasource.username}")
|
||||
private String dbUsername;
|
||||
|
||||
|
||||
@Value("${spring.datasource.password}")
|
||||
private String dbPassword;
|
||||
|
||||
@Value("${storycove.auth.password}")
|
||||
private String appPassword;
|
||||
|
||||
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
@@ -252,6 +255,11 @@ public class LibraryService implements ApplicationContextAware {
|
||||
return current != null ? current.getImagePath() : "/images/default";
|
||||
}
|
||||
|
||||
public String getDbNameForLibrary(String libraryId) {
|
||||
Library library = libraries.get(libraryId);
|
||||
return library != null ? library.getDbName() : null;
|
||||
}
|
||||
|
||||
public String getImagePathForLibrary(String libraryId) {
|
||||
if (libraryId == null) {
|
||||
return "/images/default";
|
||||
@@ -358,21 +366,17 @@ public class LibraryService implements ApplicationContextAware {
|
||||
|
||||
Library defaultLibrary = new Library(
|
||||
"main",
|
||||
"Main Library",
|
||||
"Your existing story collection (migrated)",
|
||||
passwordEncoder.encode("temp-password-change-me"), // Temporary password
|
||||
existingDbName // Use existing database name
|
||||
"Main Library",
|
||||
"Your story collection",
|
||||
passwordEncoder.encode(appPassword),
|
||||
existingDbName
|
||||
);
|
||||
defaultLibrary.setInitialized(true); // Mark as initialized since it has existing data
|
||||
|
||||
defaultLibrary.setInitialized(true);
|
||||
|
||||
libraries.put("main", defaultLibrary);
|
||||
saveLibrariesToFile();
|
||||
|
||||
logger.warn("=".repeat(80));
|
||||
logger.warn("MIGRATION: Created 'Main Library' for your existing data");
|
||||
logger.warn("Temporary password: 'temp-password-change-me'");
|
||||
logger.warn("IMPORTANT: Please set a proper password in Settings > Library Settings");
|
||||
logger.warn("=".repeat(80));
|
||||
|
||||
logger.info("Created default library 'Main Library' using APP_PASSWORD");
|
||||
}
|
||||
|
||||
private String extractDatabaseName(String jdbcUrl) {
|
||||
|
||||
Reference in New Issue
Block a user