Skip to content

Commit 805ef55

Browse files
committed
Add Figures to Form Log In Docs
Closes gh-8035
1 parent 3257349 commit 805ef55

16 files changed

+87
-44
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
[[servlet-authentication-authenticationentrypoint]]
22
= Request Credentials with `AuthenticationEntryPoint`
3-
:figures: images/servlet/authentication/architecture
4-
:icondir: images/icons
53

64

75
{security-api-url}org/springframework/security/web/AuthenticationEntryPoint.html[`AuthenticationEntryPoint`] is used to send an HTTP response that requests credentials from a client.
@@ -11,23 +9,6 @@ In these cases, Spring Security does not need to provide an HTTP response that r
119

1210
In other cases, a client will make an unauthenticated request to a resource that they are not authorized to access.
1311
In this case, an implementation of `AuthenticationEntryPoint` is used to request credentials from the client.
14-
The `AuthenticationEntryPoint` implementation might perform a redirect to a log in page, respond with an https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate[WWW-Authenticate] header, etc.
12+
The `AuthenticationEntryPoint` implementation might perform a <<servlet-authentication-form,redirect to a log in page>>, respond with an https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate[WWW-Authenticate] header, etc.
1513

16-
[[servlet-authentication-authenticationentrypoint-example]]
17-
To better understand how `AuthenticationEntryPoint` is used, let's take a look at a concrete example using <<servlet-authentication-form,form based log in>>.
18-
// FIXME: link to form based login
1914

20-
.AuthenticationEntryPoint with Form Log In
21-
image::{figures}/request-credentials.png[]
22-
23-
The figure builds off our <<servlet-securityfilterchain,`SecurityFilterChain`>> diagram.
24-
25-
image:{icondir}/number_1.png[] First, a user makes an unauthenticated request to the resource `/private` for which it is not authorized.
26-
27-
image:{icondir}/number_2.png[] Spring Security's <<servlet-authorization-filtersecurityinterceptor,`FilterSecurityInterceptor`>> indicates that the unauthenticated request is __Denied__ by throwing an `AccessDeniedException`.
28-
29-
image:{icondir}/number_3.png[] Since the user is not authenticated, <<servlet-exceptiontranslationfilter,`ExceptionTranslationFilter`>> initiates __Start Authentication__ and sends a redirect to the log in page with the configured `AuthenticationEntryPoint`.
30-
31-
image:{icondir}/number_4.png[] The browser will then request the log in page that it was redirected to.
32-
33-
image:{icondir}/number_5.png[] Something within the application, must <<servlet-authentication-form-custom,render the log in page>>.

docs/manual/src/docs/asciidoc/_includes/servlet/authentication/unpwd/input/form.adoc renamed to docs/manual/src/docs/asciidoc/_includes/servlet/authentication/unpwd/form.adoc

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,73 @@
11
[[servlet-authentication-form]]
22
= Form Login
3+
:figures: images/servlet/authentication/unpwd
4+
:icondir: images/icons
35

46
Spring Security provides support for username and password being provided through an html form.
57
This section provides details on how form based authentication works within Spring Security.
68
// FIXME: describe authenticationentrypoint, authenticationfailurehandler, authenticationsuccesshandler
79

8-
[[servlet-authentication-form-min]]
9-
== Form Login Configuration
10+
Let's take a look at how form based log in works within Spring Security.
11+
First, we see how the user is redirected to the log in form.
12+
13+
.Redirecting to the Log In Page
14+
image::{figures}/request-credentials.png[]
15+
16+
The figure builds off our <<servlet-securityfilterchain,`SecurityFilterChain`>> diagram.
17+
18+
image:{icondir}/number_1.png[] First, a user makes an unauthenticated request to the resource `/private` for which it is not authorized.
19+
20+
image:{icondir}/number_2.png[] Spring Security's <<servlet-authorization-filtersecurityinterceptor,`FilterSecurityInterceptor`>> indicates that the unauthenticated request is __Denied__ by throwing an `AccessDeniedException`.
21+
22+
image:{icondir}/number_3.png[] Since the user is not authenticated, <<servlet-exceptiontranslationfilter,`ExceptionTranslationFilter`>> initiates __Start Authentication__ and sends a redirect to the log in page with the configured <<servlet-authentication-authenticationentrypoint,`AuthenticationEntryPoint`>>.
23+
In most cases the `AuthenticationEntryPoint` is an instance of {security-api-url}org/springframework/security/web/authentication/LoginUrlAuthenticationEntryPoint.html[`LoginUrlAuthenticationEntryPoint`].
24+
25+
image:{icondir}/number_4.png[] The browser will then request the log in page that it was redirected to.
26+
27+
image:{icondir}/number_5.png[] Something within the application, must <<servlet-authentication-form-custom,render the log in page>>.
28+
29+
[[servlet-authentication-usernamepasswordauthenticationfilter]]
30+
When the username and password are submitted, the `UsernamePasswordAuthenticationFilter` authenticates the username and password.
31+
The `UsernamePasswordAuthenticationFilter` extends <<servlet-authentication-abstractprocessingfilter>>, so this diagram should look pretty similar.
32+
33+
.Authenticating Username and Password
34+
image::{figures}/usernamepasswordauthenticationfilter.png[]
1035

