Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://gist.github.com/sazzadislam-dsi/edb8a0663107d3c7726065a27d0ceb9a
- @Configuration
- @EnableNeo4jRepositories(basePackages = arrayOf("com.lynas.repo"))
- @EnableTransactionManagement
- open class DBConfig(environment: Environment) : Neo4jConfiguration() {
- val neo4jDB_URL: String = environment.getProperty("db.local.url")
- @Bean
- override fun getSessionFactory() = SessionFactory(getConfiguration(), "com.lynas.model")
- @Bean
- open fun getConfiguration() = org.neo4j.ogm.config.Configuration().apply {
- driverConfiguration()
- .setDriverClassName("org.neo4j.ogm.drivers.bolt.driver.BoltDriver")
- .setConnectionPoolSize(150)
- .uri = "bolt://neo4j:123456@localhost:7687"
- }
- }
- @Configuration
- @EnableWebSecurity
- @EnableGlobalMethodSecurity(prePostEnabled = true)
- @ComponentScan(basePackageClasses = arrayOf(UserDetailService::class))
- open class SecurityConfig (val userDetailService:UserDetailsService) : WebSecurityConfigurerAdapter(){
- @Autowired
- fun configureGlobal(auth:AuthenticationManagerBuilder) {
- auth.userDetailsService(userDetailService).passwordEncoder(BCryptPasswordEncoder())
- }
- override fun configure(http: HttpSecurity) {
- http.authorizeRequests().antMatchers("/signup").permitAll()
- .and()
- .authorizeRequests().anyRequest().authenticated()
- .and()
- .formLogin().loginPage("/login").permitAll()
- .and()
- .logout().permitAll()
- }
- }
- @Service("userDetailsService")
- class UserDetailService(var appUserService: AppUserService) : UserDetailsService {
- override fun loadUserByUsername(userName: String): UserDetails {
- // todo need to fix to get in from db
- val appUser:AppUser? = appUserService.findById(48)
- /*val appUser: AppUser? = AppUser().apply {
- username = userName
- password = "$2a$10$3mUSOw6gya8AeNnzL7qiaO2p9qeko.rWVpRpRdZQ4SoICglyGQVHa"
- authorities = "ROLE_USER, ROLE_ADMIN"
- }*/
- if (null == appUser) {
- throw UsernameNotFoundException(String.format("No user found with username '%s'" + userName))
- } else {
- return SpringSecurityUser(
- appUser.id,
- appUser.username,
- appUser.password,
- null,
- null,
- AuthorityUtils.commaSeparatedStringToAuthorityList(appUser.authorities)
- )
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement