查询角色报出sql错误,数据库结构和sql语句都没有问题
源码如下:
@Test public void testAuthentication(){ JdbcRealm jdbcRealm=new JdbcRealm(); jdbcRealm.setDataSource(dataSource); jdbcRealm.setPermissionsLookupEnabled(true); String sql="select password from users where user_name=?"; jdbcRealm.setAuthenticationQuery(sql); String roleSql="select role_name from test_user_roles where user_name = ?"; jdbcRealm.setUserRolesQuery(roleSql); DefaultSecurityManager defaultSecurityManager=new DefaultSecurityManager(); defaultSecurityManager.setRealm(jdbcRealm); SecurityUtils.setSecurityManager(defaultSecurityManager); Subject subject= SecurityUtils.getSubject(); UsernamePasswordToken token=new UsernamePasswordToken("Mark","123456"); subject.login(token); System.out.println("isAuthenticated:"+subject.isAuthenticated()); subject.checkRole("user"); }
数据表结构: