我使用 Spring Security 并将我的教师登录名和教师密码存储在表 teachers
中。
当我只使用 :
@Configuration
@EnableAutoConfiguration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
DataSource dataSource;
@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery("select teacher_login,teacher_password, enabled from teachers where teacher_login=?")
.authoritiesByUsernameQuery("select teacher_login, teacher_role from teachers where teacher_login=?")
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/", "/home").permitAll().antMatchers("/admin").hasRole("TEACHER")
.anyRequest().authenticated().and().formLogin().loginPage("/login").permitAll().and().logout()
.permitAll();
http.exceptionHandling().accessDeniedPage("/403");
}
}
现在一切正常。
但是
我的项目中不仅有老师,还有学生,用于存储数据 - 登录名、学生密码和登录名、教师密码我使用两个表 - teachers
和 students
。
我应该怎么做才能在有人登录时检查学生,而不仅仅是老师?