README.adoc 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. = X.509 + Form Login MFA Sample
  2. This sample demonstrates configuring Spring Security to require both an X.509 Certificate and a Username/Password Login in order to enter the site with full permissions.
  3. == Preparing to Use X.509
  4. This sample is intended to be used in a browser.
  5. As such, you should:
  6. 1. Configure your browser to trust the `ca.crt` that accompanies this project
  7. 2. Configure your browser with the `josh-keystore.p12` client certificate
  8. Both `api-keystore.p12` and `josh-keystore.p12` use keys signed by `ca.crt`.
  9. This means that after the above steps are performed, you can also use this application without getting a security warning in your browser.
  10. == Using the Sample
  11. To run, please use:
  12. .Java
  13. [source,java,role="primary"]
  14. ----
  15. ./gradlew :bootRun
  16. ----
  17. This will start an application on 8443, meaning you will need to reach it using HTTPS.
  18. You can register a passkey at https://api.127.0.0.1.nip.io:8443/webauthn/register.
  19. With the client certificate (`josh-keystore.p12`) correctly installed in the browser, it will ask you which client certificate you want to you.
  20. Select `josh`.
  21. You will then be redirected to the PassKeys registration page where you can install a passkey.
  22. After that, navigate to https://api.127.0.0.1.nip.io:8443 and you will be redirected to page where you can provide a passkey.
  23. == Exploring the Sample
  24. The key configuration is found in the `HttpSecurity` DSL:
  25. .Java
  26. [source,java,role="primary"]
  27. ----
  28. http
  29. .x509(Customizer.withDefaults())
  30. .webAuthn((webauthn) -> webauthn
  31. // ...
  32. .factor((f) -> f.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/webauthn")))
  33. );
  34. ----
  35. This reads, "This app requires both X.509 and WebAuthn to fully authorize; redirect to /webauthn to get the WebAuthn authority".
  36. You can instead try another arrangement like the following:
  37. .Java
  38. [source,java,role="primary"]
  39. ----
  40. http
  41. .x509(Customizer.withDefaults())
  42. .oneTimeTokenLogin(Customizer.withDefaults())
  43. ----
  44. Once `oneTimeTokenLogin` is correctly configured and once a client certificate is accepted, the application will generate a token and send it to the configured destination to continue with the login process.