I want to skip the authentication for the /login request.
In my ServerApplication, I wrote this method to achieve it:
@Configuration
@EnableResourceServer
protected class ResourceServer extends ResourceServerConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/login").permitAll();
}
}
But, I'm getting this response now (while trying to hit the /login endpoint, no matter what arguments/headers I pass):
{
"timestamp": 1493881871867,
"status": 415,
"error": "Unsupported Media Type",
"exception": "org.springframework.web.HttpMediaTypeNotSupportedException",
"message": "Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported",
"path": "/login"
}
Tried consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE,
and several other similar solutions, but still getting the same response.
Also created an endpoint for /login, but that's not getting hit:
@RequestMapping(value = "/login",
method = RequestMethod.POST,
produces = "application/json")
public ResponseEntity login(@RequestBody Map<String, String> requestBody) {
System.out.println("DO I EVEN REACH HERE?");
return null;
}
I'm very new to Spring and can't figure out the mistake I'm doing here. Any help?
Error message is;
Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported
Which means you posting to /login
via a html form. but your login
endpoint doesn't accept form params. Change the login
endpoint as follows
@RequestMapping(value = "/login",
method = RequestMethod.POST,
produces = "application/json")
public ResponseEntity login(@RequestParam("username") String username, @RequestParam("password") String password) {
System.out.println("DO I EVEN REACH HERE?");
return null;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.