All Downloads are FREE. Search and download functionalities are using the official Maven repository.

foundation.cmo.api.mls.graphql.security.MUserSecurityConfig Maven / Gradle / Ivy

There is a newer version: 1.0.21
Show newest version
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();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy