Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExchangeFilterFunctions.basicAuthentication use error [SPR-16955] #21493

Closed
spring-issuemaster opened this issue Jun 18, 2018 · 5 comments
Closed
Assignees

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Jun 18, 2018

cafebaby opened SPR-16955 and commented

I use the requestFilter in WebClient and use the ExchangeFilterFunctions.basicAuthentication to perform basic authentication as described in the documentation. I use Spring Security's httbasic() to do server security authentication, but the result is still 401 authentication failure.

 

my code:

WebClient client = WebClient.builder().baseUrl("http://localhost:8081")

.filter(ExchangeFilterFunctions.basicAuthentication("admin", "admin")).build();

Mono<String> result = client.post().uri("/upload")

.syncBody(parts).retrieve()

.onStatus(HttpStatus::is4xxClientError,

response -> Mono

.create(x -> x.success(new Exception("error code:" + response.statusCode().value() + ""))))

.bodyToMono(String.class);


Reference URL: https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#webflux-http2

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 20, 2018

Rossen Stoyanchev commented

Some questions that might be easy to verify in your setup.. Does the same server and endpoint (POST /upload) work when using some other client (e.g. RestTemplate or with "curl --user admin:admin")? If so, is the Authentication header different?  

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 20, 2018

cafebaby commented

I used "curl --url http://localhost:8081/upload --user admin:admin" to successfully authenticate and get results

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 22, 2018

cafebaby commented

hi Stoyanchev,when I used 'get' request ,can success pass basic,but 'post' not,
I look at the header information at the time of the request.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 27, 2018

Rossen Stoyanchev commented

I am unable to reproduce the issue. In my sample it works for GET and POST.

when I used 'get' request ,can success pass basic,but 'post' not

That confirms the Authorization header is sent correctly, but for some reason the server rejects HTTP POST. Check your Spring Security confirmation for anything that might explain this. Whatever the issue may be, it is unlikely to have anything to do with the WebClient since all it has to do is insert one header, which is trivial, and is verified by tests.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Jun 27, 2018

cafebaby commented

ok . Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.