Advertisement
Guest User

Untitled

a guest
Nov 30th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. https://gist.github.com/sazzadislam-dsi/edb8a0663107d3c7726065a27d0ceb9a
  2.  
  3. @Configuration
  4. @EnableNeo4jRepositories(basePackages = arrayOf("com.lynas.repo"))
  5. @EnableTransactionManagement
  6. open class DBConfig(environment: Environment) : Neo4jConfiguration() {
  7. val neo4jDB_URL: String = environment.getProperty("db.local.url")
  8.  
  9. @Bean
  10. override fun getSessionFactory() = SessionFactory(getConfiguration(), "com.lynas.model")
  11.  
  12. @Bean
  13. open fun getConfiguration() = org.neo4j.ogm.config.Configuration().apply {
  14. driverConfiguration()
  15. .setDriverClassName("org.neo4j.ogm.drivers.bolt.driver.BoltDriver")
  16. .setConnectionPoolSize(150)
  17. .uri = "bolt://neo4j:123456@localhost:7687"
  18. }
  19. }
  20.  
  21. @Configuration
  22. @EnableWebSecurity
  23. @EnableGlobalMethodSecurity(prePostEnabled = true)
  24. @ComponentScan(basePackageClasses = arrayOf(UserDetailService::class))
  25. open class SecurityConfig (val userDetailService:UserDetailsService) : WebSecurityConfigurerAdapter(){
  26.  
  27. @Autowired
  28. fun configureGlobal(auth:AuthenticationManagerBuilder) {
  29. auth.userDetailsService(userDetailService).passwordEncoder(BCryptPasswordEncoder())
  30. }
  31.  
  32. override fun configure(http: HttpSecurity) {
  33. http.authorizeRequests().antMatchers("/signup").permitAll()
  34. .and()
  35. .authorizeRequests().anyRequest().authenticated()
  36. .and()
  37. .formLogin().loginPage("/login").permitAll()
  38. .and()
  39. .logout().permitAll()
  40. }
  41. }
  42.  
  43.  
  44.  
  45. @Service("userDetailsService")
  46. class UserDetailService(var appUserService: AppUserService) : UserDetailsService {
  47.  
  48.  
  49. override fun loadUserByUsername(userName: String): UserDetails {
  50. // todo need to fix to get in from db
  51. val appUser:AppUser? = appUserService.findById(48)
  52.  
  53. /*val appUser: AppUser? = AppUser().apply {
  54. username = userName
  55. password = "$2a$10$3mUSOw6gya8AeNnzL7qiaO2p9qeko.rWVpRpRdZQ4SoICglyGQVHa"
  56. authorities = "ROLE_USER, ROLE_ADMIN"
  57. }*/
  58.  
  59. if (null == appUser) {
  60. throw UsernameNotFoundException(String.format("No user found with username '%s'" + userName))
  61. } else {
  62. return SpringSecurityUser(
  63. appUser.id,
  64. appUser.username,
  65. appUser.password,
  66. null,
  67. null,
  68. AuthorityUtils.commaSeparatedStringToAuthorityList(appUser.authorities)
  69. )
  70. }
  71.  
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement