Cześć,
Mam logowanie i Spring Security oparte na DaoAuthenticationProvider, ale nie wiem jak można to zaprząc do zapewnienia dostępu do danego wpisu tylko jego autorowi. W encji Wpis jest pole Autor, w tabeli jest wpisywane id tegoż autora. Ktoś może kojarzy temat?
Obecna klasa:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
DataSourceConfig dataSource;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.authorizeRequests()
.antMatchers("/resources/**").permitAll()
.antMatchers("/wpis/**").permitAll()
.antMatchers("/").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/user/login")
.permitAll()
.and()
.headers()
.frameOptions().disable()
.and()
.logout()
.permitAll();
}
@Autowired
private CustomUserDetailsService userDetailsService;
@Bean
public DaoAuthenticationProvider authProvider() {
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider();
authProvider.setUserDetailsService(userDetailsService);
authProvider.setPasswordEncoder(passwordEncoder());
return authProvider;
}
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authProvider());
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}