36+
The figure builds off our <<servlet-securityfilterchain,`SecurityFilterChain`>> diagram.
37+
38+
39+
image:{icondir}/number_1.png[] When the user submits their username and password, the `UsernamePasswordAuthenticationFilter` creates a `UsernamePasswordAuthenticationToken` which is a type of <<servlet-authentication-authentication,`Authentication`>> by extracting the username and password from the `HttpServletRequest`.
40+
41+
image:{icondir}/number_2.png[] Next, the `UsernamePasswordAuthenticationToken` is passed into the `AuthenticationManager` to be authenticated.
42+
The details of what `AuthenticationManager` look like depend on how the <<servlet-authentication-unpwd-storage,user information is stored>>.
43+
44+
image:{icondir}/number_3.png[] If authentication fails, then __Failure__
45+
46+
* The <<servlet-authentication-securitycontextholder>> is cleared out.
47+
* `RememberMeServices.loginFail` is invoked.
48+
If remember me is not configured, this is a no-op.
49+
// FIXME: link to rememberme
50+
* `AuthenticationFailureHandler` is invoked.
51+
// FIXME: link to AuthenticationFailureHandler
52+
53+
image:{icondir}/number_4.png[] If authentication is successful, then __Success__.
54+
55+
* `SessionAuthenticationStrategy` is notified of a new log in.
56+
// FIXME: Add link to SessionAuthenticationStrategy
57+
* The <<servlet-authentication-authentication>> is set on the <<servlet-authentication-securitycontextholder>>.
58+
// FIXME: link securitycontextpersistencefilter
59+
* `RememberMeServices.loginSuccess` is invoked.
60+
If remember me is not configured, this is a no-op.
61+
// FIXME: link to rememberme
62+
* `ApplicationEventPublisher` publishes an `InteractiveAuthenticationSuccessEvent`.
63+
* The `AuthenticationSuccessHandler` is invoked. Typically this is a `SimpleUrlAuthenticationSuccessHandler` which will redirect to a request saved by <<servlet-exceptiontranslationfilter,`ExceptionTranslationFilter`>> when we redirect to the log in page.
64+
65+
[[servlet-authentication-form-min]]
1166
Spring Security form log in is enabled by default.
1267
However, as soon as any servlet based configuration is provided, form based log in must be explicitly provided.
1368
A minimal, explicit Java configuration can be found below:
1469

15-
.Form Log
70+
.Form Log In
1671
====
1772
.Java
1873
[source,java,role="primary"]
@@ -49,8 +104,6 @@ In this configuration Spring Security will render a default log in page.
49104
Most production applications will require a custom log in form.
50105

51106
[[servlet-authentication-form-custom]]
52-
== Custom Log In Form
53-
54107
The configuration below demonstrates how to provide a custom log in form.
55108

56109
.Custom Log In Form Configuration

docs/manual/src/docs/asciidoc/_includes/servlet/authentication/unpwd/index.adoc

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,33 @@
22
= Username/Password Authentication
33

44
One of the most common ways to authenticate a user is by validating a username and password.
5-
As such, Spring Security provides comprehensive support for user <<servlet-authentication-unpwd-input,input>> and <<servlet-authentication-unpwd-storage,storage>> of a username and password.
5+
As such, Spring Security provides comprehensive support for authenticating with a username and password.
66

7-
include::input/index.adoc[leveloffset=+1]
7+
[[servlet-authentication-unpwd-input]]
8+
Spring Security provides the following built in mechanisms for reading a username and password from the `HttpServletRequest`:
89

9-
include::storage/index.adoc[leveloffset=+1]
10+
* <<servlet-authentication-form,Form Login>>
11+
* <<servlet-authentication-basic,Basic Authentication>>
12+
* <<servlet-authentication-digest,Digest Authentication>>
13+
14+
[[servlet-authentication-unpwd-storage]]
15+
Each of the supported mechanisms for reading a username and password can leverage any of the supported storage mechanisms:
16+
17+
* Simple Storage with <<servlet-authentication-inmemory>>
18+
* Relational Databases with <<servlet-authentication-jdbc>>
19+
* LDAP Servers with <<servlet-authentication-ldap>>
20+
* Custom data stores with <<servlet-authentication-userdetailsservice>>
21+
22+
include::form.adoc[leveloffset=+1]
23+
24+
include::basic.adoc[leveloffset=+1]
25+
26+
include::digest.adoc[leveloffset=+1]
27+
28+
include::in-memory.adoc[leveloffset=+1]
29+
30+
include::jdbc.adoc[leveloffset=+1]
31+
32+
include::ldap.adoc[leveloffset=+1]
33+
34+
include::user-details-service.adoc[leveloffset=+1]

docs/manual/src/docs/asciidoc/_includes/servlet/authentication/unpwd/input/index.adoc

Lines changed: 0 additions & 16 deletions
This file was deleted.
Loading

0 commit comments

Comments
 (0)