Skip to content

Commit e4a3813

Browse files
Towards Spring Boot 2.2, and reactive oauth
1 parent bfd628f commit e4a3813

File tree

16 files changed

+237
-72
lines changed

16 files changed

+237
-72
lines changed

lemon-demo-angularjs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "angularsample",
33
"version": "0.0.0",
44
"dependencies": {
5-
"natives": "^1.1.5",
5+
"natives": "^1.1.6",
66
"wiredep": "^2.2.2"
77
},
88
"repository": {},
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
## Spring Lemon Bean Validation messages
3+
#
4+
5+
com.naturalprogrammer.spring.blank.email: Email needed
6+
com.naturalprogrammer.spring.invalid.email: Not a well formed email address
7+
com.naturalprogrammer.spring.invalid.email.size: Email must be between {min} and {max} characters
8+
com.naturalprogrammer.spring.duplicate.email: Email Id already used
9+
com.naturalprogrammer.spring.wrong.captcha: Looks like you are a robot! Please try again.
10+
11+
com.naturalprogrammer.spring.invalid.password.size: Password must be between {min} and {max} characters
12+
13+
com.naturalprogrammer.spring.different.passwords: Passwords do not match
14+
com.naturalprogrammer.spring.blank.password: Password needed
15+
16+
17+
#
18+
## My Bean Validation Messages
19+
#
20+
21+
blank.name: Name required

lemon-demo-jpa/src/main/resources/messages.properties

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,6 @@ com.naturalprogrammer.spring.blank: Please provide {0}
4242
com.naturalprogrammer.spring.userClaimAbsent: User claim absent in the authorization token
4343
com.naturalprogrammer.spring.fullTokenNotAllowed: Full authorization tokens aren't allowed here
4444

45-
#
46-
## Spring Lemon Bean Validation messages
47-
#
48-
49-
com.naturalprogrammer.spring.blank.email: Email needed
50-
com.naturalprogrammer.spring.invalid.email: Not a well formed email address
51-
com.naturalprogrammer.spring.invalid.email.size: Email must be between {min} and {max} characters
52-
com.naturalprogrammer.spring.duplicate.email: Email Id already used
53-
com.naturalprogrammer.spring.wrong.captcha: Looks like you are a robot! Please try again.
54-
55-
com.naturalprogrammer.spring.invalid.password.size: Password must be between {min} and {max} characters
56-
57-
com.naturalprogrammer.spring.different.passwords: Passwords do not match
58-
com.naturalprogrammer.spring.blank.password: Password needed
59-
6045
#
6146
## My Normal Messages
62-
#
63-
64-
6547
#
66-
## My Bean Validation Messages
67-
#
68-
69-
blank.name: Name required

lemon-demo-jpa/src/test/java/com/naturalprogrammer/spring/lemondemo/SignupMvcTests.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,17 @@ public void testSignupWithInvalidData() throws Exception {
3333
.andExpect(status().is(422))
3434
.andExpect(jsonPath("$.errors[*].field").value(hasSize(4)))
3535
.andExpect(jsonPath("$.errors[*].field").value(hasItems(
36-
"user.email", "user.password", "user.name")));
36+
"user.email", "user.password", "user.name")))
37+
.andExpect(jsonPath("$.errors[*].code").value(hasItems(
38+
"{com.naturalprogrammer.spring.invalid.email}",
39+
"{blank.name}",
40+
"{com.naturalprogrammer.spring.invalid.email.size}",
41+
"{com.naturalprogrammer.spring.invalid.password.size}")))
42+
.andExpect(jsonPath("$.errors[*].message").value(hasItems(
43+
"Not a well formed email address",
44+
"Name required",
45+
"Email must be between 4 and 250 characters",
46+
"Password must be between 6 and 50 characters")));
3747

3848
verify(mailSender, never()).send(any());
3949
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
## Spring Lemon Bean Validation messages
3+
#
4+
5+
com.naturalprogrammer.spring.blank.email: Email needed
6+
com.naturalprogrammer.spring.invalid.email: Not a well formed email address
7+
com.naturalprogrammer.spring.invalid.email.size: Email must be between {min} and {max} characters
8+
com.naturalprogrammer.spring.duplicate.email: Email Id already used
9+
com.naturalprogrammer.spring.wrong.captcha: Looks like you are a robot! Please try again.
10+
11+
com.naturalprogrammer.spring.invalid.password.size: Password must be between {min} and {max} characters
12+
13+
com.naturalprogrammer.spring.different.passwords: Passwords do not match
14+
com.naturalprogrammer.spring.blank.password: Password needed
15+
16+
#
17+
## My Bean Validation Messages
18+
#
19+
20+
blank.name: Name required

lemon-demo-reactive/src/main/resources/messages.properties

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,6 @@ com.naturalprogrammer.spring.blank: Please provide {0}
4242
com.naturalprogrammer.spring.userClaimAbsent: User claim absent in the authorization token
4343
com.naturalprogrammer.spring.fullTokenNotAllowed: Full authorization tokens aren't allowed here
4444

