|
8 | 8 | import org.springframework.context.annotation.Bean; |
9 | 9 | import org.springframework.data.web.config.EnableSpringDataWebSupport; |
10 | 10 | import org.springframework.data.web.config.EnableSpringDataWebSupport.PageSerializationMode; |
| 11 | +import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
| 12 | +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
| 13 | +import org.springframework.security.core.userdetails.User; |
| 14 | +import org.springframework.security.core.userdetails.UserDetails; |
| 15 | +import org.springframework.security.core.userdetails.UserDetailsService; |
| 16 | +import org.springframework.security.provisioning.InMemoryUserDetailsManager; |
| 17 | +import org.springframework.security.web.SecurityFilterChain; |
| 18 | +import org.springframework.security.web.csrf.CookieCsrfTokenRepository; |
| 19 | +import org.springframework.security.web.csrf.CsrfTokenRequestAttributeHandler; |
11 | 20 | import org.springframework.transaction.support.TransactionTemplate; |
12 | 21 | import org.sterl.spring.persistent_tasks.EnableSpringPersistentTasks; |
13 | 22 | import org.sterl.spring.persistent_tasks.scheduler.SchedulerService; |
|
16 | 25 | import org.sterl.spring.persistent_tasks.trigger.TriggerService; |
17 | 26 | import org.sterl.spring.persistent_tasks_ui.EnableSpringPersistentTasksUI; |
18 | 27 |
|
| 28 | +@EnableWebSecurity |
19 | 29 | @SpringBootApplication |
20 | 30 | @EnableSpringPersistentTasks |
21 | 31 | @EnableSpringPersistentTasksUI |
@@ -53,4 +63,25 @@ SchedulerService schedulerB( |
53 | 63 | return new SchedulerService("schedulerB", triggerService, |
54 | 64 | new TaskExecutorComponent(triggerService, 7), editSchedulerStatus, trx); |
55 | 65 | } |
| 66 | + |
| 67 | + @Bean |
| 68 | + SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { |
| 69 | + http |
| 70 | + .httpBasic(org.springframework.security.config.Customizer.withDefaults()) |
| 71 | + .csrf(c -> |
| 72 | + c.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse()) |
| 73 | + .csrfTokenRequestHandler(new CsrfTokenRequestAttributeHandler()) |
| 74 | + ); |
| 75 | + return http.build(); |
| 76 | + } |
| 77 | + |
| 78 | + @Bean |
| 79 | + UserDetailsService users() { |
| 80 | + UserDetails admin = User.builder() |
| 81 | + .username("admin") |
| 82 | + .password("admin") |
| 83 | + .roles("ADMIN") |
| 84 | + .build(); |
| 85 | + return new InMemoryUserDetailsManager(admin); |
| 86 | + } |
56 | 87 | } |
0 commit comments