Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.swordcode.webcore.security.server; import com.swordcode.webcore.security.server.dao.SecurityRepositories; import com.swordcode.webcore.security.server.dao.UserDetailsServiceImpl; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; /** * * @author euclidesflores */ @Configuration @Import({ SecurityRepositories.class }) public class SecurityConfig { // @Autowired // private SecurityRepositories _repositories; private AuthenticationManager _authenticationManager; @Bean public SecurityService getSecurityService() { return new SecurityService(this); } @Bean public SecurityRepositories getRepositories() { // return _repositories; return new SecurityRepositories(); } public AuthenticationManager getAuthenticationManager() { return _authenticationManager; } void setAuthenticationManager(AuthenticationManager mgr) { // Setting AuthenticationManager _authenticationManager = mgr; } @Bean public PasswordEncoder passwordEncoder() { return new BCryptPasswordEncoder(); } @Bean public AuthenticationProvider authenticationProvider() { DaoAuthenticationProvider ap = new DaoAuthenticationProvider(); ap.setUserDetailsService(userDetailsService()); ap.setPasswordEncoder(passwordEncoder()); return ap; } @Bean public UserDetailsService userDetailsService() { return new UserDetailsServiceImpl(getRepositories()); } }