small cleanup

This commit is contained in:
eugenp 2014-09-27 22:18:28 +03:00
parent eb55fdbaad
commit 686fdd8ee2
8 changed files with 34 additions and 33 deletions

View File

@ -7,11 +7,13 @@
<name>spring-security-login-and-registration</name> <name>spring-security-login-and-registration</name>
<packaging>war</packaging> <packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version> <version>1.0.0-BUILD-SNAPSHOT</version>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.5.RELEASE</version> <version>1.1.6.RELEASE</version>
</parent> </parent>
<dependencies> <dependencies>
<!-- Spring --> <!-- Spring -->
<dependency> <dependency>

View File

@ -23,7 +23,6 @@ public class Role {
@JoinColumn(name = "user_id") @JoinColumn(name = "user_id")
private User user; private User user;
@Column(name = "role") @Column(name = "role")
private Integer role; private Integer role;

View File

@ -5,6 +5,7 @@ import javax.validation.constraints.NotNull;
import org.baeldung.validation.service.PasswordMatches; import org.baeldung.validation.service.PasswordMatches;
import org.baeldung.validation.service.ValidEmail; import org.baeldung.validation.service.ValidEmail;
import org.hibernate.validator.constraints.NotEmpty; import org.hibernate.validator.constraints.NotEmpty;
@PasswordMatches @PasswordMatches
public class UserDto { public class UserDto {
@NotNull @NotNull
@ -23,6 +24,7 @@ public class UserDto {
@NotNull @NotNull
@NotEmpty @NotEmpty
private String email; private String email;
public String getEmail() { public String getEmail() {
return email; return email;
} }
@ -64,9 +66,11 @@ public class UserDto {
public void setPassword(String password) { public void setPassword(String password) {
this.password = password; this.password = password;
} }
public String getMatchingPassword() { public String getMatchingPassword() {
return matchingPassword; return matchingPassword;
} }
public void setMatchingPassword(String matchingPassword) { public void setMatchingPassword(String matchingPassword) {
this.matchingPassword = matchingPassword; this.matchingPassword = matchingPassword;
} }

View File

@ -18,7 +18,6 @@ public class UserService implements IUserService {
@Override @Override
public User registerNewUserAccount(UserDto accountDto) throws EmailExistsException { public User registerNewUserAccount(UserDto accountDto) throws EmailExistsException {
if (emailExist(accountDto.getEmail())) { if (emailExist(accountDto.getEmail())) {
throw new EmailExistsException("There is an account with that email adress: " + accountDto.getEmail()); throw new EmailExistsException("There is an account with that email adress: " + accountDto.getEmail());
} }
User user = new User(); User user = new User();

View File

@ -17,6 +17,8 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
public @interface PasswordMatches { public @interface PasswordMatches {
String message() default "Passwords don't match"; String message() default "Passwords don't match";
Class<?>[] groups() default {}; Class<?>[] groups() default {};
Class<? extends Payload>[] payload() default {}; Class<? extends Payload>[] payload() default {};
} }

View File

@ -10,6 +10,7 @@ public class PasswordMatchesValidator implements ConstraintValidator<PasswordMat
@Override @Override
public void initialize(PasswordMatches constraintAnnotation) { public void initialize(PasswordMatches constraintAnnotation) {
} }
@Override @Override
public boolean isValid(Object obj, ConstraintValidatorContext context) { public boolean isValid(Object obj, ConstraintValidatorContext context) {
UserDto user = (UserDto) obj; UserDto user = (UserDto) obj;

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security" <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:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation=" xsi:schemaLocation="
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd 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="/resources/**" access="permitAll" />
<intercept-url pattern="/invalidSession*" access="isAnonymous()" /> <intercept-url pattern="/invalidSession*" access="isAnonymous()" />
<intercept-url pattern="/**" access="isAuthenticated()" /> <intercept-url pattern="/**" access="isAuthenticated()" />
<form-login login-page='/login.html' <form-login login-page='/login.html' authentication-failure-url="/login.html?error=true" authentication-success-handler-ref="myAuthenticationSuccessHandler"
authentication-failure-url="/login.html?error=true"
authentication-success-handler-ref="myAuthenticationSuccessHandler"
default-target-url="/homepage.html" /> default-target-url="/homepage.html" />
<session-management invalid-session-url="/invalidSession.html" <session-management invalid-session-url="/invalidSession.html" session-fixation-protection="none" />
session-fixation-protection="none" /> <logout invalidate-session="false" logout-success-url="/logout.html?logSucc=true" logout-url="/j_spring_security_logout" delete-cookies="JSESSIONID" />
<logout invalidate-session="false" logout-success-url="/logout.html?logSucc=true"
logout-url="/j_spring_security_logout" delete-cookies="JSESSIONID" />
</http> </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> </authentication-manager>
<beans:bean id="userDetailsService" class="org.baeldung.security.MyUserDetailsService" <beans:bean id="userDetailsService" class="org.baeldung.security.MyUserDetailsService" />
autowire="constructor" />
</beans:beans> </beans:beans>