Skip to content

Commit 76ebbb8

Browse files
committed
Separate Namespace Servlet Docs
Issue gh-10367
1 parent 48c8532 commit 76ebbb8

File tree

18 files changed

+1210
-1190
lines changed

18 files changed

+1210
-1190
lines changed

config/src/test/java/org/springframework/security/config/doc/XsdDocumentedTests.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
package org.springframework.security.config.doc;
1818

19+
import java.io.File;
1920
import java.io.IOException;
2021
import java.nio.file.Files;
21-
import java.nio.file.Paths;
22+
import java.nio.file.Path;
2223
import java.util.ArrayList;
2324
import java.util.Arrays;
2425
import java.util.Collection;
@@ -60,7 +61,7 @@ public class XsdDocumentedTests {
6061
"nsa-frame-options-from-parameter");
6162
// @formatter:on
6263

63-
String referenceLocation = "../docs/modules/ROOT/pages/servlet/appendix/namespace.adoc";
64+
String referenceLocation = "../docs/modules/ROOT/pages/servlet/appendix/namespace";
6465

6566
String schema31xDocumentLocation = "org/springframework/security/config/spring-security-3.1.xsd";
6667

@@ -163,7 +164,7 @@ public void sizeWhenReadingFilesystemThenIsCorrectNumberOfSchemaFiles() throws I
163164
public void countReferencesWhenReviewingDocumentationThenEntireSchemaIsIncluded() throws IOException {
164165
Map<String, Element> elementsByElementName = this.xml.elementsByElementName(this.schemaDocumentLocation);
165166
// @formatter:off
166-
List<String> documentIds = Files.lines(Paths.get(this.referenceLocation))
167+
List<String> documentIds = namespaceLines()
167168
.filter((line) -> line.matches("\\[\\[(nsa-.*)\\]\\]"))
168169
.map((line) -> line.substring(2, line.length() - 2))
169170
.collect(Collectors.toList());
@@ -189,7 +190,7 @@ public void countLinksWhenReviewingDocumentationThenParentsAndChildrenAreCorrect
189190
Map<String, List<String>> docAttrNameToParents = new TreeMap<>();
190191
String docAttrName = null;
191192
Map<String, List<String>> currentDocAttrNameToElmt = null;
192-
List<String> lines = Files.readAllLines(Paths.get(this.referenceLocation));
193+
List<String> lines = namespaceLines().collect(Collectors.toList());
193194
for (String line : lines) {
194195
if (line.matches("^\\[\\[.*\\]\\]$")) {
195196
String id = line.substring(2, line.length() - 2);
@@ -212,6 +213,13 @@ else if (id.endsWith("-attributes") || docAttrName != null && !id.startsWith(doc
212213
String elmtId = line.replaceAll(expression, "$1");
213214
currentDocAttrNameToElmt.computeIfAbsent(docAttrName, (key) -> new ArrayList<>()).add(elmtId);
214215
}
216+
else {
217+
expression = ".*xref:.*#(nsa-.*)\\[.*\\]";
218+
if (line.matches(expression)) {
219+
String elmtId = line.replaceAll(expression, "$1");
220+
currentDocAttrNameToElmt.computeIfAbsent(docAttrName, (key) -> new ArrayList<>()).add(elmtId);
221+
}
222+
}
215223
}
216224
}
217225
Map<String, Element> elementNameToElement = this.xml.elementsByElementName(this.schemaDocumentLocation);
@@ -295,4 +303,17 @@ public void countWhenReviewingDocumentationThenAllElementsDocumented() throws IO
295303
assertThat(notDocAttrIds).isEmpty();
296304
}
297305

306+
private Stream<String> namespaceLines() {
307+
return Stream.of(new File(this.referenceLocation).listFiles()).map(File::toPath).flatMap(this::fileLines);
308+
}
309+
310+
private Stream<String> fileLines(Path path) {
311+
try {
312+
return Files.lines(path);
313+
}
314+
catch (Exception ex) {
315+
throw new RuntimeException(ex);
316+
}
317+
}
318+
298319
}

