From 997bb1c116205a1d3e3740e082bd7b1e735de9d5 Mon Sep 17 00:00:00 2001 From: Linus Westling Date: Thu, 23 Apr 2026 17:07:43 +0200 Subject: [PATCH] seeded again.... --- .../infrastructure/config/SecurityConfig.java | 5 ++- src/main/resources/data-local.sql | 42 +++++++++++++++++++ src/main/resources/data.sql | 16 +++++++ 3 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/example/projektarendehantering/infrastructure/config/SecurityConfig.java b/src/main/java/org/example/projektarendehantering/infrastructure/config/SecurityConfig.java index 98185d1..0dcb02b 100644 --- a/src/main/java/org/example/projektarendehantering/infrastructure/config/SecurityConfig.java +++ b/src/main/java/org/example/projektarendehantering/infrastructure/config/SecurityConfig.java @@ -7,7 +7,7 @@ import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.factory.PasswordEncoderFactories; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.HttpStatusEntryPoint; @@ -72,6 +72,7 @@ public UserDetailsService userDetailsService() { @Bean public PasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); + // Supports both encoded passwords (e.g. {bcrypt}) and explicit dev-only {noop} seeds. + return PasswordEncoderFactories.createDelegatingPasswordEncoder(); } } diff --git a/src/main/resources/data-local.sql b/src/main/resources/data-local.sql index bbbc925..42accfc 100644 --- a/src/main/resources/data-local.sql +++ b/src/main/resources/data-local.sql @@ -10,3 +10,45 @@ VALUES ( NOW() ) ON CONFLICT (email) DO NOTHING; + +-- Local development only: seed patient accounts with visible (unhashed) passwords. +-- Credentials: +-- - john.doe@traumateam.com / patient123 +-- - jane.smith@traumateam.com / patient123 +-- - anders.andersson@traumateam.com / patient123 +-- Note: "{noop}" means "do not hash" in Spring Security. +INSERT INTO user_account (id, email, password_hash, role, provider, enabled, created_at) +VALUES ( + '550e8400-e29b-41d4-a716-446655440000', + 'john.doe@traumateam.com', + '{noop}patient123', + 'PATIENT', + 'LOCAL', + true, + NOW() + ) +ON CONFLICT (email) DO NOTHING; + +INSERT INTO user_account (id, email, password_hash, role, provider, enabled, created_at) +VALUES ( + '550e8400-e29b-41d4-a716-446655440001', + 'jane.smith@traumateam.com', + '{noop}patient123', + 'PATIENT', + 'LOCAL', + true, + NOW() + ) +ON CONFLICT (email) DO NOTHING; + +INSERT INTO user_account (id, email, password_hash, role, provider, enabled, created_at) +VALUES ( + '550e8400-e29b-41d4-a716-446655440002', + 'anders.andersson@traumateam.com', + '{noop}patient123', + 'PATIENT', + 'LOCAL', + true, + NOW() + ) +ON CONFLICT (email) DO NOTHING; diff --git a/src/main/resources/data.sql b/src/main/resources/data.sql index 734607f..7af5114 100644 --- a/src/main/resources/data.sql +++ b/src/main/resources/data.sql @@ -15,6 +15,14 @@ INSERT INTO user_account (id, email, password_hash, role, provider, provider_use VALUES ('120e8400-e29b-41d4-a716-446655440002', 'patient.seed@traumateam.local', NULL, 'PATIENT', 'GITHUB', 'seed-patient-001', true, CURRENT_TIMESTAMP - INTERVAL '40 days') ON CONFLICT (email) DO NOTHING; +INSERT INTO user_account (id, email, password_hash, role, provider, provider_user_id, enabled, created_at) +VALUES ('228023f0-e676-356e-ba78-097cc894cc5a', NULL, NULL, 'MANAGER', 'GITHUB', 'linuswestling', true, CURRENT_TIMESTAMP - INTERVAL '2 days') +ON CONFLICT (id) DO NOTHING; + +INSERT INTO user_account (id, email, password_hash, role, provider, provider_user_id, enabled, created_at) +VALUES ('876a23e4-2207-3e12-b36c-c44e4a50f772', NULL, NULL, 'MANAGER', 'GITHUB', 'mattknatt', true, CURRENT_TIMESTAMP - INTERVAL '2 days') +ON CONFLICT (id) DO NOTHING; + -- ------------------------------------------------------------ -- Patients -- ------------------------------------------------------------ @@ -65,6 +73,14 @@ INSERT INTO employees (id, display_name, github_username, role, created_at) VALUES ('770e8400-e29b-41d4-a716-446655440004', 'Nurse Emma Karlsson', 'emma-karlsson-rn', 'NURSE', CURRENT_TIMESTAMP - INTERVAL '33 days') ON CONFLICT (id) DO NOTHING; +INSERT INTO employees (id, display_name, github_username, role, created_at) +VALUES ('228023f0-e676-356e-ba78-097cc894cc5a', 'Linus Westling', 'linuswestling', 'MANAGER', CURRENT_TIMESTAMP - INTERVAL '2 days') +ON CONFLICT (id) DO NOTHING; + +INSERT INTO employees (id, display_name, github_username, role, created_at) +VALUES ('876a23e4-2207-3e12-b36c-c44e4a50f772', 'Matt Knatt', 'mattknatt', 'MANAGER', CURRENT_TIMESTAMP - INTERVAL '2 days') +ON CONFLICT (id) DO NOTHING; + -- ------------------------------------------------------------ -- Cases -- ------------------------------------------------------------