From a0727bbda0db3404f04b40b3e6e64c1678e122b7 Mon Sep 17 00:00:00 2001 From: egmp777 Date: Mon, 25 Aug 2014 14:07:34 -0500 Subject: [PATCH] Spring Registration Code --- .../.classpath | 6 +- spring-security-login-error-handling/.project | 8 +- spring-security-login-error-handling/pom.xml | 23 ----- .../persistence/dao/UserRepository.java | 3 +- .../org/baeldung/persistence/model/Role.java | 90 ++++++++++--------- .../org/baeldung/persistence/model/User.java | 20 ++--- .../service/EmailExistsException.java | 4 +- .../persistence/service/PasswordMatches.java | 22 +++++ .../service/PasswordMatchesValidator.java | 16 ++++ .../service/RepositoryService.java | 21 +++-- .../baeldung/persistence/service/UserDto.java | 22 +++++ .../persistence/service/UserService.java | 3 +- .../persistence/service/UserValidator.java | 33 ------- .../service/UsernameValidator.java | 28 ++++++ .../persistence/service/ValidUsername.java | 24 +++++ .../java/org/baeldung/spring/MvcConfig.java | 18 ++-- .../controller/RegistrationController.java | 36 +++----- .../src/main/resources/application.properties | 1 + .../src/main/resources/messages_en.properties | 16 +++- .../main/resources/messages_es_ES.properties | 16 +++- .../src/main/resources/webSecurityConfig.xml | 6 +- .../src/main/webapp/WEB-INF/view/admin.jsp | 19 ++-- .../src/main/webapp/WEB-INF/view/console.jsp | 12 +-- .../src/main/webapp/WEB-INF/view/home.jsp | 11 +-- .../src/main/webapp/WEB-INF/view/homepage.jsp | 10 +-- .../webapp/WEB-INF/view/invalidSession.jsp | 1 - .../src/main/webapp/WEB-INF/view/login.jsp | 36 ++++---- .../src/main/webapp/WEB-INF/view/logout.jsp | 3 +- .../main/webapp/WEB-INF/view/registration.jsp | 5 ++ .../webapp/WEB-INF/view/successRegister.jsp | 8 +- 30 files changed, 295 insertions(+), 226 deletions(-) create mode 100644 spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/PasswordMatches.java create mode 100644 spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/PasswordMatchesValidator.java delete mode 100644 spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UserValidator.java create mode 100644 spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UsernameValidator.java create mode 100644 spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/ValidUsername.java diff --git a/spring-security-login-error-handling/.classpath b/spring-security-login-error-handling/.classpath index 1151b0d257..5cd1e45c53 100644 --- a/spring-security-login-error-handling/.classpath +++ b/spring-security-login-error-handling/.classpath @@ -17,16 +17,18 @@ - + - + + + diff --git a/spring-security-login-error-handling/.project b/spring-security-login-error-handling/.project index 818a1e1a48..47dec50119 100644 --- a/spring-security-login-error-handling/.project +++ b/spring-security-login-error-handling/.project @@ -26,7 +26,7 @@ - org.eclipse.wst.validation.validationbuilder + org.jboss.tools.jst.web.kb.kbbuilder @@ -40,6 +40,11 @@ + + org.eclipse.wst.validation.validationbuilder + + + org.eclipse.jem.workbench.JavaEMFNature @@ -50,5 +55,6 @@ org.eclipse.wst.common.project.facet.core.nature org.eclipse.wst.jsdt.core.jsNature org.hibernate.eclipse.console.hibernateNature + org.jboss.tools.jst.web.kb.kbnature diff --git a/spring-security-login-error-handling/pom.xml b/spring-security-login-error-handling/pom.xml index 53d446cc99..f3dd7e2fb9 100644 --- a/spring-security-login-error-handling/pom.xml +++ b/spring-security-login-error-handling/pom.xml @@ -7,13 +7,11 @@ spring-security-login-and-registration war 1.0.0-BUILD-SNAPSHOT - org.springframework.boot spring-boot-starter-parent 1.1.4.RELEASE - @@ -29,9 +27,6 @@ org.springframework spring-context-support - - - org.slf4j @@ -40,57 +35,47 @@ ch.qos.logback logback-classic - - org.slf4j jcl-over-slf4j - org.slf4j log4j-over-slf4j - javax.inject javax.inject ${javax.inject.version} - javax.servlet javax.servlet-api - javax.servlet.jsp javax.servlet.jsp-api ${javax.servlet.jsp-api.version} - javax.servlet jstl - org.springframework.security spring-security-taglibs - junit junit test - org.springframework.data @@ -104,7 +89,6 @@ org.hibernate hibernate-validator - mysql @@ -129,7 +113,6 @@ ${guava.version} - spring-security-login-and-registration @@ -144,22 +127,16 @@ 3.1.1.RELEASE 3.2.4.RELEASE 1.6.10 - 1.7.6 1.1.1 - 2.3.2-b01 - 1 - 1.4.1.RELEASE - 17.0 - diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/dao/UserRepository.java b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/dao/UserRepository.java index d36cd1ba2f..373a28b476 100644 --- a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/dao/UserRepository.java +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/dao/UserRepository.java @@ -3,7 +3,6 @@ package org.baeldung.persistence.dao; import org.springframework.data.jpa.repository.JpaRepository; import org.baeldung.persistence.model.User; - -public interface UserRepository extends JpaRepository{ +public interface UserRepository extends JpaRepository { public User findByUsername(String username); } 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 f0a08885f5..ceec68a9f3 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 @@ -11,52 +11,56 @@ import javax.persistence.JoinColumn; import javax.persistence.OneToOne; import javax.persistence.Table; - -@Entity(name="role") +@Entity(name = "role") @Table(name = "role") public class Role { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private Long id; + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + @OneToOne(targetEntity = User.class, fetch = FetchType.EAGER, cascade = CascadeType.ALL) + @JoinColumn(name = "user_id") + private User user; + @Column(name = "role") + private Integer role; - - @OneToOne(targetEntity = User.class, fetch = FetchType.EAGER, cascade = CascadeType.ALL) - @JoinColumn(name = "user_id") - private User user; - - @Column(name="role") - private Integer role; + public Role() { + super(); - public Role(){ - super(); - - } - public Role(Integer role){ - super(); - this.role = role; - } - public Role(Integer role, User user){ - super(); - this.role = role; - this.user = user; - } - public Long getId() { - return id; - } - public void setId(Long id) { - this.id = id; - } - public User getUser() { - return user; - } - public void setUser(User user) { - this.user = user; - } - public Integer getRole() { - return role; - } - public void setRole(Integer role) { - this.role = role; - } + } + + public Role(Integer role) { + super(); + this.role = role; + } + + public Role(Integer role, User user) { + super(); + this.role = role; + this.user = user; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public Integer getRole() { + return role; + } + + public void setRole(Integer role) { + this.role = role; + } } \ No newline at end of file diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/model/User.java b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/model/User.java index 4fe8c9986f..33851c9fa5 100644 --- a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/model/User.java +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/model/User.java @@ -17,17 +17,16 @@ public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; - @Column(name="firstName") + @Column(name = "firstName") private String firstName; - @Column(name="lastName") + @Column(name = "lastName") private String lastName; - @Column(name="username") + @Column(name = "username") private String username; - @Column(name="password") + @Column(name = "password") private String password; - - - @OneToOne(mappedBy = "user",fetch = FetchType.EAGER, cascade = CascadeType.ALL) + + @OneToOne(mappedBy = "user", fetch = FetchType.EAGER, cascade = CascadeType.ALL) private Role role; public Long getId() { @@ -77,8 +76,7 @@ public class User { public void setRole(Role role) { this.role = role; } - - + @Override public int hashCode() { final int prime = 31; @@ -100,11 +98,11 @@ public class User { return false; return true; } + @Override public String toString() { final StringBuilder builder = new StringBuilder(); - builder.append("User [firstName=").append(firstName).append("]"). - append("[lastName=").append(lastName).append("]").append("[username").append(username).append("]"); + builder.append("User [firstName=").append(firstName).append("]").append("[lastName=").append(lastName).append("]").append("[username").append(username).append("]"); return builder.toString(); } } \ No newline at end of file diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/EmailExistsException.java b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/EmailExistsException.java index edb44bd598..ad00388f06 100644 --- a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/EmailExistsException.java +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/EmailExistsException.java @@ -1,8 +1,8 @@ package org.baeldung.persistence.service; @SuppressWarnings("serial") -public class EmailExistsException extends Throwable{ - +public class EmailExistsException extends Throwable { + public EmailExistsException(String message) { super(message); } diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/PasswordMatches.java b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/PasswordMatches.java new file mode 100644 index 0000000000..eb98a73d2c --- /dev/null +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/PasswordMatches.java @@ -0,0 +1,22 @@ +package org.baeldung.persistence.service; + +import javax.validation.Constraint; +import javax.validation.Payload; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +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}) +@Retention(RUNTIME) +@Constraint(validatedBy = PasswordMatchesValidator.class) +@Documented +public @interface PasswordMatches { + + String message() default "Passwords don't match"; + Class[] groups() default {}; + Class[] payload() default {}; +} diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/PasswordMatchesValidator.java b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/PasswordMatchesValidator.java new file mode 100644 index 0000000000..18a70637e5 --- /dev/null +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/PasswordMatchesValidator.java @@ -0,0 +1,16 @@ +package org.baeldung.persistence.service; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class PasswordMatchesValidator implements ConstraintValidator { + + @Override + public void initialize(PasswordMatches constraintAnnotation) { + } + @Override + public boolean isValid(Object obj, ConstraintValidatorContext context){ + UserDto user = (UserDto) obj; + return user.getPassword().equals(user.getMatchingPassword()); + } +} diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/RepositoryService.java b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/RepositoryService.java index e5fbc3622d..06730f1b65 100644 --- a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/RepositoryService.java +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/RepositoryService.java @@ -10,33 +10,32 @@ import org.springframework.stereotype.Service; @Service public class RepositoryService implements UserService { - @Autowired + @Autowired private UserRepository repository; - @Autowired private Environment env; - + @Autowired - public RepositoryService( UserRepository repository) { + public RepositoryService(UserRepository repository) { this.repository = repository; - } - + } + @Transactional @Override public User registerNewUserAccount(UserDto userAccountData) throws EmailExistsException { if (emailExist(userAccountData.getUsername())) { - + throw new EmailExistsException("There is an account with that email adress: " + userAccountData.getUsername()); - } - User user = new User(); + } + User user = new User(); user.setFirstName(userAccountData.getFirstName()); user.setLastName(userAccountData.getLastName()); user.setPassword(userAccountData.getPassword()); user.setUsername(userAccountData.getUsername()); user.setRole(new Role(userAccountData.getRole(), user)); - return repository.save(user); + return repository.save(user); } - + private boolean emailExist(String email) { User user = repository.findByUsername(email); if (user != null) { 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 05056c7eb7..fbd968a834 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 @@ -1,10 +1,26 @@ package org.baeldung.persistence.service; +import javax.validation.constraints.NotNull; +import org.hibernate.validator.constraints.NotEmpty; +@PasswordMatches public class UserDto { + @NotNull + @NotEmpty private String firstName; + @NotNull + @NotEmpty private String lastName; + @NotNull + @NotEmpty private String password; + @NotNull + @NotEmpty + private String matchingPassword; + @ValidUsername + @NotNull + @NotEmpty private String username; + private Integer role; public Integer getRole() { @@ -37,6 +53,12 @@ public class UserDto { public void setPassword(String password) { this.password = password; } + public String getMatchingPassword() { + return matchingPassword; + } + public void setMatchingPassword(String matchingPassword) { + this.matchingPassword = matchingPassword; + } @Override public String toString() { final StringBuilder builder = new StringBuilder(); 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 b51bda5b3b..44187e2c85 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 @@ -1,8 +1,9 @@ package org.baeldung.persistence.service; + import org.baeldung.persistence.model.User; public interface UserService { - + public User registerNewUserAccount(UserDto userAccountData) throws EmailExistsException; } diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UserValidator.java b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UserValidator.java deleted file mode 100644 index ac6bbb89f3..0000000000 --- a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UserValidator.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.baeldung.persistence.service; - -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -public class UserValidator implements Validator { - private Pattern pattern; - private Matcher matcher; - private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; - - @Override - public boolean supports(Class clazz) { - return UserDto.class.isAssignableFrom(clazz); - } - - @Override - public void validate(Object obj, Errors errors) { - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "message.firstName", "Firstname is required."); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "message.lastName", "LastName is required."); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "message.password", "LastName is required."); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "username", "message.username", "UserName is required."); - } - - public boolean validateEmail(String email) { - pattern = Pattern.compile(EMAIL_PATTERN); - matcher = pattern.matcher(email); - return matcher.matches(); - - } -} diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UsernameValidator.java b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UsernameValidator.java new file mode 100644 index 0000000000..67a7753801 --- /dev/null +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UsernameValidator.java @@ -0,0 +1,28 @@ +package org.baeldung.persistence.service; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +public class UsernameValidator implements ConstraintValidator { + private Pattern pattern; + private Matcher matcher; + private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@" + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$"; + + @Override + public void initialize(ValidUsername constraintAnnotation) { + } + + @Override + public boolean isValid(String username, ConstraintValidatorContext context) { + return (validateEmail(username)); + } + + public boolean validateEmail(String email) { + pattern = Pattern.compile(EMAIL_PATTERN); + matcher = pattern.matcher(email); + return matcher.matches(); + } +} diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/ValidUsername.java b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/ValidUsername.java new file mode 100644 index 0000000000..9aed811713 --- /dev/null +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/ValidUsername.java @@ -0,0 +1,24 @@ +package org.baeldung.persistence.service; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target({ TYPE, FIELD, ANNOTATION_TYPE }) +@Retention(RUNTIME) +@Constraint(validatedBy = UsernameValidator.class) +@Documented +public @interface ValidUsername { + + String message() default "Invalid Email"; + + Class[] groups() default {}; + + Class[] payload() default {}; +} 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 4747821d1f..1aa0a4e27f 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 @@ -1,7 +1,9 @@ package org.baeldung.spring; import java.util.Locale; -import org.baeldung.persistence.service.UserValidator; + +import org.baeldung.persistence.service.PasswordMatchesValidator; +import org.baeldung.persistence.service.UsernameValidator; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -85,11 +87,17 @@ public class MvcConfig extends WebMvcConfigurerAdapter { messageSource.setCacheSeconds(0); return messageSource; } - + @Bean - public UserValidator userValidator() { - UserValidator userValidator = new UserValidator(); - return userValidator; + public UsernameValidator usernameValidator() { + UsernameValidator userNameValidator = new UsernameValidator(); + return userNameValidator; } + @Bean + public PasswordMatchesValidator passwordMatchesValidator() { + PasswordMatchesValidator passwordMatchesValidator = new PasswordMatchesValidator(); + return passwordMatchesValidator; + } + } \ No newline at end of file diff --git a/spring-security-login-error-handling/src/main/java/org/baeldung/web/controller/RegistrationController.java b/spring-security-login-error-handling/src/main/java/org/baeldung/web/controller/RegistrationController.java index a8494efb2d..443f6b0a91 100644 --- a/spring-security-login-error-handling/src/main/java/org/baeldung/web/controller/RegistrationController.java +++ b/spring-security-login-error-handling/src/main/java/org/baeldung/web/controller/RegistrationController.java @@ -5,46 +5,33 @@ import org.baeldung.persistence.model.User; import org.baeldung.persistence.service.EmailExistsException; import org.baeldung.persistence.service.UserDto; import org.baeldung.persistence.service.UserService; -import org.baeldung.persistence.service.UserValidator; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; -import org.springframework.mail.javamail.JavaMailSender; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.validation.Errors; -import org.springframework.web.bind.WebDataBinder; -import org.springframework.web.bind.annotation.InitBinder; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.ModelAndView; - @Controller public class RegistrationController { - private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationController.class); + private final Logger LOGGER = LoggerFactory.getLogger(getClass()); private UserService service; @Autowired private MessageSource messages; - @Autowired - private JavaMailSender mailSender; - @Autowired - private UserValidator validator; - - @InitBinder - protected void initBinder(WebDataBinder binder) { - binder.setValidator(this.validator); - } + @Autowired public RegistrationController(UserService service) { this.service = service; } - + @RequestMapping(value = "/user/registration", method = RequestMethod.GET) public String showRegistrationForm(WebRequest request, Model model) { LOGGER.debug("Rendering registration page."); @@ -52,16 +39,14 @@ public class RegistrationController { model.addAttribute("user", userDto); return "registration"; } - + @RequestMapping(value = "/user/registration", method = RequestMethod.POST) public ModelAndView registerUserAccount(@ModelAttribute("user") @Valid UserDto userAccountData, BindingResult result, WebRequest request, Errors errors) { - boolean goodEmailCheck = validator.validateEmail(userAccountData.getUsername()); - if (!goodEmailCheck) - result.rejectValue("username", "message.badEmail"); - User registered = null; + + User registered = new User(); if (!result.hasErrors()) registered = createUserAccount(userAccountData, result); - if (registered == null && !userAccountData.getUsername().isEmpty() && goodEmailCheck) { + if (registered == null) { result.rejectValue("username", "message.regError"); } if (result.hasErrors()) { @@ -71,15 +56,14 @@ public class RegistrationController { } } - + private User createUserAccount(UserDto userAccountData, BindingResult result) { User registered = null; try { registered = service.registerNewUserAccount(userAccountData); } catch (EmailExistsException e) { return null; - } + } return registered; - } + } } - diff --git a/spring-security-login-error-handling/src/main/resources/application.properties b/spring-security-login-error-handling/src/main/resources/application.properties index 1144b5f03f..425018eea6 100644 --- a/spring-security-login-error-handling/src/main/resources/application.properties +++ b/spring-security-login-error-handling/src/main/resources/application.properties @@ -8,3 +8,4 @@ init-db=false hibernate.dialect=org.hibernate.dialect.MySQLDialect hibernate.show_sql=false hibernate.hbm2ddl.auto=create-drop + diff --git a/spring-security-login-error-handling/src/main/resources/messages_en.properties b/spring-security-login-error-handling/src/main/resources/messages_en.properties index de6630ec92..0d4393fb5e 100644 --- a/spring-security-login-error-handling/src/main/resources/messages_en.properties +++ b/spring-security-login-error-handling/src/main/resources/messages_en.properties @@ -14,4 +14,18 @@ label.user.email=Email label.user.firstName=First name label.user.lastName=Last name label.user.password=Password -label.login=Login here \ No newline at end of file +label.login=Login here +ValidUsername.user.username=Invalid Username (Email) +UniqueUsername.user.username=An account with that username/email already exists +NotNull.user.firstName=First name required +NotEmpty.user.firstName=First name required +NotNull.user.lastName=Last name required +NotEmpty.user.lastName=Last name required +NotNull.user.username=Username(Email) required +NotEmpty.user.username=Username(Email) required +NotNull.user.password=Password required +NotEmpty.user.password=Password required +NotNull.user.matchingPassword=Required +NotEmpty.user.matchingPassword=Required +PasswordMatches.user:Password does not match! +Email.user.username=Invalid Username (Email) \ No newline at end of file diff --git a/spring-security-login-error-handling/src/main/resources/messages_es_ES.properties b/spring-security-login-error-handling/src/main/resources/messages_es_ES.properties index 3f870472a4..2084b14667 100644 --- a/spring-security-login-error-handling/src/main/resources/messages_es_ES.properties +++ b/spring-security-login-error-handling/src/main/resources/messages_es_ES.properties @@ -14,4 +14,18 @@ label.user.email=Email label.user.firstName=Nombre label.user.lastName=Apellido label.user.password=Clave -label.login=Autehtifiquese aqui \ No newline at end of file +label.login=Autehtifiquese aqui +ValidUsername.user.username=Email no es valido +UniqueUsername.user.username=Ya existe una cuenta con ese nombre de usuario +NotNull.user.firstName=Por favor ingrese su nombre +NotEmpty.user.firstName=Por favor ingrese su nombre +NotNull.user.lastName=Por favor ingrese su apellido +NotEmpty.user.lastName=Por favor ingrese su apellido +NotNull.user.username=Por favor ingrese su cuenta de email +NotEmpty.user.username=Por favor ingrese su cuenta de email +NotNull.user.password=Por favor ingrese su clave +NotEmpty.user.password=Por favor ingrese su clave +NotNull.user.matchingPassword=Campo obligatirio +NotEmpty.user.matchingPassword=Campo obligatrio +PasswordMatches.user:Las claves no coinciden! +Email.user.username=Email no es valido 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 7c362885ae..70e80d9023 100644 --- a/spring-security-login-error-handling/src/main/resources/webSecurityConfig.xml +++ b/spring-security-login-error-handling/src/main/resources/webSecurityConfig.xml @@ -5,8 +5,6 @@ xsi:schemaLocation=" http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd"> - - @@ -16,7 +14,6 @@ - - + -<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> +<%@ taglib prefix="sec" + uri="http://www.springframework.org/security/tags"%> <%@taglib uri="http://www.springframework.org/tags" prefix="spring"%> - - + + " rel="stylesheet"> - - - - -

Hello Admin

-
- +

Hello Admin

+
+ ">Logout ">Home - - diff --git a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/console.jsp b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/console.jsp index b82842169f..87aeedc662 100644 --- a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/console.jsp +++ b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/console.jsp @@ -1,25 +1,21 @@ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> -<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %> +<%@ taglib prefix="security" + uri="http://www.springframework.org/security/tags"%> " rel="stylesheet"> -

This is the landing page for the admin

- This text is only visible to a user -
+
- This text is only visible to an admin -
+
- ">Logout ">Administrator Page - \ No newline at end of file diff --git a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/home.jsp b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/home.jsp index 4d54257bff..058d67a4ba 100644 --- a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/home.jsp +++ b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/home.jsp @@ -1,14 +1,11 @@ -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> -<%@ page session="true" %> +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> +<%@ page session="true"%> " rel="stylesheet"> - Home +Home -

- Welcome back home! -

- +

Welcome back home!

diff --git a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/homepage.jsp b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/homepage.jsp index c13acb7756..c6135a3372 100644 --- a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/homepage.jsp +++ b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/homepage.jsp @@ -1,13 +1,12 @@ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> -<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %> -<%@ page session="true" %> +<%@ taglib prefix="sec" + uri="http://www.springframework.org/security/tags"%> +<%@ page session="true"%> " rel="stylesheet"> - -

This is the homepage for the user

@@ -23,8 +22,5 @@ ">Logout ">Home ">Administrator Page - - - \ No newline at end of file diff --git a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/invalidSession.jsp b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/invalidSession.jsp index 8aa9d7b49f..3b03726733 100644 --- a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/invalidSession.jsp +++ b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/invalidSession.jsp @@ -9,6 +9,5 @@

- diff --git a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/login.jsp b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/login.jsp index 97c8b3317d..a6a828515a 100644 --- a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/login.jsp +++ b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/login.jsp @@ -38,32 +38,28 @@ } -

Login

English | Spanish -
- - - - - - - - - - - - - -
User:
Password:
- -
+
+ + + + + + + + + + + + +
User:
Password:
+

Current Locale : ${pageContext.response.locale}
">Sign Up - \ No newline at end of file diff --git a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/logout.jsp b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/logout.jsp index a234f11d09..ed05de3458 100644 --- a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/logout.jsp +++ b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/logout.jsp @@ -11,7 +11,7 @@ - +
@@ -20,7 +20,6 @@ Logged Out - Login \ No newline at end of file diff --git a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/registration.jsp b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/registration.jsp index 979da11427..a4c40d670b 100644 --- a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/registration.jsp +++ b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/registration.jsp @@ -35,6 +35,11 @@ + + + + + diff --git a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/successRegister.jsp b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/successRegister.jsp index ca676a4999..d937128a59 100644 --- a/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/successRegister.jsp +++ b/spring-security-login-error-handling/src/main/webapp/WEB-INF/view/successRegister.jsp @@ -13,8 +13,10 @@ Registration Success - -

- "> +
+ +
+ "> \ No newline at end of file