@@ -21,7 +21,6 @@ import javax.transaction.Transactional;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
@@ -57,7 +56,7 @@ public class UserManagement {
|
||||
throw new IllegalArgumentException("User with that name already exists!");
|
||||
});
|
||||
|
||||
Password encryptedPassword = Password.encrypted(encoder.encode(password));
|
||||
var encryptedPassword = Password.encrypted(encoder.encode(password));
|
||||
|
||||
return repository.save(new User(username, encryptedPassword));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.Map;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.web.PageableDefault;
|
||||
@@ -91,7 +90,7 @@ class UserController {
|
||||
|
||||
userManagement.register(new Username(userForm.getUsername()), Password.raw(userForm.getPassword()));
|
||||
|
||||
RedirectView redirectView = new RedirectView("redirect:/users");
|
||||
var redirectView = new RedirectView("redirect:/users");
|
||||
redirectView.setPropagateQueryParams(true);
|
||||
|
||||
return redirectView;
|
||||
|
||||
@@ -15,9 +15,7 @@
|
||||
*/
|
||||
package example.users;
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
/**
|
||||
* Integration tests to bootstrap the application.
|
||||
@@ -25,6 +23,5 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest
|
||||
public abstract class AbstractIntegrationTests {}
|
||||
abstract class AbstractIntegrationTests {}
|
||||
|
||||
@@ -27,7 +27,7 @@ import static org.assertj.core.api.Assertions.*;
|
||||
* @author Divya Srivastava
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
public class UserManagementIntegrationTests extends AbstractIntegrationTests {
|
||||
class UserManagementIntegrationTests extends AbstractIntegrationTests {
|
||||
|
||||
@Autowired UserManagement userManagement;
|
||||
|
||||
@@ -35,9 +35,9 @@ public class UserManagementIntegrationTests extends AbstractIntegrationTests {
|
||||
* @see #65
|
||||
*/
|
||||
@Test
|
||||
public void encryptsPasswordWhenCreatingAUser() {
|
||||
void encryptsPasswordWhenCreatingAUser() {
|
||||
|
||||
User user = userManagement.register(new Username("olivergierke"), Password.raw("foobar"));
|
||||
var user = userManagement.register(new Username("olivergierke"), Password.raw("foobar"));
|
||||
|
||||
assertThat(user.getPassword().isEncrypted()).isTrue();
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
public class UserRepositoryIntegrationTests extends AbstractIntegrationTests {
|
||||
class UserRepositoryIntegrationTests extends AbstractIntegrationTests {
|
||||
|
||||
@Autowired UserRepository users;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class UserRepositoryIntegrationTests extends AbstractIntegrationTests {
|
||||
* @see #65
|
||||
*/
|
||||
@Test
|
||||
public void repositoryRejectsUnencryptedPassword() {
|
||||
void repositoryRejectsUnencryptedPassword() {
|
||||
Assertions.assertThrows(InvalidDataAccessApiUsageException.class, () -> {
|
||||
users.save(new User(new Username("olivergierke"), Password.raw("foobar")));
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user