我有spring引导代码来验证数据库的使用。它生成x-auth令牌或会话。外部redis服务器正在管理会话,我将如何将用户信息放入会话中,以便其他用户无法修改他们将被交叉检查的会话所属的任何其他用户的数据。
下面是代码片段:

public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    JdbcTemplate jdbcTemplate;

    @Override
    protected void configure(AuthenticationManagerBuilder builder) throws Exception {
          builder.jdbcAuthentication().dataSource(jdbcTemplate.getDataSource())
        .usersByUsernameQuery(
            "select username,password, enabled from users where username=?")
        .authoritiesByUsernameQuery(
            "select username, role from user_roles where username=?");

    }

另外,我想将登录限制为仅一个web服务,它将生成x-auth令牌,其他web服务将被禁用以生成令牌。

最佳答案

因为你用的是redis。假设用户有一个id(user.id=toto12)
您应该在服务器端而不是客户端执行用户的检查。
检查服务器端的进程:
1。检查auth jdbctemplate,
然后,让用户登录并与尝试登录redis的用户进行比较。如果为空,则在redis中创建一个新记录[例如auth:users:tototo12=sessionid]。
如果所有这些测试都有效,则假设用户有权登录,则返回令牌。

10-01 02:38
查看更多