Spring Security configuration

In Chapter 2Deep Diving into Spring Security (in the Spring Security setup sub-section of the Sample application section), we saw basic authentication, which we configured in our configure method in the Spring Security Configuration class. In this example, we will create a custom login page and change the login mechanism to form-based. Open the SpringSecurityConfig class and change the configure method, as shown in the following code snippet. Then, add the tokenRepository bean that we are going to use to accomplish remember me functionality:

@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests().anyRequest().hasAnyRole("ADMIN", "USER")
.and()
.authorizeRequests().antMatchers("/login**").permitAll()
.and()
.formLogin()
.loginPage("/login").loginProcessingUrl("/loginProc").permitAll()
.and()
.logout().logoutSuccessUrl("/login").permitAll()
.and()
.rememberMe()
.rememberMeParameter("rememberme").tokenRepository(tokenRepository());
}
@Bean
public PersistentTokenRepository tokenRepository() {
JdbcTokenRepositoryImpl jdbcTokenRepositoryImpl=new JdbcTokenRepositoryImpl();
jdbcTokenRepositoryImpl.setDataSource(dataSource);
return jdbcTokenRepositoryImpl;
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.106.212