Skip to content

Commit 88d02cb

Browse files
authored
Merge pull request #139 from Edamijueda/issue-#135
make controller path mappings configurable
2 parents 1c5597e + 7c1c9c8 commit 88d02cb

3 files changed

Lines changed: 51 additions & 35 deletions

File tree

src/main/java/com/digitalsanctuary/spring/user/controller/UserActionController.java

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import lombok.extern.slf4j.Slf4j;
2222

2323
/**
24-
* The UserActionController handles non-API, non-Page requests like token validation links from emails.
24+
* The UserActionController handles non-API, non-Page requests like token
25+
* validation links from emails.
2526
*/
2627
@Slf4j
2728
@RequiredArgsConstructor
@@ -56,20 +57,23 @@ public class UserActionController {
5657
private String forgotPasswordChangeURI;
5758

5859
/**
59-
* Validate a forgot password token link from an email, and if valid, show the change password page.
60+
* Validate a forgot password token link from an email, and if valid, show the
61+
* change password page.
6062
*
6163
* @param request the request
62-
* @param model the model
63-
* @param token the token
64+
* @param model the model
65+
* @param token the token
6466
* @return the model and view
6567
*/
66-
@GetMapping("/user/changePassword")
67-
public ModelAndView showChangePasswordPage(final HttpServletRequest request, final ModelMap model, @RequestParam("token") final String token) {
68+
@GetMapping("${user.security.changePasswordURI:/user/changePassword}")
69+
public ModelAndView showChangePasswordPage(final HttpServletRequest request, final ModelMap model,
70+
@RequestParam("token") final String token) {
6871
log.debug("UserAPI.showChangePasswordPage: called with token: {}", token);
6972
final TokenValidationResult result = userService.validatePasswordResetToken(token);
7073
log.debug("UserAPI.showChangePasswordPage:" + "result: {}", result);
7174
AuditEvent changePasswordAuditEvent = AuditEvent.builder().source(this).sessionId(request.getSession().getId())
72-
.ipAddress(UserUtils.getClientIP(request)).userAgent(request.getHeader("User-Agent")).action("showChangePasswordPage")
75+
.ipAddress(UserUtils.getClientIP(request)).userAgent(request.getHeader("User-Agent"))
76+
.action("showChangePasswordPage")
7377
.actionStatus("Success").message("Requested. Result:" + result).build();
7478

7579
eventPublisher.publishEvent(changePasswordAuditEvent);
@@ -85,15 +89,16 @@ public ModelAndView showChangePasswordPage(final HttpServletRequest request, fin
8589
}
8690

8791
/**
88-
* Validate a forgot password token link from an email, and if valid, show the registration success page.
92+
* Validate a forgot password token link from an email, and if valid, show the
93+
* registration success page.
8994
*
9095
* @param request the request
91-
* @param model the model
92-
* @param token the token
96+
* @param model the model
97+
* @param token the token
9398
* @return the model and view
9499
* @throws UnsupportedEncodingException the unsupported encoding exception
95100
*/
96-
@GetMapping("/user/registrationConfirm")
101+
@GetMapping("${user.security.registrationConfirmURI:/user/registrationConfirm}")
97102
public ModelAndView confirmRegistration(final HttpServletRequest request, final ModelMap model,
98103
@RequestParam("token") final String token) throws UnsupportedEncodingException {
99104
log.debug("UserAPI.confirmRegistration: called with token: {}", token);
@@ -107,8 +112,10 @@ public ModelAndView confirmRegistration(final HttpServletRequest request, final
107112
userService.authWithoutPassword(user);
108113
userVerificationService.deleteVerificationToken(token);
109114

110-
AuditEvent registrationAuditEvent = AuditEvent.builder().source(this).user(user).sessionId(request.getSession().getId())
111-
.ipAddress(UserUtils.getClientIP(request)).userAgent(request.getHeader("User-Agent")).action("Registration Confirmation")
115+
AuditEvent registrationAuditEvent = AuditEvent.builder().source(this).user(user)
116+
.sessionId(request.getSession().getId())
117+
.ipAddress(UserUtils.getClientIP(request)).userAgent(request.getHeader("User-Agent"))
118+
.action("Registration Confirmation")
112119
.actionStatus("Success").message("Registration Confirmed. User logged in.").build();
113120

114121
eventPublisher.publishEvent(registrationAuditEvent);

src/main/java/com/digitalsanctuary/spring/user/controller/UserPageController.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ public class UserPageController {
3131
* Login Page.
3232
*
3333
* @param userDetails the user details
34-
* @param session the session
35-
* @param model the model
34+
* @param session the session
35+
* @param model the model
3636
*
3737
* @return the string
3838
*/
39-
@GetMapping("/user/login.html")
39+
@GetMapping("${user.security.loginPageURI:/user/login.html}")
4040
public String login(@AuthenticationPrincipal DSUserDetails userDetails, HttpSession session, ModelMap model) {
4141
log.debug("UserPageController.login:" + "userDetails: {}", userDetails);
4242
if (session != null && session.getAttribute("error.message") != null) {
@@ -52,11 +52,11 @@ public String login(@AuthenticationPrincipal DSUserDetails userDetails, HttpSess
5252
* Register Page.
5353
*
5454
* @param userDetails the user details
55-
* @param session the session
56-
* @param model the model
55+
* @param session the session
56+
* @param model the model
5757
* @return the string
5858
*/
59-
@GetMapping("/user/register.html")
59+
@GetMapping("${user.security.registrationURI:/user/register.html}")
6060
public String register(@AuthenticationPrincipal DSUserDetails userDetails, HttpSession session, ModelMap model) {
6161
log.debug("UserPageController.register:" + "userDetails: {}", userDetails);
6262
if (session != null && session.getAttribute("error.message") != null) {
@@ -73,7 +73,7 @@ public String register(@AuthenticationPrincipal DSUserDetails userDetails, HttpS
7373
*
7474
* @return the string
7575
*/
76-
@GetMapping("/user/registration-pending-verification.html")
76+
@GetMapping("${user.security.registrationPendingURI:/user/registration-pending-verification.html}")
7777
public String registrationPending() {
7878
return "user/registration-pending-verification";
7979
}
@@ -82,13 +82,14 @@ public String registrationPending() {
8282
* Registration complete.
8383
*
8484
* @param userDetails the user details
85-
* @param session the session
86-
* @param model the model
85+
* @param session the session
86+
* @param model the model
8787
*
8888
* @return the string
8989
*/
90-
@GetMapping("/user/registration-complete.html")
91-
public String registrationComplete(@AuthenticationPrincipal DSUserDetails userDetails, HttpSession session, ModelMap model) {
90+
@GetMapping("${user.security.registrationSuccessURI:/user/registration-complete.html}")
91+
public String registrationComplete(@AuthenticationPrincipal DSUserDetails userDetails, HttpSession session,
92+
ModelMap model) {
9293
log.debug("UserPageController.registrationComplete:" + "userDetails: {}", userDetails);
9394
return "user/registration-complete";
9495
}
@@ -98,7 +99,7 @@ public String registrationComplete(@AuthenticationPrincipal DSUserDetails userDe
9899
*
99100
* @return the string
100101
*/
101-
@GetMapping("/user/request-new-verification-email.html")
102+
@GetMapping("${user.security.registrationNewVerificationURI:/user/request-new-verification-email.html}")
102103
public String requestNewVerificationEMail() {
103104
return "user/request-new-verification-email";
104105
}
@@ -108,7 +109,7 @@ public String requestNewVerificationEMail() {
108109
*
109110
* @return the string
110111
*/
111-
@GetMapping("/user/forgot-password.html")
112+
@GetMapping("${user.security.forgotPasswordURI:/user/forgot-password.html}")
112113
public String forgotPassword() {
113114
return "user/forgot-password";
114115
}
@@ -118,7 +119,7 @@ public String forgotPassword() {
118119
*
119120
* @return the string
120121
*/
121-
@GetMapping("/user/forgot-password-pending-verification.html")
122+
@GetMapping("${user.security.forgotPasswordPendingURI:/user/forgot-password-pending-verification.html}")
122123
public String forgotPasswordPendingVerification() {
123124
return "user/forgot-password-pending-verification";
124125
}
@@ -128,20 +129,20 @@ public String forgotPasswordPendingVerification() {
128129
*
129130
* @return the string
130131
*/
131-
@GetMapping("/user/forgot-password-change.html")
132+
@GetMapping("${user.security.forgotPasswordChangeURI:/user/forgot-password-change.html}")
132133
public String forgotPasswordChange() {
133134
return "user/forgot-password-change";
134135
}
135136

136-
137137
/**
138138
* @param userDetails the user details
139-
* @param request the request
140-
* @param model the model
139+
* @param request the request
140+
* @param model the model
141141
* @return String
142142
*/
143-
@GetMapping("/user/update-user.html")
144-
public String updateUser(@AuthenticationPrincipal DSUserDetails userDetails, final HttpServletRequest request, final ModelMap model) {
143+
@GetMapping("${user.security.updateUserURI:/user/update-user.html}")
144+
public String updateUser(@AuthenticationPrincipal DSUserDetails userDetails, final HttpServletRequest request,
145+
final ModelMap model) {
145146
if (userDetails != null) {
146147
User user = userDetails.getUser();
147148
UserDto userDto = new UserDto();
@@ -157,7 +158,7 @@ public String updateUser(@AuthenticationPrincipal DSUserDetails userDetails, fin
157158
*
158159
* @return the string
159160
*/
160-
@GetMapping("/user/update-password.html")
161+
@GetMapping("${user.security.updatePasswordURI:/user/update-password.html}")
161162
public String updatePassword() {
162163
return "user/update-password";
163164
}
@@ -167,7 +168,7 @@ public String updatePassword() {
167168
*
168169
* @return the string
169170
*/
170-
@GetMapping("/user/delete-account.html")
171+
@GetMapping("${user.security.deleteAccountURI:/user/delete-account.html}")
171172
public String deleteAccount() {
172173
return "user/delete-account";
173174
}

src/main/resources/config/dsspringuserconfig.properties

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ user.security.registrationSuccessURI=/user/registration-complete.html
7474
user.security.registrationNewVerificationURI=/user/request-new-verification-email.html
7575
# The URI for the update user page.
7676
user.security.updateUserURI=/user/update-user.html
77+
# The URI for the update password page.
78+
user.security.updatePasswordURI=/user/update-password.html
79+
# The URI for the delete account page.
80+
user.security.deleteAccountURI=/user/delete-account.html
81+
# The URI for the change password page.
82+
user.security.changePasswordURI=/user/changePassword
83+
# The URI for the registration confirm page.
84+
user.security.registrationConfirmURI=/user/registrationConfirm
7785

7886
# The from address for all emails sent by the application.
7987
user.mail.fromAddress=test@test.com

0 commit comments

Comments
 (0)