Skip to content

Commit 686fdd8

Browse files
author
eugenp
committed
small cleanup
1 parent eb55fdb commit 686fdd8

8 files changed

Lines changed: 34 additions & 33 deletions

File tree

spring-security-login-error-handling/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
<name>spring-security-login-and-registration</name>
88
<packaging>war</packaging>
99
<version>1.0.0-BUILD-SNAPSHOT</version>
10+
1011
<parent>
1112
<groupId>org.springframework.boot</groupId>
1213
<artifactId>spring-boot-starter-parent</artifactId>
13-
<version>1.1.5.RELEASE</version>
14+
<version>1.1.6.RELEASE</version>
1415
</parent>
16+
1517
<dependencies>
1618
<!-- Spring -->
1719
<dependency>

spring-security-login-error-handling/src/main/java/org/baeldung/persistence/model/Role.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public class Role {
2323
@JoinColumn(name = "user_id")
2424
private User user;
2525

26-
2726
@Column(name = "role")
2827
private Integer role;
2928

@@ -66,7 +65,7 @@ public Integer getRole() {
6665
public void setRole(Integer role) {
6766
this.role = role;
6867
}
69-
68+
7069
@Override
7170
public int hashCode() {
7271
final int prime = 31;

spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UserDto.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.baeldung.validation.service.PasswordMatches;
66
import org.baeldung.validation.service.ValidEmail;
77
import org.hibernate.validator.constraints.NotEmpty;
8+
89
@PasswordMatches
910
public class UserDto {
1011
@NotNull
@@ -23,6 +24,7 @@ public class UserDto {
2324
@NotNull
2425
@NotEmpty
2526
private String email;
27+
2628
public String getEmail() {
2729
return email;
2830
}
@@ -64,9 +66,11 @@ public String getPassword() {
6466
public void setPassword(String password) {
6567
this.password = password;
6668
}
69+
6770
public String getMatchingPassword() {
6871
return matchingPassword;
6972
}
73+
7074
public void setMatchingPassword(String matchingPassword) {
7175
this.matchingPassword = matchingPassword;
7276
}

spring-security-login-error-handling/src/main/java/org/baeldung/persistence/service/UserService.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,23 @@
1010
import org.springframework.stereotype.Service;
1111

1212
@Service
13-
public class UserService implements IUserService {
13+
public class UserService implements IUserService {
1414
@Autowired
1515
private UserRepository repository;
16-
16+
1717
@Transactional
1818
@Override
1919
public User registerNewUserAccount(UserDto accountDto) throws EmailExistsException {
2020
if (emailExist(accountDto.getEmail())) {
21-
2221
throw new EmailExistsException("There is an account with that email adress: " + accountDto.getEmail());
2322
}
2423
User user = new User();
2524
user.setFirstName(accountDto.getFirstName());
2625
user.setLastName(accountDto.getLastName());
2726
user.setPassword(accountDto.getPassword());
2827
user.setEmail(accountDto.getEmail());
29-
//ROLE WILL ALWAYS BE USER. HARDCODING IT
30-
user.setRole(new Role(Integer.valueOf(1),user));
28+
// ROLE WILL ALWAYS BE USER. HARDCODING IT
29+
user.setRole(new Role(Integer.valueOf(1), user));
3130
return repository.save(user);
3231
}
3332

spring-security-login-error-handling/src/main/java/org/baeldung/spring/MvcConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public MessageSource messageSource() {
8383
messageSource.setCacheSeconds(0);
8484
return messageSource;
8585
}
86-
86+
8787
@Bean
8888
public EmailValidator usernameValidator() {
8989
EmailValidator userNameValidator = new EmailValidator();

spring-security-login-error-handling/src/main/java/org/baeldung/validation/service/PasswordMatches.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
import static java.lang.annotation.ElementType.TYPE;
1111
import static java.lang.annotation.RetentionPolicy.RUNTIME;
1212

13-
@Target({TYPE,ANNOTATION_TYPE})
13+
@Target({ TYPE, ANNOTATION_TYPE })
1414
@Retention(RUNTIME)
1515
@Constraint(validatedBy = PasswordMatchesValidator.class)
1616
@Documented
1717
public @interface PasswordMatches {
18-
18+
1919
String message() default "Passwords don't match";
20-
Class<?>[] groups() default {};
20+
21+
Class<?>[] groups() default {};
22+
2123
Class<? extends Payload>[] payload() default {};
2224
}

spring-security-login-error-handling/src/main/java/org/baeldung/validation/service/PasswordMatchesValidator.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import org.baeldung.persistence.service.UserDto;
77

88
public class PasswordMatchesValidator implements ConstraintValidator<PasswordMatches, Object> {
9-
9+
1010
@Override
11-
public void initialize(PasswordMatches constraintAnnotation) {
11+
public void initialize(PasswordMatches constraintAnnotation) {
1212
}
13+
1314
@Override
14-
public boolean isValid(Object obj, ConstraintValidatorContext context){
15+
public boolean isValid(Object obj, ConstraintValidatorContext context) {
1516
UserDto user = (UserDto) obj;
16-
return user.getPassword().equals(user.getMatchingPassword());
17-
}
17+
return user.getPassword().equals(user.getMatchingPassword());
18+
}
1819
}
Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<beans:beans xmlns="http://www.springframework.org/schema/security"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
2+
<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"
43
xmlns:mvc="http://www.springframework.org/schema/mvc"
54
xsi:schemaLocation="
65
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.2.xsd
@@ -15,22 +14,17 @@
1514
<intercept-url pattern="/resources/**" access="permitAll" />
1615
<intercept-url pattern="/invalidSession*" access="isAnonymous()" />
1716
<intercept-url pattern="/**" access="isAuthenticated()" />
18-
<form-login login-page='/login.html'
19-
authentication-failure-url="/login.html?error=true"
20-
authentication-success-handler-ref="myAuthenticationSuccessHandler"
17+
<form-login login-page='/login.html' authentication-failure-url="/login.html?error=true" authentication-success-handler-ref="myAuthenticationSuccessHandler"
2118
default-target-url="/homepage.html" />
22-
<session-management invalid-session-url="/invalidSession.html"
23-
session-fixation-protection="none" />
24-
<logout invalidate-session="false" logout-success-url="/logout.html?logSucc=true"
25-
logout-url="/j_spring_security_logout" delete-cookies="JSESSIONID" />
19+
<session-management invalid-session-url="/invalidSession.html" session-fixation-protection="none" />
20+
<logout invalidate-session="false" logout-success-url="/logout.html?logSucc=true" logout-url="/j_spring_security_logout" delete-cookies="JSESSIONID" />
2621
</http>
27-
<beans:bean id="myAuthenticationSuccessHandler"
28-
class="org.baeldung.security.MySimpleUrlAuthenticationSuccessHandler" />
22+
23+
<beans:bean id="myAuthenticationSuccessHandler" class="org.baeldung.security.MySimpleUrlAuthenticationSuccessHandler" />
24+
2925
<authentication-manager>
30-
<authentication-provider user-service-ref="userDetailsService">
31-
32-
</authentication-provider>
26+
<authentication-provider user-service-ref="userDetailsService" />
3327
</authentication-manager>
34-
<beans:bean id="userDetailsService" class="org.baeldung.security.MyUserDetailsService"
35-
autowire="constructor" />
28+
<beans:bean id="userDetailsService" class="org.baeldung.security.MyUserDetailsService" />
29+
3630
</beans:beans>

0 commit comments

Comments
 (0)