small cleanup
This commit is contained in:
parent
eb55fdbaad
commit
686fdd8ee2
|
@ -7,11 +7,13 @@
|
|||
<name>spring-security-login-and-registration</name>
|
||||
<packaging>war</packaging>
|
||||
<version>1.0.0-BUILD-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.1.5.RELEASE</version>
|
||||
<version>1.1.6.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<!-- Spring -->
|
||||
<dependency>
|
||||
|
|
|
@ -23,7 +23,6 @@ public class Role {
|
|||
@JoinColumn(name = "user_id")
|
||||
private User user;
|
||||
|
||||
|
||||
@Column(name = "role")
|
||||
private Integer role;
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ public class UserService implements IUserService {
|
|||
@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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<? extends Payload>[] payload() default {};
|
||||
}
|
||||
|
|
|
@ -10,8 +10,9 @@ public class PasswordMatchesValidator implements ConstraintValidator<PasswordMat
|
|||
@Override
|
||||
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());
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/security"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
|
||||
|
@ -15,22 +14,17 @@
|
|||
<intercept-url pattern="/resources/**" access="permitAll" />
|
||||
<intercept-url pattern="/invalidSession*" access="isAnonymous()" />
|
||||
<intercept-url pattern="/**" access="isAuthenticated()" />
|
||||
<form-login login-page='/login.html'
|
||||
authentication-failure-url="/login.html?error=true"
|
||||
authentication-success-handler-ref="myAuthenticationSuccessHandler"
|
||||
<form-login login-page='/login.html' authentication-failure-url="/login.html?error=true" authentication-success-handler-ref="myAuthenticationSuccessHandler"
|
||||
default-target-url="/homepage.html" />
|
||||
<session-management invalid-session-url="/invalidSession.html"
|
||||
session-fixation-protection="none" />
|
||||
<logout invalidate-session="false" logout-success-url="/logout.html?logSucc=true"
|
||||
logout-url="/j_spring_security_logout" delete-cookies="JSESSIONID" />
|
||||
<session-management invalid-session-url="/invalidSession.html" session-fixation-protection="none" />
|
||||
<logout invalidate-session="false" logout-success-url="/logout.html?logSucc=true" logout-url="/j_spring_security_logout" delete-cookies="JSESSIONID" />
|
||||
</http>
|
||||
<beans:bean id="myAuthenticationSuccessHandler"
|
||||
class="org.baeldung.security.MySimpleUrlAuthenticationSuccessHandler" />
|
||||
<authentication-manager>
|
||||
<authentication-provider user-service-ref="userDetailsService">
|
||||
|
||||
</authentication-provider>
|
||||
<beans:bean id="myAuthenticationSuccessHandler" class="org.baeldung.security.MySimpleUrlAuthenticationSuccessHandler" />
|
||||
|
||||
<authentication-manager>
|
||||
<authentication-provider user-service-ref="userDetailsService" />
|
||||
</authentication-manager>
|
||||
<beans:bean id="userDetailsService" class="org.baeldung.security.MyUserDetailsService"
|
||||
autowire="constructor" />
|
||||
<beans:bean id="userDetailsService" class="org.baeldung.security.MyUserDetailsService" />
|
||||
|
||||
</beans:beans>
|
Loading…
Reference in New Issue