【发布时间】:2018-10-04 12:05:21
【问题描述】:
我有一个 curl 类型的 url,
curl -i -X GET -H Accept:application/json http://localhost:8080/onyxcxm/admin/getDTMF/2
当我点击 url 并得到响应时,
HTTP/1.1 302
X-Content-Type-Options: nosniff
X-XSS-保护:1;模式=阻止
Cache-Control: no-cache, no-store, max-age=0,
must-revalidate Pragma: no-cache
过期:0 X-Frame-选项:SAMEORIGIN
位置:http://localhost:8080/onyxcxm/login
内容长度:0
日期:格林威治标准时间 2018 年 10 月 4 日星期四 11:36:48
这里是我的控制器,
@RequestMapping(value="/getDTMF/{dtmf}",headers = "Accept=application/json")
@ResponseBody
public ResponseEntity<String> getDTMF(@PathVariable("dtmf") String dtmf) {
System.err.println("Pressed digit is "+dtmf);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json; charset=utf-8");
return new ResponseEntity<String>(null, headers, HttpStatus.OK);
}
我的安全配置是,
protected void configure(HttpSecurity http) throws Exception {
http
.headers().addHeaderWriter(
new XFrameOptionsHeaderWriter(
XFrameOptionsHeaderWriter.XFrameOptionsMode.SAMEORIGIN))
.and()
.authorizeRequests()
.antMatchers("/admin/**").access("hasRole('ADMIN')")
.antMatchers("/user/**").access("hasRole('USER')")
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/j_spring_security_check")
.successHandler(authenticationSuccessHandler())
.failureUrl("/login?error")
.usernameParameter("username")
.passwordParameter("password")
.and()
.logout()
.logoutUrl("/j_spring_security_logout")
.logoutSuccessHandler(logoutSuccessHandler())
.logoutSuccessUrl("/login?logout")
.invalidateHttpSession(true)
.and()
.csrf().disable();
}
我不认为我为什么会收到此错误,任何人都可以解决它吗?谢谢。
【问题讨论】:
-
因为您没有经过身份验证。您将被重定向到登录页面。
-
那么我如何在这里验证它并感谢快速回复。
-
启用基本身份验证并使用 curl 发送基本身份验证标头...或禁用安全性。
-
但是亲爱的,当我已经通过 BCryptPasswordEncoder 加密密码时,如何启用基本身份验证。如果您有任何示例,可以与我分享。谢谢
-
http.httpBasic().and().<what you had>。类似的东西...
标签: java spring spring-mvc curl