update MyUser and User constructor
This commit is contained in:
parent
6a25a24eae
commit
2da3ca4e7c
|
@ -15,16 +15,12 @@ public class MyUser {
|
|||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private int id;
|
||||
|
||||
private String name;
|
||||
|
||||
@Column(unique = true, nullable = false)
|
||||
private String username;
|
||||
|
||||
@Column(nullable = false)
|
||||
private String password;
|
||||
|
||||
private boolean enabled;
|
||||
|
||||
public MyUser() {
|
||||
}
|
||||
|
||||
|
@ -36,14 +32,6 @@ public class MyUser {
|
|||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
@ -59,18 +47,4 @@ public class MyUser {
|
|||
public void setPassword(final String 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 + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.baeldung.user.dao.MyUserDAO;
|
|||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
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.UserDetailsService;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
|
@ -29,7 +30,7 @@ public class MyUserDetailsService implements UserDetailsService {
|
|||
else {
|
||||
final Collection<GrantedAuthority> authorities = new ArrayList<>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,8 +26,6 @@ public class MyUserService {
|
|||
|
||||
user.setUsername(accountDto.getUsername());
|
||||
user.setPassword(passwordEncoder.encode(accountDto.getPassword()));
|
||||
user.setName(accountDto.getName());
|
||||
user.setEnabled(true);
|
||||
return myUserDAO.save(user);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,6 @@ public class MyUserDto {
|
|||
@Size(min = 1)
|
||||
private String username;
|
||||
|
||||
@NotNull
|
||||
@Size(min = 1)
|
||||
private String name;
|
||||
|
||||
private String password;
|
||||
|
||||
public String getUsername() {
|
||||
|
@ -21,15 +17,7 @@ public class MyUserDto {
|
|||
public void setUsername(final String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ Register here:<br><br>
|
|||
<form action="${registerUrl }" method="POST">
|
||||
Username: <input type="text" name="username"/><br>
|
||||
Password: <input type="password" name="password"/><br>
|
||||
Name: <input type="text" name="name" /><br><br>
|
||||
<input type="submit" value="Register"/>
|
||||
</form>
|
||||
|
||||
|
|
Loading…
Reference in New Issue