Skip to content

Commit

Permalink
Merge pull request #9 from TG-WinG/feature/login
Browse files Browse the repository at this point in the history
Feature/login
  • Loading branch information
wwingyou authored May 14, 2024
2 parents 2585ffb + 04c98e0 commit a30710c
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 23 deletions.
37 changes: 19 additions & 18 deletions src/main/java/kr/tgwing/tech/security/config/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package kr.tgwing.tech.security.config;


import kr.tgwing.tech.security.filter.JwtFilter;
import kr.tgwing.tech.security.util.JwtUtil;
import kr.tgwing.tech.security.filter.LoginFilter;
Expand Down Expand Up @@ -47,6 +46,7 @@ public class SecurityConfig {
"/api-docs/json/swagger-config",
"/api-docs/json"
};

@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
log.info("WebSecurity......................");
Expand All @@ -64,6 +64,7 @@ public SecurityConfig(AuthenticationConfiguration authenticationConfiguration, J
this.authenticationConfiguration = authenticationConfiguration;
this.jwtUtil = jwtUtil;
}

@Bean
public AuthenticationManager authenticationManager(AuthenticationConfiguration configuration) throws Exception {

Expand All @@ -78,9 +79,9 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.csrf(AbstractHttpConfigurer::disable) // 토큰 사용하기에 csrf 불가능
.cors(AbstractHttpConfigurer::disable)

// .formLogin(Customizer.withDefaults())// -> 로그인 화면 구성되면 사용해야함.
// .logout((logout) -> logout
// .clearAuthentication(true))
// .formLogin(Customizer.withDefaults())// -> 로그인 화면 구성되면 사용해야함.
// .logout((logout) -> logout
// .clearAuthentication(true))

.authorizeHttpRequests(request -> request
.requestMatchers(PERMIT_URL_ARRAY)
Expand All @@ -91,26 +92,26 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.hasRole("ADMIN")
.requestMatchers(HttpMethod.GET, "/file/**")
.permitAll()
.anyRequest().authenticated()
)
.anyRequest().authenticated())
.addFilterBefore(new JwtFilter(jwtUtil), LoginFilter.class)
.addFilterAt(new LoginFilter(authenticationManager(authenticationConfiguration), jwtUtil), UsernamePasswordAuthenticationFilter.class)
.addFilterAt(new LoginFilter(authenticationManager(authenticationConfiguration), jwtUtil),
UsernamePasswordAuthenticationFilter.class)
.sessionManagement((session) -> session
.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
.build();
}

// @Bean
// @ConditionalOnMissingBean(UserDetailsService.class)
// InMemoryUserDetailsManager inMemoryUserDetailsManager() {
// User.UserBuilder users = User.withDefaultPasswordEncoder();
// UserDetails admin = users
// .username("admin")
// .password("admin")
// .roles("ADMIN")
// .build();
// return new InMemoryUserDetailsManager(admin);
// }
// @Bean
// @ConditionalOnMissingBean(UserDetailsService.class)
// InMemoryUserDetailsManager inMemoryUserDetailsManager() {
// User.UserBuilder users = User.withDefaultPasswordEncoder();
// UserDetails admin = users
// .username("admin")
// .password("admin")
// .roles("ADMIN")
// .build();
// return new InMemoryUserDetailsManager(admin);
// }

@Bean
public BCryptPasswordEncoder bCryptPasswordEncoder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import kr.tgwing.tech.user.dto.ProfileReqDTO;
import kr.tgwing.tech.user.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.repository.config.RepositoryNameSpaceHandler;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -42,6 +43,16 @@ public ResponseEntity<ApiResponse<Long>> changeProfile(
return ResponseEntity.ok(ApiResponse.updated(change));
}

@Operation(summary = "회원 탈퇴" )
@DeleteMapping("")
public ResponseEntity<ApiResponse<Long>> removeProfile(Principal principal){
String studentId = principal.getName();
Long remove = userService.removeUser(studentId);

return ResponseEntity.ok(ApiResponse.delete(remove));

}


// @GetMapping("/myPosting")

Expand Down
4 changes: 0 additions & 4 deletions src/main/java/kr/tgwing/tech/user/dto/UserDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public class UserDTO {
private String name; // 이름
private Date birth;
private String phoneNumber;
private String role;
private String profilePicture;

public static UserEntity toUserEntity(UserDTO userDTO) {

Expand All @@ -28,8 +26,6 @@ public static UserEntity toUserEntity(UserDTO userDTO) {
.name(userDTO.getName())
.birth(userDTO.getBirth())
.phoneNumber(userDTO.getPhoneNumber())
.role(userDTO.getRole())
.profilePicture(userDTO.getProfilePicture())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@
public interface UserRepository extends JpaRepository<UserEntity, Long> {
Optional<UserEntity> findByStudentId(String studentId);

@Transactional
void deleteByStudentId(String studentId);


@Transactional
@Modifying
@Query("UPDATE UserEntity U SET U.name = :name, U.phoneNumber = :phoneNumber, U.profilePicture = :profilePicture WHERE U.studentId = :id")
void changeUser(String id, String name, String phoneNumber, String profilePicture);


Boolean existsByStudentId(String studentId);
}
2 changes: 2 additions & 0 deletions src/main/java/kr/tgwing/tech/user/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public interface UserService{

Long changeUser(String name, ProfileReqDTO request);

Long removeUser(String name);

ProfileDTO showUser(String name);

Boolean checkUser(CheckUserDTO checkUserDTO); // 본인 확인하기
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ public Long changeUser(String studentId, ProfileReqDTO request){
return id;
};

@Override
public Long removeUser(String studentId){
userRepository.deleteByStudentId(studentId);
return null;
}



@Override
public ProfileDTO showUser(String studentId){
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ cloud.aws.region.auto=false
cloud.aws.stack.auto=false

# Log level configuration
logging.level.root=DEBUG
logging.level.root=DEBUG

spring.data.redis.port=6379
spring.data.redis.host=localhost
spring.data.redis.password=

0 comments on commit a30710c

Please sign in to comment.