Skip to content

Commit 2fb056b

Browse files
committed
Merge Clean up Reference Documentation
Closes gh-9668
2 parents d884d9a + 252ef78 commit 2fb056b

File tree

105 files changed

+4536
-4225
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+4536
-4225
lines changed

docs/modules/ROOT/pages/features/authentication/index.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ Authentication is how we verify the identity of who is trying to access a partic
66
A common way to authenticate users is by requiring the user to enter a username and password.
77
Once authentication is performed we know the identity and can perform authorization.
88

9-
Spring Security provides built in support for authenticating users.
9+
Spring Security provides built-in support for authenticating users.
1010
This section is dedicated to generic authentication support that applies in both Servlet and WebFlux environments.
11-
Refer to the sections on authentication for xref:servlet/authentication/index.adoc#servlet-authentication[Servlet] and WebFlux for details on what is supported for each stack.
11+
See the sections on authentication for xref:servlet/authentication/index.adoc#servlet-authentication[Servlet] and WebFlux for details on what is supported for each stack.

docs/modules/ROOT/pages/features/authentication/password-storage.adoc

Lines changed: 80 additions & 76 deletions
Large diffs are not rendered by default.

docs/modules/ROOT/pages/features/exploits/csrf.adoc

Lines changed: 79 additions & 78 deletions
Large diffs are not rendered by default.

docs/modules/ROOT/pages/features/exploits/headers.adoc

Lines changed: 81 additions & 92 deletions
Large diffs are not rendered by default.
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
[[http]]
22
= HTTP
33

4-
All HTTP based communication, including https://www.troyhunt.com/heres-why-your-static-website-needs-https/[static resources], should be protected https://cheatsheetseries.owasp.org/cheatsheets/Transport_Layer_Protection_Cheat_Sheet.html[using TLS].
4+
All HTTP-based communication, including https://www.troyhunt.com/heres-why-your-static-website-needs-https/[static resources], should be protected by https://cheatsheetseries.owasp.org/cheatsheets/Transport_Layer_Protection_Cheat_Sheet.html[using TLS].
55

66
As a framework, Spring Security does not handle HTTP connections and thus does not provide support for HTTPS directly.
77
However, it does provide a number of features that help with HTTPS usage.
88

99
[[http-redirect]]
1010
== Redirect to HTTPS
1111

12-
When a client uses HTTP, Spring Security can be configured to redirect to HTTPS both xref:servlet/exploits/http.adoc#servlet-http-redirect[Servlet] and xref:reactive/exploits/http.adoc#webflux-http-redirect[WebFlux] environments.
12+
When a client uses HTTP, you can configure Spring Security to redirect to HTTPS in both xref:servlet/exploits/http.adoc#servlet-http-redirect[Servlet] and xref:reactive/exploits/http.adoc#webflux-http-redirect[WebFlux] environments.
1313

1414
[[http-hsts]]
1515
== Strict Transport Security
@@ -19,14 +19,14 @@ Spring Security provides support for xref:features/exploits/headers.adoc#headers
1919
[[http-proxy-server]]
2020
== Proxy Server Configuration
2121

22-
When using a proxy server it is important to ensure that you have configured your application properly.
23-
For example, many applications will have a load balancer that responds to request for https://example.com/ by forwarding the request to an application server at https://192.168.1:8080.
24-
Without proper configuration, the application server will not know that the load balancer exists and treat the request as though https://192.168.1:8080 was requested by the client.
22+
When using a proxy server, it is important to ensure that you have configured your application properly.
23+
For example, many applications have a load balancer that responds to request for https://example.com/ by forwarding the request to an application server at https://192.168.1:8080
24+
Without proper configuration, the application server can not know that the load balancer exists and treats the request as though https://192.168.1:8080 was requested by the client.
2525

26-
To fix this you can use https://tools.ietf.org/html/rfc7239[RFC 7239] to specify that a load balancer is being used.
27-
To make the application aware of this, you need to either configure your application server aware of the X-Forwarded headers.
28-
For example Tomcat uses the https://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/valves/RemoteIpValve.html[RemoteIpValve] and Jetty uses https://www.eclipse.org/jetty/javadoc/jetty-9/org/eclipse/jetty/server/ForwardedRequestCustomizer.html[ForwardedRequestCustomizer].
29-
Alternatively, Spring users can leverage https://github.com/spring-projects/spring-framework/blob/v4.3.3.RELEASE/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java[ForwardedHeaderFilter].
26+
To fix this, you can use https://tools.ietf.org/html/rfc7239[RFC 7239] to specify that a load balancer is being used.
27+
To make the application aware of this, you need to configure your application server to be aware of the X-Forwarded headers.
28+
For example, Tomcat uses https://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/valves/RemoteIpValve.html[`RemoteIpValve`] and Jetty uses https://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/server/ForwardedRequestCustomizer.html[`ForwardedRequestCustomizer`].
29+
Alternatively, Spring users can use https://github.com/spring-projects/spring-framework/blob/v4.3.3.RELEASE/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java[`ForwardedHeaderFilter`].
3030

31-
Spring Boot users may use the `server.use-forward-headers` property to configure the application.
31+
Spring Boot users can use the `server.use-forward-headers` property to configure the application.
3232
See the https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-use-tomcat-behind-a-proxy-server[Spring Boot documentation] for further details.

docs/modules/ROOT/pages/features/exploits/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
Spring Security provides protection against common exploits.
66
Whenever possible, the protection is enabled by default.
7-
Below you will find high level description of the various exploits that Spring Security protects against.
7+
This section describes the various exploits that Spring Security protects against.

docs/modules/ROOT/pages/features/integrations/cryptography.adoc

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
[[crypto]]
22
= Spring Security Crypto Module
33

4-
54
[[spring-security-crypto-introduction]]
6-
== Introduction
75
The Spring Security Crypto module provides support for symmetric encryption, key generation, and password encoding.
86
The code is distributed as part of the core module but has no dependencies on any other Spring Security (or Spring) code.
97

108

119
[[spring-security-crypto-encryption]]
1210
== Encryptors
13-
The Encryptors class provides factory methods for constructing symmetric encryptors.
14-
Using this class, you can create ByteEncryptors to encrypt data in raw byte[] form.
15-
You can also construct TextEncryptors to encrypt text strings.
11+
The {security-api-url}org/springframework/security/crypto/encrypt/Encryptors.html[`Encryptors`] class provides factory methods for constructing symmetric encryptors.
12+
This class lets you create {security-api-url}org/springframework/security/crypto/encrypt/BytesEncryptor.html[`BytesEncryptor`] instances to encrypt data in raw `byte[]` form.
13+
You can also construct {security-api-url}org/springframework/security/crypto/encrypt/TextEncryptor.html[TextEncryptor] instances to encrypt text strings.
1614
Encryptors are thread-safe.
1715

16+
[NOTE]
17+
====
18+
Both `BytesEncryptor` and `TextEncryptor` are interfaces. `BytesEncryptor` has multiple implementations.
19+
====
20+
1821
[[spring-security-crypto-encryption-bytes]]
1922
=== BytesEncryptor
20-
Use the `Encryptors.stronger` factory method to construct a BytesEncryptor:
23+
You can use the `Encryptors.stronger` factory method to construct a `BytesEncryptor`:
2124

2225
.BytesEncryptor
2326
====
@@ -34,16 +37,16 @@ Encryptors.stronger("password", "salt")
3437
----
3538
====
3639

37-
The "stronger" encryption method creates an encryptor using 256 bit AES encryption with
40+
The `stronger` encryption method creates an encryptor by using 256-bit AES encryption with
3841
Galois Counter Mode (GCM).
39-
It derives the secret key using PKCS #5's PBKDF2 (Password-Based Key Derivation Function #2).
42+
It derives the secret key by using PKCS #5's PBKDF2 (Password-Based Key Derivation Function #2).
4043
This method requires Java 6.
41-
The password used to generate the SecretKey should be kept in a secure place and not be shared.
42-
The salt is used to prevent dictionary attacks against the key in the event your encrypted data is compromised.
43-
A 16-byte random initialization vector is also applied so each encrypted message is unique.
44+
The password used to generate the `SecretKey` should be kept in a secure place and should not be shared.
45+
The salt is used to prevent dictionary attacks against the key in the event that your encrypted data is compromised.
46+
A 16-byte random initialization vector is also applied so that each encrypted message is unique.
4447

4548
The provided salt should be in hex-encoded String form, be random, and be at least 8 bytes in length.
46-
Such a salt may be generated using a KeyGenerator:
49+
You can generate such a salt by using a `KeyGenerator`:
4750

4851
.Generating a key
4952
====
@@ -60,14 +63,14 @@ val salt = KeyGenerators.string().generateKey() // generates a random 8-byte sal
6063
----
6164
====
6265

63-
Users may also use the `standard` encryption method, which is 256-bit AES in Cipher Block Chaining (CBC) Mode.
66+
You can also use the `standard` encryption method, which is 256-bit AES in Cipher Block Chaining (CBC) Mode.
6467
This mode is not https://en.wikipedia.org/wiki/Authenticated_encryption[authenticated] and does not provide any
6568
guarantees about the authenticity of the data.
66-
For a more secure alternative, users should prefer `Encryptors.stronger`.
69+
For a more secure alternative, use `Encryptors.stronger`.
6770

6871
[[spring-security-crypto-encryption-text]]
6972
=== TextEncryptor
70-
Use the Encryptors.text factory method to construct a standard TextEncryptor:
73+
You can use the `Encryptors.text` factory method to construct a standard TextEncryptor:
7174

7275
.TextEncryptor
7376
====
@@ -84,10 +87,10 @@ Encryptors.text("password", "salt")
8487
----
8588
====
8689

87-
A TextEncryptor uses a standard BytesEncryptor to encrypt text data.
88-
Encrypted results are returned as hex-encoded strings for easy storage on the filesystem or in the database.
90+
A `TextEncryptor` uses a standard `BytesEncryptor` to encrypt text data.
91+
Encrypted results are returned as hex-encoded strings for easy storage on the filesystem or in a database.
8992

90-
Use the Encryptors.queryableText factory method to construct a "queryable" TextEncryptor:
93+
You can use the `Encryptors.queryableText` factory method to construct a "`queryable`" `TextEncryptor`:
9194

9295
.Queryable TextEncryptor
9396
====
@@ -104,21 +107,21 @@ Encryptors.queryableText("password", "salt")
104107
----
105108
====
106109

107-
The difference between a queryable TextEncryptor and a standard TextEncryptor has to do with initialization vector (iv) handling.
108-
The iv used in a queryable TextEncryptor#encrypt operation is shared, or constant, and is not randomly generated.
109-
This means the same text encrypted multiple times will always produce the same encryption result.
110-
This is less secure, but necessary for encrypted data that needs to be queried against.
111-
An example of queryable encrypted text would be an OAuth apiKey.
110+
The difference between a queryable `TextEncryptor` and a standard `TextEncryptor` has to do with initialization vector (IV) handling.
111+
The IV used in a queryable `TextEncryptor.encrypt` operation is shared, or constant, and is not randomly generated.
112+
This means the same text encrypted multiple times always produces the same encryption result.
113+
This is less secure but necessary for encrypted data that needs to be queried against.
114+
An example of queryable encrypted text would be an OAuth `apiKey`.
112115

113116
[[spring-security-crypto-keygenerators]]
114117
== Key Generators
115-
The KeyGenerators class provides a number of convenience factory methods for constructing different types of key generators.
116-
Using this class, you can create a BytesKeyGenerator to generate byte[] keys.
117-
You can also construct a StringKeyGenerator to generate string keys.
118-
KeyGenerators are thread-safe.
118+
The {security-api-url}org/springframework/security/crypto/keygen/KeyGenerators.html[`KeyGenerators`] class provides a number of convenience factory methods for constructing different types of key generators.
119+
By using this class, you can create a {security-api-url}org/springframework/security/crypto/keygen/BytesKeyGenerator.html[`BytesKeyGenerator`] to generate `byte[]` keys.
120+
You can also construct a {security-api-url}org/springframework/security/crypto/keygen/StringKeyGenerator.html`[StringKeyGenerator]` to generate string keys.
121+
`KeyGenerators` is a thread-safe class.
119122

120123
=== BytesKeyGenerator
121-
Use the KeyGenerators.secureRandom factory methods to generate a BytesKeyGenerator backed by a SecureRandom instance:
124+
You can use the `KeyGenerators.secureRandom` factory methods to generate a `BytesKeyGenerator` backed by a `SecureRandom` instance:
122125

123126
.BytesKeyGenerator
124127
====
@@ -138,7 +141,7 @@ val key = generator.generateKey()
138141
====
139142

140143
The default key length is 8 bytes.
141-
There is also a KeyGenerators.secureRandom variant that provides control over the key length:
144+
A `KeyGenerators.secureRandom` variant provides control over the key length:
142145

143146
.KeyGenerators.secureRandom
144147
====
@@ -155,7 +158,7 @@ KeyGenerators.secureRandom(16)
155158
----
156159
====
157160

158-
Use the KeyGenerators.shared factory method to construct a BytesKeyGenerator that always returns the same key on every invocation:
161+
Use the `KeyGenerators.shared` factory method to construct a BytesKeyGenerator that always returns the same key on every invocation:
159162

160163
.KeyGenerators.shared
161164
====
@@ -173,7 +176,7 @@ KeyGenerators.shared(16)
173176
====
174177

175178
=== StringKeyGenerator
176-
Use the KeyGenerators.string factory method to construct a 8-byte, SecureRandom KeyGenerator that hex-encodes each key as a String:
179+
You can use the `KeyGenerators.string` factory method to construct an 8-byte, `SecureRandom` `KeyGenerator` that hex-encodes each key as a `String`:
177180

178181
.StringKeyGenerator
179182
====
@@ -192,9 +195,10 @@ KeyGenerators.string()
192195

193196
[[spring-security-crypto-passwordencoders]]
194197
== Password Encoding
195-
The password package of the spring-security-crypto module provides support for encoding passwords.
198+
The password package of the `spring-security-crypto` module provides support for encoding passwords.
196199
`PasswordEncoder` is the central service interface and has the following signature:
197200

201+
====
198202
[source,java]
199203
----
200204
public interface PasswordEncoder {
@@ -204,16 +208,18 @@ String encode(String rawPassword);
204208
boolean matches(String rawPassword, String encodedPassword);
205209
}
206210
----
211+
====
207212

208-
The matches method returns true if the rawPassword, once encoded, equals the encodedPassword.
213+
The `matches` method returns true if the `rawPassword`, once encoded, equals the `encodedPassword`.
209214
This method is designed to support password-based authentication schemes.
210215

211-
The `BCryptPasswordEncoder` implementation uses the widely supported "bcrypt" algorithm to hash the passwords.
212-
Bcrypt uses a random 16 byte salt value and is a deliberately slow algorithm, in order to hinder password crackers.
213-
The amount of work it does can be tuned using the "strength" parameter which takes values from 4 to 31.
216+
The `BCryptPasswordEncoder` implementation uses the widely supported "`bcrypt`" algorithm to hash the passwords.
217+
Bcrypt uses a random 16-byte salt value and is a deliberately slow algorithm, to hinder password crackers.
218+
You can tune the amount of work it does by using the `strength` parameter, which takes a value from 4 to 31.
214219
The higher the value, the more work has to be done to calculate the hash.
215-
The default value is 10.
220+
The default value is `10`.
216221
You can change this value in your deployed system without affecting existing passwords, as the value is also stored in the encoded hash.
222+
The following example uses the `BCryptPasswordEncoder`:
217223

218224
.BCryptPasswordEncoder
219225
====
@@ -239,7 +245,8 @@ assertTrue(encoder.matches("myPassword", result))
239245
====
240246

241247
The `Pbkdf2PasswordEncoder` implementation uses PBKDF2 algorithm to hash the passwords.
242-
In order to defeat password cracking PBKDF2 is a deliberately slow algorithm and should be tuned to take about .5 seconds to verify a password on your system.
248+
To defeat password cracking, PBKDF2 is a deliberately slow algorithm and should be tuned to take about .5 seconds to verify a password on your system.
249+
The following system uses the `Pbkdf2PasswordEncoder`:
243250

244251

245252
.Pbkdf2PasswordEncoder

0 commit comments

Comments
 (0)