Skip to content

Commit 1ddef21

Browse files
committed
work
1 parent b34ba4f commit 1ddef21

File tree

8 files changed

+47
-49
lines changed

8 files changed

+47
-49
lines changed

src/main/java/org/woehlke/java/simpleworklist/domain/PagesController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.woehlke.java.simpleworklist.domain;
22

33
import lombok.extern.slf4j.Slf4j;
4+
import org.springframework.security.access.prepost.PreAuthorize;
45
import org.springframework.stereotype.Controller;
56
import org.springframework.ui.Model;
67
import org.springframework.web.bind.annotation.ModelAttribute;
@@ -13,9 +14,11 @@
1314

1415
@Slf4j
1516
@Controller
17+
@PreAuthorize("permitAll()")
1618
@RequestMapping(path = "/pages")
17-
public class PagesController extends AbstractController {
19+
public class PagesController {
1820

21+
@PreAuthorize("permitAll()")
1922
@RequestMapping(path = "/information", method = RequestMethod.GET)
2023
public final String renderPageInformation(
2124
@NotNull @ModelAttribute("userSession") UserSessionBean userSession,

src/main/java/org/woehlke/java/simpleworklist/domain/UserLoginController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public UserLoginController(
4242
* Login Formular. If User is not logged in, this page will be displayed for
4343
* all page-URLs which need login.
4444
*
45-
* @param model
45+
* @param model Model
4646
* @return Login Screen.
4747
*/
4848
@RequestMapping(path = "/login", method = RequestMethod.GET)
@@ -56,9 +56,9 @@ public final String loginGet(Model model) {
5656
/**
5757
* Perform login.
5858
*
59-
* @param loginForm
60-
* @param result
61-
* @param model
59+
* @param loginForm LoginForm
60+
* @param result BindingResult
61+
* @param model Model
6262
* @return Shows Root Project after successful login or login form with error messages.
6363
*/
6464
@RequestMapping(path = "/login", method = RequestMethod.POST)

src/main/java/org/woehlke/java/simpleworklist/domain/UserPasswordRecoveryController.java

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.woehlke.java.simpleworklist.domain;
22

33
import lombok.extern.slf4j.Slf4j;
4+
import org.springframework.beans.factory.annotation.Autowired;
45
import org.springframework.security.access.prepost.PreAuthorize;
56
import org.springframework.stereotype.Controller;
67
import org.springframework.ui.Model;
@@ -16,36 +17,33 @@
1617
import org.woehlke.java.simpleworklist.domain.db.user.passwordrecovery.UserAccountPasswordRecoveryService;
1718
import org.woehlke.java.simpleworklist.domain.db.user.signup.UserAccountRegistrationForm;
1819

19-
import org.springframework.beans.factory.annotation.Autowired;
20-
2120
import javax.validation.Valid;
2221

2322
@Slf4j
2423
@Controller
25-
@RequestMapping(path = "/user")
24+
@RequestMapping(path= "/user/resetPassword")
2625
public class UserPasswordRecoveryController {
2726

28-
private final UserAccountService userAccountService;
2927
private final UserAccountPasswordRecoveryService userAccountPasswordRecoveryService;
28+
private final UserAccountService userAccountService;
3029

3130
@Autowired
3231
public UserPasswordRecoveryController(
33-
UserAccountService userAccountService,
34-
UserAccountPasswordRecoveryService userAccountPasswordRecoveryService
32+
UserAccountPasswordRecoveryService userAccountPasswordRecoveryService,
33+
UserAccountService userAccountService
3534
) {
36-
this.userAccountService = userAccountService;
3735
this.userAccountPasswordRecoveryService = userAccountPasswordRecoveryService;
36+
this.userAccountService = userAccountService;
3837
}
3938

4039
/**
4140
* Visitor who might be Registered, but not yet logged in, clicks
4241
* on 'password forgotten' at login formular.
4342
*
44-
* @param model
43+
* @param model Model
4544
* @return a Formular for entering the email-adress.
4645
*/
47-
@PreAuthorize("isAnonymous()")
48-
@RequestMapping(path="/resetPassword", method = RequestMethod.GET)
46+
@RequestMapping(path="/form", method = RequestMethod.GET)
4947
public final String passwordForgottenForm(Model model) {
5048
UserAccountRegistrationForm userAccountRegistrationForm = new UserAccountRegistrationForm();
5149
model.addAttribute("userAccountRegistrationForm", userAccountRegistrationForm);
@@ -55,13 +53,12 @@ public final String passwordForgottenForm(Model model) {
5553
/**
5654
* If email-address exists, send email with Link for password-Reset.
5755
*
58-
* @param userAccountRegistrationForm
59-
* @param result
60-
* @param model
56+
* @param userAccountRegistrationForm UserAccountRegistrationForm
57+
* @param result BindingResult
58+
* @param model Model
6159
* @return info page if without errors or formular again displaying error messages.
6260
*/
63-
@PreAuthorize("isAnonymous()")
64-
@RequestMapping(path="/resetPassword", method = RequestMethod.POST)
61+
@RequestMapping(path="/form", method = RequestMethod.POST)
6562
public final String passwordForgottenPost(
6663
@Valid UserAccountRegistrationForm userAccountRegistrationForm,
6764
BindingResult result,
@@ -78,6 +75,9 @@ public final String passwordForgottenPost(
7875
log.info(userAccountRegistrationForm.toString());
7976
log.info(result.toString());
8077
log.info(model.toString());
78+
if(userAccountService == null){
79+
return "redirect:/";
80+
}
8181
if (userAccountService.findByUserEmail(userAccountRegistrationForm.getEmail()) == null) {
8282
String objectName = "userRegistrationForm";
8383
String field = "email";
@@ -95,12 +95,11 @@ public final String passwordForgottenPost(
9595
/**
9696
* User clicked on Link in Email for Password-Recovery.
9797
*
98-
* @param confirmId
99-
* @param model
98+
* @param confirmId String
99+
* @param model Model
100100
* @return a Formular for entering the new Password.
101101
*/
102-
@PreAuthorize("isAnonymous()")
103-
@RequestMapping(path = "/resetPassword/confirm/{confirmId}", method = RequestMethod.GET)
102+
@RequestMapping(path = "/confirm/{confirmId}", method = RequestMethod.GET)
104103
public final String enterNewPasswordFormular(
105104
@PathVariable String confirmId,
106105
Model model
@@ -123,14 +122,14 @@ public final String enterNewPasswordFormular(
123122
/**
124123
* Save new Password.
125124
*
126-
* @param userAccountForm
127-
* @param result
128-
* @param confirmId
129-
* @param model
125+
* @param userAccountForm UserAccountForm
126+
* @param result BindingResult
127+
* @param confirmId String
128+
* @param model Model
129+
*
130130
* @return Info Page for success or back to formular with error messages.
131131
*/
132-
@PreAuthorize("isAnonymous()")
133-
@RequestMapping(path = "/resetPassword/confirm/{confirmId}", method = RequestMethod.POST)
132+
@RequestMapping(path = "/confirm/{confirmId}", method = RequestMethod.POST)
134133
public final String enterNewPasswordPost(
135134
@Valid UserAccountForm userAccountForm,
136135
BindingResult result,

src/main/java/org/woehlke/java/simpleworklist/domain/UserRegistrationController.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import lombok.extern.slf4j.Slf4j;
44
import org.springframework.beans.factory.annotation.Autowired;
5-
import org.springframework.security.access.prepost.PreAuthorize;
65
import org.springframework.stereotype.Controller;
76
import org.springframework.ui.Model;
87
import org.springframework.validation.BindingResult;
@@ -23,16 +22,16 @@
2322
@RequestMapping(path = "/user/register")
2423
public class UserRegistrationController {
2524

26-
private final UserAccountService userAccountService;
2725
private final UserAccountRegistrationService userAccountRegistrationService;
26+
private final UserAccountService userAccountService;
2827

2928
@Autowired
3029
public UserRegistrationController(
31-
UserAccountService userAccountService,
32-
UserAccountRegistrationService userAccountRegistrationService
30+
UserAccountRegistrationService userAccountRegistrationService,
31+
UserAccountService userAccountService
3332
) {
34-
this.userAccountService = userAccountService;
3533
this.userAccountRegistrationService = userAccountRegistrationService;
34+
this.userAccountService = userAccountService;
3635
}
3736

3837
/**
@@ -42,8 +41,7 @@ public UserRegistrationController(
4241
* @param model Model
4342
* @return Formular for entering Email-Address for Registration
4443
*/
45-
@PreAuthorize("isAnonymous()")
46-
@RequestMapping(path = "/", method = RequestMethod.GET)
44+
@RequestMapping(path = "/form", method = RequestMethod.GET)
4745
public final String registerGet(Model model) {
4846
log.info("registerGet");
4947
UserAccountRegistrationForm userAccountRegistrationForm = new UserAccountRegistrationForm();
@@ -59,8 +57,7 @@ public final String registerGet(Model model) {
5957
* @param model Model
6058
* @return info page at success or return to form with error messages.
6159
*/
62-
@PreAuthorize("isAnonymous()")
63-
@RequestMapping(path = "/", method = RequestMethod.POST)
60+
@RequestMapping(path = "/form", method = RequestMethod.POST)
6461
public final String registerPost(
6562
@Valid UserAccountRegistrationForm userAccountRegistrationForm,
6663
BindingResult result,
@@ -105,7 +102,6 @@ public final String registerPost(
105102
* @param model Model
106103
* @return Formular for Entering Account Task or Error Messages.
107104
*/
108-
@PreAuthorize("isAnonymous()")
109105
@RequestMapping(path = "/confirm/{confirmId}", method = RequestMethod.GET)
110106
public final String registerConfirmGet(
111107
@PathVariable String confirmId,
@@ -134,7 +130,6 @@ public final String registerConfirmGet(
134130
* @param model Model
135131
* @return login page at success or page with error messages.
136132
*/
137-
@PreAuthorize("isAnonymous()")
138133
@RequestMapping(path = "/confirm/{confirmId}", method = RequestMethod.POST)
139134
public final String registerConfirmPost(
140135
@PathVariable String confirmId,

src/main/java/org/woehlke/java/simpleworklist/domain/db/user/account/UserAccountServiceImpl.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import org.springframework.data.domain.Page;
1010
import org.springframework.data.domain.Pageable;
11-
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
1211
import org.springframework.security.crypto.password.PasswordEncoder;
1312
import org.springframework.stereotype.Service;
1413
import org.springframework.transaction.annotation.Propagation;
@@ -33,13 +32,15 @@ public class UserAccountServiceImpl implements UserAccountService {
3332
public UserAccountServiceImpl(
3433
UserAccountRepository userAccountRepository,
3534
ChatMessageRepository userMessageRepository,
36-
ContextRepository contextRepository
35+
ContextRepository contextRepository,
36+
PasswordEncoder encoder
3737
) {
3838
this.userAccountRepository = userAccountRepository;
3939
this.userMessageRepository = userMessageRepository;
4040
this.contextRepository = contextRepository;
41-
int strength = 10;
42-
this.encoder = new BCryptPasswordEncoder(strength);
41+
//int strength = this.simpleworklistProperties.getWebSecurity().getStrengthBCryptPasswordEncoder();
42+
//this.encoder = new BCryptPasswordEncoder(strength);
43+
this.encoder = encoder;
4344
}
4445

4546
public boolean isEmailAvailable(String email) {

src/main/resources/templates/user/login/loginForm.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ <h2><small th:utext="#{user.loginForm.h2}">Your Todo-List for Getting Things Don
5858
</button>
5959
</span>
6060
<span class="col-md-4 col-4 m-2 pe-2 align-middle text-right align-self-center">
61-
<a id="registerButton" th:href="@{/user/register/}"
61+
<a id="registerButton" th:href="@{/user/register/form}"
6262
class="btn btn-outline-secondary btn-sm align-middle text-right">
6363
<i class="fas fa-user"></i><span th:utext="#{user.loginForm.register}"></span>
6464
</a>
6565
</span>
6666
<span class="col-md-4 col-4 m-2 pe-2 align-middle text-right align-self-center">
67-
<a id="passwordResetButton" th:href="@{/user/resetPassword}"
67+
<a id="passwordResetButton" th:href="@{/user/resetPassword/form}"
6868
class="btn btn-outline-secondary btn-sm align-middle text-right align-self-center">
6969
<i class="fas fa-question-circle"></i><span th:utext="#{user.loginForm.passwordReset}"></span>
7070
</a>

src/main/resources/templates/user/register/registerForm.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h1>
1818
</div>
1919

2020
<div th:fragment="mytwcontent">
21-
<form id="formId" th:action="@{/user/register/}" th:object="${userAccountRegistrationForm}" method="post">
21+
<form id="formId" th:action="@{/user/register/form}" th:object="${userAccountRegistrationForm}" method="post">
2222
<div class="card">
2323
<div class="card-header">
2424
<span th:utext="#{user.loginForm.register}">register as new user</span>

src/main/resources/templates/user/resetPassword/resetPasswordForm.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h1>
1818
</div>
1919

2020
<div th:fragment="mytwcontent">
21-
<form id="formId" th:action="@{/user/resetPassword}" th:object="${userAccountRegistrationForm}" method="post">
21+
<form id="formId" th:action="@{/user/resetPassword/form}" th:object="${userAccountRegistrationForm}" method="post">
2222
<div class="card">
2323
<div class="card-header">
2424
<span th:utext="#{user.resetPasswordForm.h1}">Password Reset</span>

0 commit comments

Comments
 (0)