cleanup work
This commit is contained in:
parent
33b6d5c645
commit
1222077785
|
@ -3,7 +3,6 @@ package org.baeldung.persistence.dao;
|
|||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.baeldung.persistence.model.User;
|
||||
|
||||
|
||||
public interface UserRepository extends JpaRepository<User,Long>{
|
||||
public interface UserRepository extends JpaRepository<User, Long> {
|
||||
public User findByUsername(String username);
|
||||
}
|
||||
|
|
|
@ -11,8 +11,7 @@ import javax.persistence.JoinColumn;
|
|||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
|
||||
@Entity(name="role")
|
||||
@Entity(name = "role")
|
||||
@Table(name = "role")
|
||||
public class Role {
|
||||
|
||||
|
@ -20,42 +19,49 @@ public class Role {
|
|||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
|
||||
|
||||
@OneToOne(targetEntity = User.class, fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
||||
@JoinColumn(name = "user_id")
|
||||
private User user;
|
||||
|
||||
@Column(name="role")
|
||||
@Column(name = "role")
|
||||
private Integer role;
|
||||
|
||||
public Role(){
|
||||
public Role() {
|
||||
super();
|
||||
|
||||
}
|
||||
public Role(Integer role){
|
||||
|
||||
public Role(Integer role) {
|
||||
super();
|
||||
this.role = role;
|
||||
}
|
||||
public Role(Integer role, User user){
|
||||
|
||||
public Role(Integer role, User user) {
|
||||
super();
|
||||
this.role = role;
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Integer getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(Integer role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
|
|
@ -17,17 +17,16 @@ public class User {
|
|||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
private Long id;
|
||||
@Column(name="firstName")
|
||||
@Column(name = "firstName")
|
||||
private String firstName;
|
||||
@Column(name="lastName")
|
||||
@Column(name = "lastName")
|
||||
private String lastName;
|
||||
@Column(name="username")
|
||||
@Column(name = "username")
|
||||
private String username;
|
||||
@Column(name="password")
|
||||
@Column(name = "password")
|
||||
private String password;
|
||||
|
||||
|
||||
@OneToOne(mappedBy = "user",fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
||||
@OneToOne(mappedBy = "user", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
|
||||
private Role role;
|
||||
|
||||
public Long getId() {
|
||||
|
@ -78,7 +77,6 @@ public class User {
|
|||
this.role = role;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
|
@ -100,11 +98,11 @@ public class User {
|
|||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append("User [firstName=").append(firstName).append("]").
|
||||
append("[lastName=").append(lastName).append("]").append("[username").append(username).append("]");
|
||||
builder.append("User [firstName=").append(firstName).append("]").append("[lastName=").append(lastName).append("]").append("[username").append(username).append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package org.baeldung.persistence.service;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class EmailExistsException extends Throwable{
|
||||
public class EmailExistsException extends Throwable {
|
||||
|
||||
public EmailExistsException(String message) {
|
||||
super(message);
|
||||
|
|
|
@ -17,7 +17,7 @@ public class RepositoryService implements UserService {
|
|||
private Environment env;
|
||||
|
||||
@Autowired
|
||||
public RepositoryService( UserRepository repository) {
|
||||
public RepositoryService(UserRepository repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,38 +10,47 @@ public class UserDto {
|
|||
public Integer getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(Integer role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
builder.append("User [firstName=").append(firstName).append("]").
|
||||
append("[lastName=").append(lastName).append("]").append("[username").append(username).append("]").append("[password").append(password).append("]");
|
||||
builder.append("User [firstName=").append(firstName).append("]").append("[lastName=").append(lastName).append("]").append("[username").append(username).append("]").append("[password").append(password).append("]");
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
package org.baeldung.persistence.service;
|
||||
|
||||
import org.baeldung.persistence.model.User;
|
||||
|
||||
public interface UserService {
|
||||
|
|
|
@ -36,7 +36,7 @@ public class MyUserDetailsService implements UserDetailsService {
|
|||
User user = userRepository.findByUsername(username);
|
||||
LOGGER.debug("Found user: {}", user);
|
||||
if (user == null) {
|
||||
//throw new UsernameNotFoundException("No user found with username: " + username);
|
||||
// throw new UsernameNotFoundException("No user found with username: " + username);
|
||||
boolean enabled = false;
|
||||
return new org.springframework.security.core.userdetails.User(" ", " ", enabled, true, true, true, getAuthorities(new Integer(1)));
|
||||
}
|
||||
|
|
|
@ -19,11 +19,8 @@ import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
|
|||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||
import org.springframework.web.servlet.view.JstlView;
|
||||
|
||||
|
||||
@Configuration
|
||||
@ComponentScan(basePackages = {
|
||||
"org.baeldung.web.controller", "org.baeldung.persistence.service", "org.baeldung.persistence.dao"
|
||||
})
|
||||
@ComponentScan(basePackages = { "org.baeldung.web.controller", "org.baeldung.persistence.service", "org.baeldung.persistence.dao" })
|
||||
@EnableWebMvc
|
||||
public class MvcConfig extends WebMvcConfigurerAdapter {
|
||||
|
||||
|
@ -58,8 +55,7 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
|
|||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/resources/**")
|
||||
.addResourceLocations("/","/resources/");
|
||||
registry.addResourceHandler("/resources/**").addResourceLocations("/", "/resources/");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,8 +9,6 @@ import org.baeldung.persistence.service.UserValidator;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.validation.BindingResult;
|
||||
|
@ -23,16 +21,12 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
|||
import org.springframework.web.context.request.WebRequest;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
|
||||
@Controller
|
||||
public class RegistrationController {
|
||||
private final Logger LOGGER = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RegistrationController.class);
|
||||
private UserService service;
|
||||
@Autowired
|
||||
private MessageSource messages;
|
||||
@Autowired
|
||||
private JavaMailSender mailSender;
|
||||
|
||||
@Autowired
|
||||
private UserValidator validator;
|
||||
|
||||
|
@ -40,6 +34,7 @@ public class RegistrationController {
|
|||
protected void initBinder(WebDataBinder binder) {
|
||||
binder.setValidator(this.validator);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public RegistrationController(UserService service) {
|
||||
this.service = service;
|
||||
|
@ -81,5 +76,5 @@ public class RegistrationController {
|
|||
}
|
||||
return registered;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue