-
Notifications
You must be signed in to change notification settings - Fork 61
Add support for native htmx redirects in Spring Security #169
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
Conversation
|
Thank you for your contribution. I will look into more detail later, but what I am already missing is an update to the README to explain how to use the classes. I don't know if it would be possible to add some tests as well ? |
...a/io/github/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectAccessDeniedHandler.java
Outdated
Show resolved
Hide resolved
...a/io/github/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectAccessDeniedHandler.java
Outdated
Show resolved
Hide resolved
...github/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectAuthenticationEntryPoint.java
Outdated
Show resolved
Hide resolved
...github/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectAuthenticationEntryPoint.java
Outdated
Show resolved
Hide resolved
...ub/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectAuthenticationSuccessHandler.java
Outdated
Show resolved
Hide resolved
.../io/github/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectLogoutSuccessHandler.java
Outdated
Show resolved
Hide resolved
.../io/github/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectLogoutSuccessHandler.java
Outdated
Show resolved
Hide resolved
...a/io/github/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectAccessDeniedHandler.java
Outdated
Show resolved
Hide resolved
...a/io/github/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectAccessDeniedHandler.java
Outdated
Show resolved
Hide resolved
...github/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectAuthenticationEntryPoint.java
Outdated
Show resolved
Hide resolved
|
Hi @xhaggi |
|
@lcnicolau Could tests be added? |
|
Hi @wimdeblauwe |
|
There is indeed 100% test coverage, but it is mocking everything. I would rather see |
|
Thanks @wimdeblauwe |
|
No, you can remove the mocked tests. |
@wimdeblauwe done. |
...github/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectAuthenticationEntryPoint.java
Outdated
Show resolved
Hide resolved
.../java/io/github/wimdeblauwe/htmx/spring/boot/security/HxLocationBoostedRedirectStrategy.java
Show resolved
Hide resolved
...rc/main/java/io/github/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectStrategy.java
Outdated
Show resolved
Hide resolved
.../io/github/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectLogoutSuccessHandler.java
Outdated
Show resolved
Hide resolved
...ub/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectAuthenticationSuccessHandler.java
Outdated
Show resolved
Hide resolved
.../java/io/github/wimdeblauwe/htmx/spring/boot/security/HxLocationBoostedRedirectStrategy.java
Outdated
Show resolved
Hide resolved
...a/io/github/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectAccessDeniedHandler.java
Outdated
Show resolved
Hide resolved
...ub/wimdeblauwe/htmx/spring/boot/security/HxLocationRedirectAuthenticationFailureHandler.java
Outdated
Show resolved
Hide resolved
...t/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/security/HtmxRedirectPatternTest.java
Outdated
Show resolved
Hide resolved
...est/java/io/github/wimdeblauwe/htmx/spring/boot/security/HtmxBoostedRedirectPatternTest.java
Outdated
Show resolved
Hide resolved
|
@lcnicolau please squash all your commits into the first one. |
6dcd768 to
1d24f3e
Compare
Htmx provides a special way to send a redirect instruction to the client, keeping a success code (200) and sending a custom HTTP header from the server (HX-Location / HX-Redirect). Htmx correctly interprets these headers and follows the redirect, replacing the response in the page body.
You can take advantage of this behavior by integrating the
HxLocationRedirectAuthenticationFailureHandler,HxLocationRedirectAuthenticationSuccessHandler,HxLocationRedirectLogoutSuccessHandler,HxLocationRedirectAuthenticationEntryPointand/orHxLocationRedirectAccessDeniedHandlerinto theSecurityFilterChainbean definition.For detailed information and a usage example, see:
https://github.com/lcnicolau/cs50-todo-list?tab=readme-ov-file#htmx-redirect-pattern