docs/modules/ROOT/nav.adoc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,12 @@
100100
*** xref:servlet/test/mockmvc/result-handlers.adoc[Security ResultHandlers]
101101
** xref:servlet/appendix/index.adoc[Appendix]
102102
*** xref:servlet/appendix/database-schema.adoc[Database Schemas]
103-
*** xref:servlet/appendix/namespace.adoc[XML Namespace]
103+
*** xref:servlet/appendix/namespace/index.adoc[XML Namespace]
104+
**** xref:servlet/appendix/namespace/authentication-manager.adoc[Authentication Services]
105+
**** xref:servlet/appendix/namespace/http.adoc[Web Security]
106+
**** xref:servlet/appendix/namespace/method-security.adoc[Method Security]
107+
**** xref:servlet/appendix/namespace/ldap.adoc[LDAP Security]
108+
**** xref:servlet/appendix/namespace/websocket.adoc[WebSocket Security]
104109
*** xref:servlet/appendix/faq.adoc[FAQ]
105110
* xref:reactive/index.adoc[Reactive Applications]
106111
** xref:reactive/getting-started.adoc[Getting Started]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fun run() {
4444

4545
While very simple, it makes it seamless to transfer the SecurityContext from one Thread to another.
4646
This is important since, in most cases, the SecurityContextHolder acts on a per Thread basis.
47-
For example, you might have used Spring Security's xref:servlet/appendix/namespace.adoc#nsa-global-method-security[<global-method-security>] support to secure one of your services.
47+
For example, you might have used Spring Security's xref:servlet/appendix/namespace/method-security.adoc#nsa-global-method-security[<global-method-security>] support to secure one of your services.
4848
You can now easily transfer the `SecurityContext` of the current `Thread` to the `Thread` that invokes the secured service.
4949
An example of how you might do this can be found below:
5050

docs/modules/ROOT/pages/servlet/appendix/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ This is an appendix for Servlet based Spring Security.
44
It has the following sections:
55

66
* xref:servlet/appendix/database-schema.adoc[Database Schemas]
7-
* xref:servlet/appendix/namespace.adoc[XML Namespace]
7+
* xref:servlet/appendix/namespace/index.adoc[XML Namespace]
88
* xref:servlet/appendix/faq.adoc[FAQ]
Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
[[nsa-authentication]]
2+
= Authentication Services
3+
Before Spring Security 3.0, an `AuthenticationManager` was automatically registered internally.
4+
Now you must register one explicitly using the `<authentication-manager>` element.
5+
This creates an instance of Spring Security's `ProviderManager` class, which needs to be configured with a list of one or more `AuthenticationProvider` instances.
6+
These can either be created using syntax elements provided by the namespace, or they can be standard bean definitions, marked for addition to the list using the `authentication-provider` element.
7+
8+
9+
[[nsa-authentication-manager]]
10+
== <authentication-manager>
11+
Every Spring Security application which uses the namespace must have include this element somewhere.
12+
It is responsible for registering the `AuthenticationManager` which provides authentication services to the application.
13+
All elements which create `AuthenticationProvider` instances should be children of this element.
14+
15+
16+
[[nsa-authentication-manager-attributes]]
17+
=== <authentication-manager> Attributes
18+
19+
20+
[[nsa-authentication-manager-alias]]
21+
* **alias**
22+
This attribute allows you to define an alias name for the internal instance for use in your own configuration.
23+
24+
25+
[[nsa-authentication-manager-erase-credentials]]
26+
* **erase-credentials**
27+
If set to true, the AuthenticationManager will attempt to clear any credentials data in the returned Authentication object, once the user has been authenticated.
28+
Literally it maps to the `eraseCredentialsAfterAuthentication` property of the xref:servlet/authentication/architecture.adoc#servlet-authentication-providermanager[`ProviderManager`].
29+
30+
31+
[[nsa-authentication-manager-id]]
32+
* **id**
33+
This attribute allows you to define an id for the internal instance for use in your own configuration.
34+
It is the same as the alias element, but provides a more consistent experience with elements that use the id attribute.
35+
36+
37+
[[nsa-authentication-manager-children]]
38+
=== Child Elements of <authentication-manager>
39+
40+
41+
* <<nsa-authentication-provider,authentication-provider>>
42+
* xref:servlet/appendix/namespace/ldap.adoc#nsa-ldap-authentication-provider[ldap-authentication-provider]
43+
44+
45+
46+
[[nsa-authentication-provider]]
47+
== <authentication-provider>
48+
Unless used with a `ref` attribute, this element is shorthand for configuring a `DaoAuthenticationProvider`.
49+
`DaoAuthenticationProvider` loads user information from a `UserDetailsService` and compares the username/password combination with the values supplied at login.
50+
The `UserDetailsService` instance can be defined either by using an available namespace element (`jdbc-user-service` or by using the `user-service-ref` attribute to point to a bean defined elsewhere in the application context).
51+
52+
53+
54+
[[nsa-authentication-provider-parents]]
55+
=== Parent Elements of <authentication-provider>
56+
57+
58+
* <<nsa-authentication-manager,authentication-manager>>
59+
60+
61+
62+
[[nsa-authentication-provider-attributes]]
63+
=== <authentication-provider> Attributes
64+
65+
66+
[[nsa-authentication-provider-ref]]
67+
* **ref**
68+
Defines a reference to a Spring bean that implements `AuthenticationProvider`.
69+
70+
If you have written your own `AuthenticationProvider` implementation (or want to configure one of Spring Security's own implementations as a traditional bean for some reason, then you can use the following syntax to add it to the internal list of `ProviderManager`:
71+
72+
[source,xml]
73+
----
74+
75+
<security:authentication-manager>
76+
<security:authentication-provider ref="myAuthenticationProvider" />
77+
</security:authentication-manager>
78+
<bean id="myAuthenticationProvider" class="com.something.MyAuthenticationProvider"/>
79+
80+
----
81+
82+
83+
84+
85+
[[nsa-authentication-provider-user-service-ref]]
86+
* **user-service-ref**
87+
A reference to a bean that implements UserDetailsService that may be created using the standard bean element or the custom user-service element.
88+
89+
90+
[[nsa-authentication-provider-children]]
91+
=== Child Elements of <authentication-provider>
92+
93+
94+
* <<nsa-jdbc-user-service,jdbc-user-service>>
95+
* xref:servlet/appendix/namespace/ldap.adoc#nsa-ldap-user-service[ldap-user-service]
96+
* <<nsa-password-encoder,password-encoder>>
97+
* <<nsa-user-service,user-service>>
98+
99+
100+
101+
[[nsa-jdbc-user-service]]
102+
== <jdbc-user-service>
103+
Causes creation of a JDBC-based UserDetailsService.
104+
105+
106+
[[nsa-jdbc-user-service-attributes]]
107+
=== <jdbc-user-service> Attributes
108+
109+
110+
[[nsa-jdbc-user-service-authorities-by-username-query]]
111+
* **authorities-by-username-query**
112+
An SQL statement to query for a user's granted authorities given a username.
113+
114+
The default is
115+
116+
[source]
117+
----
118+
select username, authority from authorities where username = ?
119+
----
120+
121+
122+
123+
124+
[[nsa-jdbc-user-service-cache-ref]]
125+
* **cache-ref**
126+
Defines a reference to a cache for use with a UserDetailsService.
127+
128+
129+
[[nsa-jdbc-user-service-data-source-ref]]
130+
* **data-source-ref**
131+
The bean ID of the DataSource which provides the required tables.
132+
133+
134+
[[nsa-jdbc-user-service-group-authorities-by-username-query]]
135+
* **group-authorities-by-username-query**
136+
An SQL statement to query user's group authorities given a username.
137+
The default is
138+
139+
+
140+
141+
[source]
142+
----
143+
select
144+
g.id, g.group_name, ga.authority
145+
from
146+
groups g, group_members gm, group_authorities ga
147+
where
148+
gm.username = ? and g.id = ga.group_id and g.id = gm.group_id
149+
----
150+
151+
152+
153+
154+
[[nsa-jdbc-user-service-id]]
155+
* **id**
156+
A bean identifier, used for referring to the bean elsewhere in the context.
157+
158+
159+
[[nsa-jdbc-user-service-role-prefix]]
160+
* **role-prefix**
161+
A non-empty string prefix that will be added to role strings loaded from persistent storage (default is "ROLE_").
162+
Use the value "none" for no prefix in cases where the default is non-empty.
163+
164+
165+
[[nsa-jdbc-user-service-users-by-username-query]]
166+
* **users-by-username-query**
167+
An SQL statement to query a username, password, and enabled status given a username.
168+
The default is
169+
170+
+
171+
172+
[source]
173+
----
174+
select username, password, enabled from users where username = ?
175+
----
176+
177+
178+
179+
180+
[[nsa-password-encoder]]
181+
== <password-encoder>
182+
Authentication providers can optionally be configured to use a password encoder as described in the xref:features/authentication/password-storage.adoc#authentication-password-storage[Password Storage].
183+
This will result in the bean being injected with the appropriate `PasswordEncoder` instance.
184+
185+
186+
[[nsa-password-encoder-parents]]
187+
=== Parent Elements of <password-encoder>
188+
189+
190+
* <<nsa-authentication-provider,authentication-provider>>
191+
* xref:servlet/appendix/namespace/authentication-manager.adoc#nsa-password-compare[password-compare]
192+
193+
194+
195+
[[nsa-password-encoder-attributes]]
196+
=== <password-encoder> Attributes
197+
198+
199+
[[nsa-password-encoder-hash]]
200+
* **hash**
201+
Defines the hashing algorithm used on user passwords.
202+
We recommend strongly against using MD4, as it is a very weak hashing algorithm.
203+
204+
205+
[[nsa-password-encoder-ref]]
206+
* **ref**
207+
Defines a reference to a Spring bean that implements `PasswordEncoder`.
208+
209+
210+
[[nsa-user-service]]
211+
== <user-service>
212+
Creates an in-memory UserDetailsService from a properties file or a list of "user" child elements.
213+
Usernames are converted to lower-case internally to allow for case-insensitive lookups, so this should not be used if case-sensitivity is required.
214+
215+
216+
[[nsa-user-service-attributes]]
217+
=== <user-service> Attributes
218+
219+
220+
[[nsa-user-service-id]]
221+
* **id**
222+
A bean identifier, used for referring to the bean elsewhere in the context.
223+
224+
225+
[[nsa-user-service-properties]]
226+
* **properties**
227+
The location of a Properties file where each line is in the format of
228+
229+
+
230+
231+
[source]
232+
----
233+
username=password,grantedAuthority[,grantedAuthority][,enabled|disabled]
234+
----
235+
236+
237+
238+
239+
[[nsa-user-service-children]]
240+
=== Child Elements of <user-service>
241+
242+
243+
* <<nsa-user,user>>
244+
245+
246+
247+
[[nsa-user]]
248+
== <user>
249+
Represents a user in the application.
250+
251+
252+
[[nsa-user-parents]]
253+
=== Parent Elements of <user>
254+
255+
256+
* <<nsa-user-service,user-service>>
257+
258+
259+
260+
[[nsa-user-attributes]]
261+
=== <user> Attributes
262+
263+
264+
[[nsa-user-authorities]]
265+
* **authorities**
266+
One of more authorities granted to the user.
267+
Separate authorities with a comma (but no space).
268+
For example, "ROLE_USER,ROLE_ADMINISTRATOR"
269+
270+
271+
[[nsa-user-disabled]]
272+
* **disabled**
273+
Can be set to "true" to mark an account as disabled and unusable.
274+
275+
276+
[[nsa-user-locked]]
277+
* **locked**
278+
Can be set to "true" to mark an account as locked and unusable.
279+
280+
281+
[[nsa-user-name]]
282+
* **name**
283+
The username assigned to the user.
284+
285+
286+
[[nsa-user-password]]
287+
* **password**
288+
The password assigned to the user.
289+
This may be hashed if the corresponding authentication provider supports hashing (remember to set the "hash" attribute of the "user-service" element).
290+
This attribute be omitted in the case where the data will not be used for authentication, but only for accessing authorities.
291+
If omitted, the namespace will generate a random value, preventing its accidental use for authentication.
292+
Cannot be empty.

0 commit comments

Comments
 (0)