0
私が持つテーブルのエージェントがあります。[ID主キー、電子メールのvarchar型、パスワードはvarchar]Spring security4「アクセスが拒否されました」という問題、authoritiesByUsernameQueryが機能しません。
とagents_rolesテーブルを:[agent_role_id主キー、電子メールvarchar型は、外部キーをAGENT_ID]私は
セキュリティコントローラ私はこれを持っている:
@Configuration
@EnableWebSecurity
public class Security extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception
{
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery("select email, password,visibility from agents where email=?")
.authoritiesByUsernameQuery("select email, role from agents_roles where email=?");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin().loginPage("/login");
http.authorizeRequests().antMatchers("/admin/**").hasRole("ADMIN");
http.authorizeRequests().antMatchers("/agent/**").hasRole("DEV");
http.exceptionHandling().accessDeniedPage("/403");
}
}
私はホームページのアクセス拒否されたページを取得し、「403.html」を取得しよう
!私は2番目のクエリ "authoritiesByUsernameQuery"が正しく動作しないと思いますが、私はその理由を知らないのですか?
私はusersのテーブルとusers_roleで他の例を試してみましたが、うまくいきますが、違いはユーザ名がプライマリキーです!!
お願いします。ありがとうございます。