update MyUser and User constructor

This commit is contained in:
Loredana Crusoveanu 2016-09-13 23:20:44 +03:00
parent 6a25a24eae
commit 2da3ca4e7c
5 changed files with 3 additions and 43 deletions

View File

@ -15,16 +15,12 @@ public class MyUser {
@GeneratedValue(strategy = GenerationType.AUTO) @GeneratedValue(strategy = GenerationType.AUTO)
private int id; private int id;
private String name;
@Column(unique = true, nullable = false) @Column(unique = true, nullable = false)
private String username; private String username;
@Column(nullable = false) @Column(nullable = false)
private String password; private String password;
private boolean enabled;
public MyUser() { public MyUser() {
} }
@ -36,14 +32,6 @@ public class MyUser {
this.id = id; this.id = id;
} }
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getUsername() { public String getUsername() {
return username; return username;
} }
@ -59,18 +47,4 @@ public class MyUser {
public void setPassword(final String password) { public void setPassword(final String password) {
this.password = password; this.password = password;
} }
public boolean isEnabled() {
return enabled;
}
public void setEnabled(final boolean enabled) {
this.enabled = enabled;
}
@Override
public String toString() {
return "MyUser [name=" + name + ", username=" + username + ", password=" + password + ", enabled=" + enabled + "]";
}
} }

View File

@ -8,6 +8,7 @@ import org.baeldung.user.dao.MyUserDAO;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.core.userdetails.UsernameNotFoundException;
@ -29,7 +30,7 @@ public class MyUserDetailsService implements UserDetailsService {
else { else {
final Collection<GrantedAuthority> authorities = new ArrayList<>(); final Collection<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority("ROLE_USER")); authorities.add(new SimpleGrantedAuthority("ROLE_USER"));
return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), user.isEnabled(), true, true, true, authorities); return new User(user.getUsername(), user.getPassword(), authorities);
} }
} }

View File

@ -26,8 +26,6 @@ public class MyUserService {
user.setUsername(accountDto.getUsername()); user.setUsername(accountDto.getUsername());
user.setPassword(passwordEncoder.encode(accountDto.getPassword())); user.setPassword(passwordEncoder.encode(accountDto.getPassword()));
user.setName(accountDto.getName());
user.setEnabled(true);
return myUserDAO.save(user); return myUserDAO.save(user);
} }

View File

@ -8,10 +8,6 @@ public class MyUserDto {
@Size(min = 1) @Size(min = 1)
private String username; private String username;
@NotNull
@Size(min = 1)
private String name;
private String password; private String password;
public String getUsername() { public String getUsername() {
@ -22,14 +18,6 @@ public class MyUserDto {
this.username = username; this.username = username;
} }
public String getName() {
return name;
}
public void setName(final String name) {
this.name = name;
}
public String getPassword() { public String getPassword() {
return password; return password;
} }

View File

@ -16,7 +16,6 @@ Register here:<br><br>
<form action="${registerUrl }" method="POST"> <form action="${registerUrl }" method="POST">
Username: <input type="text" name="username"/><br> Username: <input type="text" name="username"/><br>
Password: <input type="password" name="password"/><br> Password: <input type="password" name="password"/><br>
Name: <input type="text" name="name" /><br><br>
<input type="submit" value="Register"/> <input type="submit" value="Register"/>
</form> </form>