Java Code Examples for org.springframework.security.provisioning.JdbcUserDetailsManager#setDataSource()

The following examples show how to use org.springframework.security.provisioning.JdbcUserDetailsManager#setDataSource() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiHttpSecurityConfig.java    From enhanced-pet-clinic with Apache License 2.0 6 votes vote down vote up
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
	//@formatter:off
	String authoritiesByUsernameQuery = "select username, authority from user_authorities " +
			"inner join users on user_authorities.user_id = users.id " +
			"inner join authorities on user_authorities.authority_id = authorities.id " +
			"where username = ?";

	JdbcUserDetailsManager userDetailsService = new JdbcUserDetailsManager();
	userDetailsService.setDataSource(dataSource);
	userDetailsService.setAuthoritiesByUsernameQuery(authoritiesByUsernameQuery);
	PasswordEncoder passwordEncoder = new BCryptPasswordEncoder();

	auth
		.userDetailsService(userDetailsService)
			.passwordEncoder(passwordEncoder)
		.and()
			.jdbcAuthentication()
				.authoritiesByUsernameQuery(authoritiesByUsernameQuery)
				.passwordEncoder(passwordEncoder)
				.dataSource(dataSource)
	;
	//@formatter:on
}
 
Example 2
Source File: MultiHttpSecurityConfig.java    From enhanced-pet-clinic with Apache License 2.0 5 votes vote down vote up
@Bean
public RememberMeServices getRememberMeServices() {
	JdbcUserDetailsManager jdbcUserDetailsManager = new JdbcUserDetailsManager();
	jdbcUserDetailsManager.setDataSource(dataSource);

	JdbcTokenRepositoryImpl jdbcTokenRepositoryImpl = new JdbcTokenRepositoryImpl();
	jdbcTokenRepositoryImpl.setDataSource(dataSource);

	PersistentTokenBasedRememberMeServices services = new PersistentTokenBasedRememberMeServices(
			rememberMeToken, jdbcUserDetailsManager, jdbcTokenRepositoryImpl);
	services.setParameter(rememberMeParameter);
	return services;
}
 
Example 3
Source File: SecurityConfig.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public JdbcUserDetailsManager userDetailsManager() {
    JdbcUserDetailsManager manager = new JdbcUserDetailsManager();
    manager.setDataSource(dataSource);
    return manager;
}
 
Example 4
Source File: WebSecurityConfig.java    From tutorials with MIT License 4 votes vote down vote up
@Bean
public UserDetailsService jdbcUserDetailsService(DataSource dataSource) {
    JdbcUserDetailsManager manager = new JdbcUserDetailsManager();
    manager.setDataSource(dataSource);
    return manager;
}