diff --git a/spring-security-login-error-handling/pom.xml b/spring-security-login-error-handling/pom.xml index 68f217afc5..45ff89f52a 100644 --- a/spring-security-login-error-handling/pom.xml +++ b/spring-security-login-error-handling/pom.xml @@ -7,11 +7,13 @@ spring-security-login-and-registration war 1.0.0-BUILD-SNAPSHOT + org.springframework.boot spring-boot-starter-parent - 1.1.5.RELEASE + 1.1.6.RELEASE + diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/model/Role.java b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/model/Role.java index bb4b86e32f..dcbdd8436b 100644 --- a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/model/Role.java +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/model/Role.java @@ -23,7 +23,6 @@ public class Role { @JoinColumn(name = "user_id") private User user; - @Column(name = "role") private Integer role; @@ -66,7 +65,7 @@ public class Role { public void setRole(Integer role) { this.role = role; } - + @Override public int hashCode() { final int prime = 31; diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UserDto.java b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UserDto.java index af299520fd..c8d63fb891 100644 --- a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UserDto.java +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UserDto.java @@ -5,6 +5,7 @@ import javax.validation.constraints.NotNull; import org.baeldung.validation.service.PasswordMatches; import org.baeldung.validation.service.ValidEmail; import org.hibernate.validator.constraints.NotEmpty; + @PasswordMatches public class UserDto { @NotNull @@ -23,6 +24,7 @@ public class UserDto { @NotNull @NotEmpty private String email; + public String getEmail() { return email; } @@ -64,9 +66,11 @@ public class UserDto { public void setPassword(String password) { this.password = password; } + public String getMatchingPassword() { return matchingPassword; } + public void setMatchingPassword(String matchingPassword) { this.matchingPassword = matchingPassword; } diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UserService.java b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UserService.java index bb84fc81ab..6bde98bf4d 100644 --- a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UserService.java +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UserService.java @@ -10,15 +10,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @Service -public class UserService implements IUserService { +public class UserService implements IUserService { @Autowired private UserRepository repository; - + @Transactional @Override public User registerNewUserAccount(UserDto accountDto) throws EmailExistsException { if (emailExist(accountDto.getEmail())) { - throw new EmailExistsException("There is an account with that email adress: " + accountDto.getEmail()); } User user = new User(); @@ -26,8 +25,8 @@ public class UserService implements IUserService { user.setLastName(accountDto.getLastName()); user.setPassword(accountDto.getPassword()); user.setEmail(accountDto.getEmail()); - //ROLE WILL ALWAYS BE USER. HARDCODING IT - user.setRole(new Role(Integer.valueOf(1),user)); + // ROLE WILL ALWAYS BE USER. HARDCODING IT + user.setRole(new Role(Integer.valueOf(1), user)); return repository.save(user); } diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/spring/MvcConfig.java b/spring-security-login-error-handling/src/main/java/org/baeldung/spring/MvcConfig.java index 429ed2342d..47c23ace50 100644 --- a/spring-security-login-error-handling/src/main/java/org/baeldung/spring/MvcConfig.java +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/spring/MvcConfig.java @@ -83,7 +83,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter { messageSource.setCacheSeconds(0); return messageSource; } - + @Bean public EmailValidator usernameValidator() { EmailValidator userNameValidator = new EmailValidator(); diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/validation/service/PasswordMatches.java b/spring-security-login-error-handling/src/main/java/org/baeldung/validation/service/PasswordMatches.java index 5499921aed..63cfb297f0 100644 --- a/spring-security-login-error-handling/src/main/java/org/baeldung/validation/service/PasswordMatches.java +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/validation/service/PasswordMatches.java @@ -10,13 +10,15 @@ import static java.lang.annotation.ElementType.ANNOTATION_TYPE; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.RetentionPolicy.RUNTIME; -@Target({TYPE,ANNOTATION_TYPE}) +@Target({ TYPE, ANNOTATION_TYPE }) @Retention(RUNTIME) @Constraint(validatedBy = PasswordMatchesValidator.class) @Documented public @interface PasswordMatches { - + String message() default "Passwords don't match"; - Class[] groups() default {}; + + Class[] groups() default {}; + Class[] payload() default {}; } diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/validation/service/PasswordMatchesValidator.java b/spring-security-login-error-handling/src/main/java/org/baeldung/validation/service/PasswordMatchesValidator.java index 10fa21d02e..99f569957b 100644 --- a/spring-security-login-error-handling/src/main/java/org/baeldung/validation/service/PasswordMatchesValidator.java +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/validation/service/PasswordMatchesValidator.java @@ -6,13 +6,14 @@ import javax.validation.ConstraintValidatorContext; import org.baeldung.persistence.service.UserDto; public class PasswordMatchesValidator implements ConstraintValidator { - + @Override - public void initialize(PasswordMatches constraintAnnotation) { + public void initialize(PasswordMatches constraintAnnotation) { } + @Override - public boolean isValid(Object obj, ConstraintValidatorContext context){ + public boolean isValid(Object obj, ConstraintValidatorContext context) { UserDto user = (UserDto) obj; - return user.getPassword().equals(user.getMatchingPassword()); - } + return user.getPassword().equals(user.getMatchingPassword()); + } } diff --git a/spring-security-login-error-handling/src/main/resources/webSecurityConfig.xml b/spring-security-login-error-handling/src/main/resources/webSecurityConfig.xml index d584ff342f..2dd759f8c3 100644 --- a/spring-security-login-error-handling/src/main/resources/webSecurityConfig.xml +++ b/spring-security-login-error-handling/src/main/resources/webSecurityConfig.xml @@ -1,6 +1,5 @@ - - - - + + - + + + - - - + - + + \ No newline at end of file