source: bus-n-go-pavel-216049/bus-n-go-backend/src/main/kotlin/mk/ukim/finki/busngobackend/config/ApplicationConfig.kt

Last change on this file was baf4cc4, checked in by ppaunovski <paunovskipavel@…>, 3 months ago

split group project and individual project into two separate folders

  • Property mode set to 100644
File size: 1.3 KB
Line 
1package mk.ukim.finki.busngobackend.config
2
3import mk.ukim.finki.busngobackend.encoder
4import mk.ukim.finki.busngobackend.repository.KorisnikRepository
5import org.springframework.context.annotation.Bean
6import org.springframework.context.annotation.Configuration
7import org.springframework.security.authentication.AuthenticationManager
8import org.springframework.security.authentication.AuthenticationProvider
9import org.springframework.security.authentication.dao.DaoAuthenticationProvider
10import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration
11import org.springframework.security.core.userdetails.UserDetailsService
12
13@Configuration
14class ApplicationConfig(
15 private val korisnikRepository: KorisnikRepository,
16) {
17 @Bean
18 fun userDetailsService(): UserDetailsService =
19 UserDetailsService { email ->
20 korisnikRepository.findByEmail(email)
21 }
22
23 @Bean
24 fun authenticationProvider(korisnikRepository: KorisnikRepository): AuthenticationProvider {
25 val provider = DaoAuthenticationProvider()
26 provider.setUserDetailsService(userDetailsService())
27 provider.setPasswordEncoder(encoder())
28 return provider
29 }
30
31 @Bean
32 fun authenticationManager(config: AuthenticationConfiguration): AuthenticationManager = config.authenticationManager
33}
Note: See TracBrowser for help on using the repository browser.