foundation.cmo.api.mls.graphql.security.MUserSecurityConfig Maven / Gradle / Ivy
package foundation.cmo.api.mls.graphql.security;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import foundation.cmo.api.mls.graphql.security.services.IMUserService;
import lombok.RequiredArgsConstructor;
@Configuration
@RequiredArgsConstructor
public class MUserSecurityConfig {
@Autowired(required = false)
private IMUserService userService;
@Bean
UserDetailsService getUserDetailsService() {
return userService::getUserFromUsername;
}
@Bean
AuthenticationProvider getAuthenticationProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(getUserDetailsService());
authProvider.setPasswordEncoder(getPasswordEncoder());
return authProvider;
}
@Bean
AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) throws Exception {
return configuration.getAuthenticationManager();
}
@Bean
PasswordEncoder getPasswordEncoder() {
return new BCryptPasswordEncoder();
}
}