Java Code Examples for org.springframework.security.provisioning.JdbcUserDetailsManager

The following examples show how to use org.springframework.security.provisioning.JdbcUserDetailsManager. These examples are extracted from open source projects. 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
@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 Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 5 votes vote down vote up
/**
 * The parent method from {@link WebSecurityConfigurerAdapter} (public UserDetailsService userDetailsService())
 * originally returns a {@link UserDetailsService}, but this needs to be a {@link UserDetailsManager}
 * UserDetailsManager vs UserDetailsService
 */
@Bean
@Override
public UserDetailsManager userDetailsService() {
    return new JdbcUserDetailsManager() {{
        setDataSource(dataSource);
        // Override default SQL for JdbcUserDetailsManager
        setGroupAuthoritiesByUsernameQuery(CUSTOM_GROUP_AUTHORITIES_BY_USERNAME_QUERY);
        setUsersByUsernameQuery(CUSTOM_USERS_BY_USERNAME_QUERY);
        setAuthoritiesByUsernameQuery(CUSTOM_AUTHORITIES_BY_USERNAME_QUERY);
        // TODO: This is not available through AuthenticationManagerBuilder
        setCreateUserSql(CUSTOM_CREATE_USER_SQL);
    }};
}
 
Example 3
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 5 votes vote down vote up
/**
 * The parent method from {@link WebSecurityConfigurerAdapter} (public UserDetailsService userDetailsService())
 * originally returns a {@link UserDetailsService}, but this needs to be a {@link UserDetailsManager}
 * UserDetailsManager vs UserDetailsService
 */
@Bean
@Override
public UserDetailsManager userDetailsService() {
    return new JdbcUserDetailsManager() {{
        setDataSource(dataSource);
    }};
}
 
Example 4
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 5 votes vote down vote up
/**
 * The parent method from {@link WebSecurityConfigurerAdapter} (public UserDetailsService userDetailsService())
 * originally returns a {@link UserDetailsService}, but this needs to be a {@link UserDetailsManager}
 * UserDetailsManager vs UserDetailsService
 */
@Bean
@Override
public UserDetailsManager userDetailsService() {
    return new JdbcUserDetailsManager() {{
        setDataSource(dataSource);
        // Override default SQL for JdbcUserDetailsManager
        setGroupAuthoritiesByUsernameQuery(CUSTOM_GROUP_AUTHORITIES_BY_USERNAME_QUERY);
        setUsersByUsernameQuery(CUSTOM_USERS_BY_USERNAME_QUERY);
        setAuthoritiesByUsernameQuery(CUSTOM_AUTHORITIES_BY_USERNAME_QUERY);
        // TODO: This is not available through AuthenticationManagerBuilder
        setCreateUserSql(CUSTOM_CREATE_USER_SQL);
    }};
}
 
Example 5
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 5 votes vote down vote up
/**
 * The parent method from {@link WebSecurityConfigurerAdapter} (public UserDetailsService userDetailsService())
 * originally returns a {@link UserDetailsService}, but this needs to be a {@link UserDetailsManager}
 * UserDetailsManager vs UserDetailsService
 */
@Bean
@Override
public UserDetailsManager userDetailsService() {
    return new JdbcUserDetailsManager() {{
        setDataSource(dataSource);
        // Override default SQL for JdbcUserDetailsManager
        setGroupAuthoritiesByUsernameQuery(CUSTOM_GROUP_AUTHORITIES_BY_USERNAME_QUERY);
        // TODO: This is not available through AuthenticationManagerBuilder
        setCreateUserSql(CUSTOM_CREATE_USER_SQL);
    }};
}
 
Example 6
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 5 votes vote down vote up
/**
 * The parent method from {@link WebSecurityConfigurerAdapter} (public UserDetailsService userDetailsService())
 * originally returns a {@link UserDetailsService}, but this needs to be a {@link UserDetailsManager}
 * UserDetailsManager vs UserDetailsService
 */
@Bean
@Override
public UserDetailsManager userDetailsService() {
    return new JdbcUserDetailsManager() {{
        setDataSource(dataSource);
        // Override default SQL for JdbcUserDetailsManager
        setGroupAuthoritiesByUsernameQuery(CUSTOM_GROUP_AUTHORITIES_BY_USERNAME_QUERY);
        setUsersByUsernameQuery(CUSTOM_USERS_BY_USERNAME_QUERY);
        setAuthoritiesByUsernameQuery(CUSTOM_AUTHORITIES_BY_USERNAME_QUERY);
        // TODO: This is not available through AuthenticationManagerBuilder
        setCreateUserSql(CUSTOM_CREATE_USER_SQL);
    }};
}
 
Example 7
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 5 votes vote down vote up
/**
 * The parent method from {@link WebSecurityConfigurerAdapter} (public UserDetailsService userDetailsService())
 * originally returns a {@link UserDetailsService}, but this needs to be a {@link UserDetailsManager}
 * UserDetailsManager vs UserDetailsService
 */