45-
#
46-
## Spring Lemon Bean Validation messages
47-
#
48-
49-
com.naturalprogrammer.spring.blank.email: Email needed
50-
com.naturalprogrammer.spring.invalid.email: Not a well formed email address
51-
com.naturalprogrammer.spring.invalid.email.size: Email must be between {min} and {max} characters
52-
com.naturalprogrammer.spring.duplicate.email: Email Id already used
53-
com.naturalprogrammer.spring.wrong.captcha: Looks like you are a robot! Please try again.
54-
55-
com.naturalprogrammer.spring.invalid.password.size: Password must be between {min} and {max} characters
56-
57-
com.naturalprogrammer.spring.different.passwords: Passwords do not match
58-
com.naturalprogrammer.spring.blank.password: Password needed
59-
6045
#
6146
## My Normal Messages
6247
#
63-
64-
65-
#
66-
## My Bean Validation Messages
67-
#
68-
69-
blank.name: Name required

lemon-demo-reactive/src/test/java/com/naturalprogrammer/spring/lemondemo/SignupTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
import static org.springframework.data.mongodb.core.query.Criteria.where;
1717
import static org.springframework.data.mongodb.core.query.Query.query;
1818

19+
import java.util.Arrays;
20+
import java.util.Collection;
21+
import java.util.stream.Collectors;
22+
1923
import org.junit.Test;
2024
import org.springframework.http.HttpStatus;
2125
import org.springframework.http.MediaType;
@@ -24,6 +28,7 @@
2428
import com.naturalprogrammer.spring.lemon.commons.util.LecUtils;
2529
import com.naturalprogrammer.spring.lemondemo.domain.User;
2630
import com.naturalprogrammer.spring.lemondemo.dto.TestErrorResponse;
31+
import com.naturalprogrammer.spring.lemondemo.dto.TestLemonFieldError;
2732
import com.naturalprogrammer.spring.lemondemo.dto.TestUser;
2833
import com.naturalprogrammer.spring.lemondemo.dto.TestUserDto;
2934

@@ -73,6 +78,22 @@ public void testSignupWithInvalidData() throws Exception {
7378
"userMono.email",
7479
"userMono.password",
7580
"userMono.name");
81+
82+
Collection<TestLemonFieldError> errors = errorResponseResult.getResponseBody().getErrors();
83+
assertTrue(errors.stream()
84+
.map(TestLemonFieldError::getCode).collect(Collectors.toSet())
85+
.containsAll(Arrays.asList(
86+
"NotBlank",
87+
"Size",
88+
"Email")));
89+
90+
assertTrue(errors.stream()
91+
.map(TestLemonFieldError::getMessage).collect(Collectors.toSet())
92+
.containsAll(Arrays.asList(
93+
"Not a well formed email address",
94+
"Name required",
95+
"Email must be between 4 and 250 characters",
96+
"Password must be between 6 and 50 characters")));
7697
});
7798

7899
verify(mailSender, never()).send(any());

pom.xml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<parent>
1616
<groupId>org.springframework.boot</groupId>
1717
<artifactId>spring-boot-starter-parent</artifactId>
18-
<version>2.1.6.RELEASE</version>
18+
<version>2.2.0.BUILD-SNAPSHOT</version>
1919
<relativePath /> <!-- lookup parent from repository -->
2020
</parent>
2121

@@ -89,4 +89,28 @@
8989
<java.version>1.8</java.version>
9090
</properties>
9191

92+
<!-- Add Spring repositories -->
93+
<!-- (you don't need this if you are using a .RELEASE version) -->
94+
<repositories>
95+
<repository>
96+
<id>spring-snapshots</id>
97+
<url>https://repo.spring.io/snapshot</url>
98+
<snapshots><enabled>true</enabled></snapshots>
99+
</repository>
100+
<repository>
101+
<id>spring-milestones</id>
102+
<url>https://repo.spring.io/milestone</url>
103+
</repository>
104+
</repositories>
105+
<pluginRepositories>
106+
<pluginRepository>
107+
<id>spring-snapshots</id>
108+
<url>https://repo.spring.io/snapshot</url>
109+
</pluginRepository>
110+
<pluginRepository>
111+
<id>spring-milestones</id>
112+
<url>https://repo.spring.io/milestone</url>
113+
</pluginRepository>
114+
</pluginRepositories>
115+
92116
</project>

spring-lemon-commons-web/src/main/java/com/naturalprogrammer/spring/lemon/commonsweb/LemonCommonsWebAutoConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public LemonCommonsWebAutoConfiguration() {
6161
log.info("Created");
6262
}
6363

64-
/**
64+
/**
6565
* Prefixes JSON responses for JSON vulnerability. Disabled by default.
6666
* To enable, add this to your application properties:
6767
* lemon.enabled.json-prefix: true

spring-lemon-commons/src/main/java/com/naturalprogrammer/spring/lemon/commons/LemonCommonsAutoConfiguration.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
66
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
77
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
8-
import org.springframework.boot.web.client.RestTemplateBuilder;
98
import org.springframework.context.ApplicationContext;
109
import org.springframework.context.annotation.Bean;
1110
import org.springframework.context.annotation.ComponentScan;
@@ -142,9 +141,9 @@ public LecUtils lecUtils(ApplicationContext applicationContext, ObjectMapper obj
142141
*/
143142
@Bean
144143
@ConditionalOnMissingBean(CaptchaValidator.class)
145-
public CaptchaValidator captchaValidator(LemonProperties properties, RestTemplateBuilder restTemplateBuilder) {
144+
public CaptchaValidator captchaValidator(LemonProperties properties) {
146145

147146
log.info("Configuring LemonUserDetailsService");
148-
return new CaptchaValidator(properties, restTemplateBuilder);
147+
return new CaptchaValidator(properties);
149148
}
150149
}

0 commit comments

Comments
 (0)