From 4d36c420aa5b362f022cb3b2b613789691409834 Mon Sep 17 00:00:00 2001 From: straumat Date: Sun, 14 Jan 2024 22:41:05 +0100 Subject: [PATCH] Added spring-session-jdbc --- .../main/resources/META-INF/spring.factories | 1 - .../src/main/resources/application.properties | 2 +- .../src/test/resources/application.properties | 2 +- .../src/main/resources/application.properties | 2 +- .../src/main/resources/application.properties | 2 +- backend/servers/explorer-web/pom.xml | 4 ++++ .../configuration/SecurityConfiguration.java | 18 +++++++++++------- .../main/resources/application-dev.properties | 15 ++++++++++++++- .../src/main/resources/application.properties | 7 ++++++- .../src/test/resources/application.properties | 2 +- 10 files changed, 40 insertions(+), 15 deletions(-) diff --git a/backend/explorer-core/autoconfigure/src/main/resources/META-INF/spring.factories b/backend/explorer-core/autoconfigure/src/main/resources/META-INF/spring.factories index 2e2d55626..91001ca05 100644 --- a/backend/explorer-core/autoconfigure/src/main/resources/META-INF/spring.factories +++ b/backend/explorer-core/autoconfigure/src/main/resources/META-INF/spring.factories @@ -1,4 +1,3 @@ -#org.springframework.boot.diagnostics.FailureAnalyzer=tech.cassandre.trading.bot.util.exception.ConfigurationFailureAnalyzer org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ org.royllo.explorer.core.configuration.DatabaseConfiguration,\ org.royllo.explorer.core.configuration.ParametersConfiguration \ No newline at end of file diff --git a/backend/explorer-core/autoconfigure/src/main/resources/application.properties b/backend/explorer-core/autoconfigure/src/main/resources/application.properties index 87c4b323d..b792135d1 100644 --- a/backend/explorer-core/autoconfigure/src/main/resources/application.properties +++ b/backend/explorer-core/autoconfigure/src/main/resources/application.properties @@ -11,7 +11,7 @@ royllo.explorer.content.base-url=https://content.royllo.org # ====================================================================================================================== # Database access configuration. spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver -spring.datasource.url=jdbc:hsqldb:mem:cassandre-database;DB_CLOSE_DELAY=-1 +spring.datasource.url=jdbc:hsqldb:mem:explorer-royllo-database spring.datasource.username=sa spring.datasource.password= # diff --git a/backend/explorer-core/autoconfigure/src/test/resources/application.properties b/backend/explorer-core/autoconfigure/src/test/resources/application.properties index 6a010af5d..3b1d2f4a5 100644 --- a/backend/explorer-core/autoconfigure/src/test/resources/application.properties +++ b/backend/explorer-core/autoconfigure/src/test/resources/application.properties @@ -5,7 +5,7 @@ # ====================================================================================================================== # Database access configuration. spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver -spring.datasource.url=jdbc:hsqldb:mem:cassandre-database;DB_CLOSE_DELAY=-1 +spring.datasource.url=jdbc:hsqldb:mem:explorer-royllo-database spring.datasource.username=sa spring.datasource.password= # diff --git a/backend/servers/explorer-api/src/main/resources/application.properties b/backend/servers/explorer-api/src/main/resources/application.properties index bb824a0a7..6708717c1 100644 --- a/backend/servers/explorer-api/src/main/resources/application.properties +++ b/backend/servers/explorer-api/src/main/resources/application.properties @@ -5,7 +5,7 @@ # ====================================================================================================================== # Database access configuration. spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver -spring.datasource.url=jdbc:hsqldb:mem:cassandre-database;DB_CLOSE_DELAY=-1 +spring.datasource.url=jdbc:hsqldb:mem:explorer-royllo-database spring.datasource.username=sa spring.datasource.password= # diff --git a/backend/servers/explorer-batch/src/main/resources/application.properties b/backend/servers/explorer-batch/src/main/resources/application.properties index e1ee0aff9..59f6718ff 100644 --- a/backend/servers/explorer-batch/src/main/resources/application.properties +++ b/backend/servers/explorer-batch/src/main/resources/application.properties @@ -5,7 +5,7 @@ # ====================================================================================================================== # Database access configuration. spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver -spring.datasource.url=jdbc:hsqldb:mem:cassandre-database;DB_CLOSE_DELAY=-1 +spring.datasource.url=jdbc:hsqldb:mem:explorer-royllo-database spring.datasource.username=sa spring.datasource.password= # diff --git a/backend/servers/explorer-web/pom.xml b/backend/servers/explorer-web/pom.xml index bebc5a989..6f2335c56 100644 --- a/backend/servers/explorer-web/pom.xml +++ b/backend/servers/explorer-web/pom.xml @@ -34,6 +34,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.session + spring-session-jdbc + org.springframework.boot spring-boot-starter-security diff --git a/backend/servers/explorer-web/src/main/java/org/royllo/explorer/web/configuration/SecurityConfiguration.java b/backend/servers/explorer-web/src/main/java/org/royllo/explorer/web/configuration/SecurityConfiguration.java index e8f1b74c2..036963d20 100644 --- a/backend/servers/explorer-web/src/main/java/org/royllo/explorer/web/configuration/SecurityConfiguration.java +++ b/backend/servers/explorer-web/src/main/java/org/royllo/explorer/web/configuration/SecurityConfiguration.java @@ -23,10 +23,13 @@ public class SecurityConfiguration { @Bean public UserDetailsService userDetailsService() { + // The primary purpose of the UserDetailsService is to load user-specific data. + // It is used by the AuthenticationManager to authenticate a user during the login process. + // When a username and password are submitted (e.g., via a login form), Spring Security's AuthenticationManager + // uses the UserDetailsService to load the user details. InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); - manager.createUser(User.withDefaultPasswordEncoder() - .username("user") - .password("password") + manager.createUser(User.withUsername("user") + .password("{bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG") .roles("USER") .build()); return manager; @@ -34,15 +37,16 @@ public UserDetailsService userDetailsService() { @Bean public SecurityFilterChain filterChain(final HttpSecurity http) throws Exception { + // Each request that comes in passes through this chain of filters before reaching your application. http.csrf(AbstractHttpConfigurer::disable) - .authorizeHttpRequests((authorize) -> authorize - .anyRequest().permitAll() - ); + .cors(AbstractHttpConfigurer::disable) + // No authentication required for the public website. + .authorizeHttpRequests((authorize) -> authorize.anyRequest().permitAll()); return http.build(); } /** - * K1 manager. + * K1 manager. "k1" refers to a one-time, randomly generated key or token. * * @return k1 manager */ diff --git a/backend/servers/explorer-web/src/main/resources/application-dev.properties b/backend/servers/explorer-web/src/main/resources/application-dev.properties index acbdd4ef3..01ac2a0bc 100644 --- a/backend/servers/explorer-web/src/main/resources/application-dev.properties +++ b/backend/servers/explorer-web/src/main/resources/application-dev.properties @@ -9,6 +9,11 @@ royllo.explorer.content.base-url=http://localhost:9093 royllo.explorer.analytics.piwik.trackingId= # # ====================================================================================================================== +# Session configuration +spring.session.store-type=jdbc +spring.session.jdbc.initialize-schema=always +# +# ====================================================================================================================== # Using Liquibase to import test data spring.liquibase.enabled=true spring.liquibase.change-log=db/dev/db.dev-data.yaml @@ -16,4 +21,12 @@ spring.liquibase.change-log=db/dev/db.dev-data.yaml # ====================================================================================================================== # Disable cache during local dev spring.thymeleaf.cache=false -spring.web.resources.chain.cache=false \ No newline at end of file +spring.web.resources.chain.cache=false +# +# Enable SQL logging +#spring.jpa.show-sql=true +# Set logging level for Spring Session JDBC +#logging.level.org.springframework.session.jdbc=DEBUG +# If you want to see the SQL statements in the console +#logging.level.org.springframework.jdbc.core.JdbcTemplate=DEBUG +#logging.level.org.hibernate.SQL=DEBUG diff --git a/backend/servers/explorer-web/src/main/resources/application.properties b/backend/servers/explorer-web/src/main/resources/application.properties index 2fc4b846e..5f840be8f 100644 --- a/backend/servers/explorer-web/src/main/resources/application.properties +++ b/backend/servers/explorer-web/src/main/resources/application.properties @@ -15,7 +15,7 @@ royllo.explorer.analytics.piwik.trackingId=00000000-0000-0000-0000-000000000000 # ====================================================================================================================== # Database access configuration. spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver -spring.datasource.url=jdbc:hsqldb:mem:cassandre-database;DB_CLOSE_DELAY=-1 +spring.datasource.url=jdbc:hsqldb:mem:explorer-royllo-database spring.datasource.username=sa spring.datasource.password= # @@ -27,6 +27,11 @@ s3.bucket-name=royllo-explorer-s3-asset-bucket s3.endpoint-url=https://s3.amazonaws.com # # ====================================================================================================================== +# Session configuration +spring.session.store-type=jdbc +spring.session.jdbc.initialize-schema=always +# +# ====================================================================================================================== # Cache configuration. spring.cache.type=caffeine # diff --git a/backend/servers/explorer-web/src/test/resources/application.properties b/backend/servers/explorer-web/src/test/resources/application.properties index 69abd4f62..4c519a5dc 100644 --- a/backend/servers/explorer-web/src/test/resources/application.properties +++ b/backend/servers/explorer-web/src/test/resources/application.properties @@ -16,7 +16,7 @@ royllo.explorer.analytics.piwik.trackingId= # ====================================================================================================================== # Database access configuration. spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver -spring.datasource.url=jdbc:hsqldb:mem:cassandre-database;DB_CLOSE_DELAY=-1 +spring.datasource.url=jdbc:hsqldb:mem:explorer-royllo-database spring.datasource.username=sa spring.datasource.password= #