@Bean
@Override
public UserDetailsManager userDetailsService() {
    return new JdbcUserDetailsManager() {{
        setDataSource(dataSource);
        // Override default SQL for JdbcUserDetailsManager
        setGroupAuthoritiesByUsernameQuery(CUSTOM_GROUP_AUTHORITIES_BY_USERNAME_QUERY);
        setUsersByUsernameQuery(CUSTOM_USERS_BY_USERNAME_QUERY);
        setAuthoritiesByUsernameQuery(CUSTOM_AUTHORITIES_BY_USERNAME_QUERY);
        // TODO: This is not available through AuthenticationManagerBuilder
        setCreateUserSql(CUSTOM_CREATE_USER_SQL);
    }};
}
 
Example 8
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 5 votes vote down vote up
/**
 * The parent method from {@link WebSecurityConfigurerAdapter} (public UserDetailsService userDetailsService())
 * originally returns a {@link UserDetailsService}, but this needs to be a {@link UserDetailsManager}
 * UserDetailsManager vs UserDetailsService
 */
@Bean
@Override
public UserDetailsManager userDetailsService() {
    return new JdbcUserDetailsManager() {{
        setDataSource(dataSource);
        // Override default SQL for JdbcUserDetailsManager
        setGroupAuthoritiesByUsernameQuery(CUSTOM_GROUP_AUTHORITIES_BY_USERNAME_QUERY);
        setUsersByUsernameQuery(CUSTOM_USERS_BY_USERNAME_QUERY);
        setAuthoritiesByUsernameQuery(CUSTOM_AUTHORITIES_BY_USERNAME_QUERY);
        // TODO: This is not available through AuthenticationManagerBuilder
        setCreateUserSql(CUSTOM_CREATE_USER_SQL);
    }};
}
 
Example 9
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 5 votes vote down vote up
/**
 * The parent method from {@link WebSecurityConfigurerAdapter} (public UserDetailsService userDetailsService())
 * originally returns a {@link UserDetailsService}, but this needs to be a {@link UserDetailsManager}
 * UserDetailsManager vs UserDetailsService
 */
@Bean
@Override
public UserDetailsManager userDetailsService() {
    return new JdbcUserDetailsManager() {{
        setDataSource(dataSource);
        // Override default SQL for JdbcUserDetailsManager
        setGroupAuthoritiesByUsernameQuery(CUSTOM_GROUP_AUTHORITIES_BY_USERNAME_QUERY);
        setUsersByUsernameQuery(CUSTOM_USERS_BY_USERNAME_QUERY);
        setAuthoritiesByUsernameQuery(CUSTOM_AUTHORITIES_BY_USERNAME_QUERY);
        // TODO: This is not available through AuthenticationManagerBuilder
        setCreateUserSql(CUSTOM_CREATE_USER_SQL);
    }};
}
 
Example 10
Source Project: Spring-Security-Third-Edition   Source File: SecurityConfig.java    License: MIT License 5 votes vote down vote up
/**
 * The parent method from {@link WebSecurityConfigurerAdapter} (public UserDetailsService userDetailsService())
 * originally returns a {@link UserDetailsService}, but this needs to be a {@link UserDetailsManager}
 * UserDetailsManager vs UserDetailsService
 */
@Bean
@Override
public UserDetailsManager userDetailsService() {
    return new JdbcUserDetailsManager() {{
        setDataSource(dataSource);
        // Override default SQL for JdbcUserDetailsManager
        setGroupAuthoritiesByUsernameQuery(CUSTOM_GROUP_AUTHORITIES_BY_USERNAME_QUERY);
        setUsersByUsernameQuery(CUSTOM_USERS_BY_USERNAME_QUERY);
        setAuthoritiesByUsernameQuery(CUSTOM_AUTHORITIES_BY_USERNAME_QUERY);
        // TODO: This is not available through AuthenticationManagerBuilder
        setCreateUserSql(CUSTOM_CREATE_USER_SQL);
    }};
}
 
Example 11
@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 12
Source Project: tutorials   Source File: SecurityConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public JdbcUserDetailsManager userDetailsManager() {
    JdbcUserDetailsManager manager = new JdbcUserDetailsManager();
    manager.setDataSource(dataSource);
    return manager;
}
 
Example 13
Source Project: tutorials   Source File: SpringSecurityUserManager.java    License: MIT License 4 votes vote down vote up
public SpringSecurityUserManager(ProcessEngineConfigurationImpl processEngineConfiguration, UserDataManager userDataManager, JdbcUserDetailsManager userManager) {
    super(processEngineConfiguration, userDataManager);
    this.userManager = userManager;
}
 
Example 14
Source Project: tutorials   Source File: SpringSecurityUserManager.java    License: MIT License 4 votes vote down vote up
public void setUserManager(JdbcUserDetailsManager userManager) {
    this.userManager = userManager;
}
 
Example 15
Source Project: tutorials   Source File: SpringSecurityGroupManager.java    License: MIT License 4 votes vote down vote up
public void setUserManager(JdbcUserDetailsManager userManager) {
    this.userManager = userManager;
}
 
Example 16
Source Project: tutorials   Source File: WebSecurityConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public UserDetailsService jdbcUserDetailsService(DataSource dataSource) {
    JdbcUserDetailsManager manager = new JdbcUserDetailsManager();
    manager.setDataSource(dataSource);
    return manager;
}