@@ -3,12 +3,13 @@ Learn Spring Security by baby steps from zero to pro!
3
3
4
4
## Table of Content
5
5
* [ Step 0: No security] ( #step-0 )
6
+ * [ Step 1: Add authentication] ( #step-1 )
6
7
* [ Versioning and releasing] ( #maven )
7
8
* [ Resources and used links] ( #resources )
8
9
9
10
## step: 0
10
11
11
- let's use simple spring boot web app
12
+ let's use simple spring boot web app without security at all!
12
13
13
14
### application
14
15
@@ -57,10 +58,12 @@ finally, to gracefully shutdown application under test on CI builds,
57
58
add actuator dependency:
58
59
59
60
``` xml
61
+ <dependencies >
60
62
<dependency >
61
63
<groupId >org.springframework.boot</groupId >
62
64
<artifactId >spring-boot-starter-actuator</artifactId >
63
65
</dependency >
66
+ </dependencies >
64
67
```
65
68
66
69
with according configurations in ` application.yaml ` file:
@@ -113,11 +116,12 @@ class AppTest extends AbstractTest {
113
116
114
117
@Test
115
118
void test () {
116
- open(" http://127.0.0.1:8080" );
117
- var h1 = $(" h1" );
119
+ open(" http://127.0.0.1:8080" ); // open home page...
120
+ var h1 = $(" h1" ); // find there <h1> tag...
118
121
log. info(" h1 html: {}" , h1);
119
- h1. shouldBe(exist, visible)
120
- .shouldHave(text(" hello" ));
122
+ h1. shouldBe(exist, visible) // element should be inside DOM
123
+ .shouldHave(text(" hello" )); // textContent of the tag should
124
+ // contains expected content...
121
125
}
122
126
}
123
127
```
@@ -133,6 +137,58 @@ java -jar ./step-0-application-without-security/target/*jar --spring.profiles.ac
133
137
http post :8080/actuator/shutdown
134
138
```
135
139
140
+ ## step: 1
141
+
142
+ in this step we are going to implement simple authentication.
143
+ it's mean everyone who logged in, can access all available
144
+ resources.
145
+
146
+ ### application
147
+
148
+ add required dependencies:
149
+
150
+ ``` xml
151
+ <dependencies >
152
+ <dependency >
153
+ <groupId >org.springframework.boot</groupId >
154
+ <artifactId >spring-boot-starter-security</artifactId >
155
+ </dependency >
156
+ </dependencies >
157
+ ```
158
+
159
+ update ` application.yaml ` configuration with desired user password:
160
+
161
+ ``` yaml
162
+ spring :
163
+ security :
164
+ user :
165
+ password : pwd
166
+ ` ` `
167
+
168
+ ### test application
169
+
170
+ now, let's update test according to configured security as follows:
171
+
172
+ ` ` ` java
173
+ @Log4j2
174
+ @AllArgsConstructor
175
+ class AppTest extends AbstractTest {
176
+
177
+ @Test
178
+ void test() {
179
+ open("http://127.0.0.1:8080");
180
+ // we should be redirected to login page, so lets authenticate!
181
+ $("#username").setValue("user");
182
+ $("#password").setValue("pwd").submit();
183
+ // everything else is with no changes...
184
+ var h1 = $("h1");
185
+ log.info("h1 html : {}", h1);
186
+ h1.shouldBe(exist, visible)
187
+ .shouldHave(text("hello"));
188
+ }
189
+ }
190
+ ```
191
+
136
192
## maven
137
193
138
194
we will be releasing after each important step! so it will be easy simply checkout needed version from git tag.
0 commit comments