User and UserRepository
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.packt.cardatabase;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfiguration;
|
||||
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.provisioning.InMemoryUserDetailsManager;
|
||||
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
//deprecated
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
|
||||
@Configuration
|
||||
@EnableWebSecurity
|
||||
public class SecurityConfig {
|
||||
@SuppressWarnings("deprecation")
|
||||
@Bean
|
||||
public UserDetailsService userDetailsService() {
|
||||
UserDetails user = User.withDefaultPasswordEncoder()
|
||||
.username("user")
|
||||
.password("password")
|
||||
.roles("USER")
|
||||
.build();
|
||||
return new InMemoryUserDetailsManager(user);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import java.util.List;
|
||||
import org.springframework.data.repository.*;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
import org.springframework.data.rest.core.annotation.RestResource;
|
||||
|
||||
// @RestResource(path="vehicles") -> api 호출경로를 cars 대신 vehicles 로 변경하고자 할때 사용하는 어노테이션
|
||||
@RepositoryRestResource
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.packt.cardatabase.domain;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
|
||||
@Table(name="`user`")
|
||||
@Entity
|
||||
public class User {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
@Column(nullable=false, updatable=false)
|
||||
private Long id;
|
||||
|
||||
@Column(nullable=false, unique=true)
|
||||
private String username;
|
||||
|
||||
@Column(nullable=false)
|
||||
private String password;
|
||||
|
||||
@Column(nullable=false)
|
||||
private String role;
|
||||
|
||||
public User() {}
|
||||
|
||||
public User(String username, String password, String role) {
|
||||
super();
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
public void setRole(String role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.packt.cardatabase.domain;
|
||||
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
|
||||
public interface UserRepository extends CrudRepository<User, Long>{
|
||||
|
||||
Optional<User> findByUsername(String username);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user