【发布时间】:2017-02-27 20:04:47
【问题描述】:
我正在尝试在我的项目中实现jdbcAuthentication。问题是当我从browser 发出请求时它可以工作,但是当我从Postman 发出请求时它不起作用,我的意思是身份验证不会发生,甚至随机凭据也可以工作。
但是,如果我使用 inMemoryAuthentication,它对浏览器和 Postman 都适用。这是我在SecurityConfig 中的代码。
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource).usersByUsernameQuery("select username,password, enabled from users where username=?")
.authoritiesByUsernameQuery("select username, role from user_roles where username=?");
// This works --> auth.inMemoryAuthentication().withUser("user").password("pass").roles("USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.authorizeRequests().anyRequest().authenticated().and().httpBasic().and().csrf().disable();
}
在邮递员中,我发出POST 请求。
在Authorization 类型中,我选择基本身份验证并输入凭据,然后将其填充到下面的授权标题中
这些是标题
Content-Type:application/json
X-XSRF-TOKEN:{{X-CSRF-TOKEN}}
Authorization:Basic ajhsjajywshhshshsssss
如果我注释 jdbcAUthentication 部分并取消注释 inMomeryAuthentication 代码,则身份验证适用于浏览器和邮递员。有人可以帮我吗,为什么会这样?我错过了什么吗?谢谢!!
【问题讨论】:
-
请在使用邮递员时提及请求规范(类型、内容等)。
标签: java spring spring-security postman