Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. package com.alfsfilmhorna.demo.configs;
  2. /*
  3.  
  4. import org.springframework.context.annotation.Bean;
  5. import org.springframework.context.annotation.Configuration;
  6. import org.springframework.security.config.annotation.web.builders.HttpSecurity;
  7. import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
  8. import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
  9. import org.springframework.security.core.userdetails.User;
  10. import org.springframework.security.core.userdetails.UserDetailsService;
  11. import org.springframework.security.provisioning.InMemoryUserDetailsManager;
  12. import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
  13.  
  14. @Configuration
  15. @EnableWebSecurity
  16. public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
  17.  
  18.  
  19.  
  20. @Override
  21. protected void configure(HttpSecurity http) throws Exception {
  22. http
  23. .formLogin()
  24. .loginPage("/login")
  25. .failureUrl("/login?error")
  26. .permitAll()
  27. .defaultSuccessUrl("/home")
  28. .and()
  29. .logout()
  30. .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
  31. .logoutSuccessUrl("/")
  32. .permitAll()
  33. .and()
  34. .authorizeRequests()
  35. //.antMatchers("/").permitAll()
  36. //.antMatchers("/admin/**").hasRole("ADMIN")
  37. .antMatchers( "/css/**").permitAll()
  38. .antMatchers("/**").authenticated()
  39. .and()
  40. .csrf().disable();
  41. }
  42.  
  43. @Bean
  44. protected UserDetailsService userDetails() {
  45. User.UserBuilder builder =
  46. User.withDefaultPasswordEncoder();
  47. InMemoryUserDetailsManager manager =
  48. new InMemoryUserDetailsManager();
  49. manager.createUser(
  50. builder
  51. .username("user")
  52. .password("password")
  53. .roles("USER")
  54. .build());
  55. // manager.createUser(
  56. // builder
  57. // .username("admin")
  58. // .password("password")
  59. // .roles("USER", "ADMIN")
  60. // .build());
  61. return manager;
  62.  
  63. }
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97. */
  98. /*@Override
  99. protected void configure(HttpSecurity http) throws Exception {
  100. http
  101. .authorizeRequests()
  102. .antMatchers( "/css/**").permitAll()
  103. .anyRequest().authenticated()
  104. .and()
  105. .formLogin()
  106. .loginPage("/login")
  107. .defaultSuccessUrl("/index")
  108. .permitAll()
  109. .and()
  110. .logout()
  111. .permitAll()
  112. .and().csrf().disable();
  113. }
  114.  
  115. @Autowired
  116. public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
  117. auth
  118. .inMemoryAuthentication()
  119. .withUser("user").password("pass").roles("USER");
  120.  
  121. }*//*
  122.  
  123. }
  124. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement