Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Configuration
- @EnableWebSecurity
- public class MainSecurityConfig extends WebSecurityConfigurerAdapter {
- @Resource
- private UserDetailsServiceImpl userDetailsService;
- @Bean
- public HttpSessionEventPublisher httpSessionEventPublisher() {
- return new HttpSessionEventPublisher();
- }
- @Bean
- public PasswordEncoder passwordEncoder() {
- return new BCryptPasswordEncoder();
- }
- @Override
- protected void configure(HttpSecurity http) throws Exception {
- http
- .csrf().disable();
- http
- .authorizeRequests()
- .antMatchers("/", "/**", "/login/**", "/index.html", "/login.html", "/components/**", "/css/**", "/js/**", "/fonts/**", "/images/**", "/.sass-cache/**", "/services.html").permitAll()
- .anyRequest().authenticated();
- http.formLogin()
- .loginPage("/login")
- .failureForwardUrl("/login.html")
- .usernameParameter("user")
- .passwordParameter("password");
- }
- @Override
- protected void configure(AuthenticationManagerBuilder auth) throws Exception {
- auth.authenticationProvider(authenticationProvider());
- }
- @Bean
- public DaoAuthenticationProvider authenticationProvider() {
- DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
- authProvider.setUserDetailsService(userDetailsService);
- authProvider.setPasswordEncoder(passwordEncoder());
- return authProvider;
- }
- @Service
- public class UserDetailsServiceImpl implements UserDetailsService {
- @Resource
- private HttpSession httpSession;
- @Resource
- private UserDao userDao;
- @Override
- public UserDetails loadUserByUsername(String user) throws UsernameNotFoundException {
- User userByEmail = userDao.findUserByEmail(user);
- UserDetailsImpl userDetails = new UserDetailsImpl(userByEmail, httpSession.getId());
- return userDetails;
- }
- }
- $scope.loginUser = function () {
- $scope.user.user = $scope.email;
- $scope.user.password = $scope.password;
- $http.get("/login", { params: {username: $scope.user.user, password: $scope.user.password}});
Add Comment
Please, Sign In to add comment