Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 로그인 삭제 #194

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ dependencies {
// model mapper
implementation 'org.modelmapper:modelmapper:3.1.0'

// security
implementation 'org.springframework.boot:spring-boot-starter-security'

// jwt
implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2'
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.2'
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2'

// Oauth2
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

// Redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
// security
// implementation 'org.springframework.boot:spring-boot-starter-security'
//
// // jwt
// implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.11.2'
// runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.2'
// runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.2'
//
// // Oauth2
// implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'
//
// // Redis
// implementation 'org.springframework.boot:spring-boot-starter-data-redis'

//s3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package aromanticcat.umcproject.converter;

import aromanticcat.umcproject.entity.FriendStatus;
import aromanticcat.umcproject.entity.Member;
import aromanticcat.umcproject.web.dto.Member.MemberRequestDTO;
import aromanticcat.umcproject.web.dto.Member.MemberResponseDTO;
Expand All @@ -24,6 +25,7 @@ public static MemberRequestDTO.searchMemberDTO toSearchMemberDTO(Member member)
return MemberRequestDTO.searchMemberDTO.builder()
.memberId(member.getId())
.nickname(member.getNickname())
.friendStatus(FriendStatus.NOT_FRIEND)
.build();
}
}
2 changes: 2 additions & 0 deletions src/main/java/aromanticcat/umcproject/entity/Friend.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ public int updateExchange_num() {
this.exchange_num++;
return exchange_num;
}

public void changeIsFrom(Boolean isFrom){ this.isFrom = isFrom; }
}
6 changes: 3 additions & 3 deletions src/main/java/aromanticcat/umcproject/entity/Member.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package aromanticcat.umcproject.entity;

import aromanticcat.umcproject.security.Role;
//import aromanticcat.umcproject.security.Role;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
Expand Down Expand Up @@ -39,8 +39,8 @@ public class Member extends BaseEntity {

private int coin;

@Enumerated(EnumType.STRING)
private Role userRole;
// @Enumerated(EnumType.STRING)
// private Role userRole;

@OneToMany(mappedBy = "member", fetch = FetchType.LAZY, cascade = CascadeType.ALL)
private List<MemberMission> memberMissions = new ArrayList<>();
Expand Down
32 changes: 0 additions & 32 deletions src/main/java/aromanticcat/umcproject/entity/Reward.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,33 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Set;

public interface FriendRepository extends JpaRepository<Friend, Long> {

@Query("SELECT f FROM Friend f WHERE f.member = :member AND f.friendStatus IN (:friendStatus)")
Page<Friend> findFriendByMemberAndFriendStatus(Member member, Set<FriendStatus> friendStatus, Pageable pageable);
@Query("SELECT f " +
"FROM Friend f " +
"WHERE f.member = :member " +
"AND f.friendStatus IN (:friendStatus)")
Page<Friend> findFriendByMemberAndFriendStatus(@Param("member") Member member,
@Param("friendStatus") Set<FriendStatus> friendStatus,
Pageable pageable);

List<Friend> findFriendByMemberAndFriendName(Member member, String friendName);

List<Friend> findFriendByMemberAndFriendId(Member member, Long friendId);

Friend findByMemberAndFriendId(Member member, Long friendId);

@Query("SELECT CASE WHEN COUNT(f) > 0 THEN TRUE ELSE FALSE END " +
"FROM Friend f " +
"WHERE f.member = :member " +
"AND f.friendId = :findMemberId " +
"AND f.friendStatus IN :friendStatus")
Boolean existsByMemberAndFriendIdAndFriendStatus(@Param("member") Member member,
@Param("findMemberId") Long findMemberId,
@Param("friendStatus") Set<FriendStatus> friendStatus);
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package aromanticcat.umcproject.repository;

import aromanticcat.umcproject.security.jwt.RefreshToken;
import java.util.Optional;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface RefreshTokenRepository extends CrudRepository<RefreshToken, String> {

// accessToken으로 RefreshToken을 찾아온다.
Optional<RefreshToken> findByAccessToken(String accessToken);
}
//package aromanticcat.umcproject.repository;
//
//import aromanticcat.umcproject.security.jwt.RefreshToken;
//import java.util.Optional;
//import org.springframework.data.repository.CrudRepository;
//import org.springframework.stereotype.Repository;
//
//@Repository
//public interface RefreshTokenRepository extends CrudRepository<RefreshToken, String> {
//
// // accessToken으로 RefreshToken을 찾아온다.
// Optional<RefreshToken> findByAccessToken(String accessToken);
//}
30 changes: 15 additions & 15 deletions src/main/java/aromanticcat/umcproject/security/Role.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package aromanticcat.umcproject.security;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum Role {

GUSET("ROLE_GUEST", "손님"),
USER("ROLE_USER", "일반 사용자");

private final String key;
private final String title;
}
//package aromanticcat.umcproject.security;
//
//import lombok.Getter;
//import lombok.RequiredArgsConstructor;
//
//@Getter
//@RequiredArgsConstructor
//public enum Role {
//
// GUSET("ROLE_GUEST", "손님"),
// USER("ROLE_USER", "일반 사용자");
//
// private final String key;
// private final String title;
//}
125 changes: 64 additions & 61 deletions src/main/java/aromanticcat/umcproject/security/SecurityConfig.java
Original file line number Diff line number Diff line change
@@ -1,61 +1,64 @@
package aromanticcat.umcproject.security;

import aromanticcat.umcproject.security.jwt.JwtAuthFilter;
import aromanticcat.umcproject.security.jwt.JwtExceptionFilter;
import aromanticcat.umcproject.security.oauth.CustomOAuth2UserService;
import aromanticcat.umcproject.security.oauth.MyAuthenticationFailureHandler;
import aromanticcat.umcproject.security.oauth.MyAuthenticationSuccessHandler;
import lombok.RequiredArgsConstructor;
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.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfig {

private final MyAuthenticationSuccessHandler oAuth2LoginSuccessHandler;
private final CustomOAuth2UserService customOAuth2UserService;
private final JwtAuthFilter jwtAuthFilter;
private final MyAuthenticationFailureHandler oAuth2LoginFailureHandler;
private final JwtExceptionFilter jwtExceptionFilter;

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.httpBasic().disable() // HTTP 기본 인증을 비활성화
.cors().and() // CORS 활성화
.csrf().disable() // CSRF 보호 기능 비활성화
.logout().disable()
.sessionManagement()
.sessionCreationPolicy(
SessionCreationPolicy.STATELESS) // 세션관리 정책을 STATELESS(세션이 있으면 쓰지도 않고, 없으면 만들지도 않는다)
.and()
.authorizeRequests() // 요청에 대한 인증 설정
.antMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-resources/**").permitAll()
.antMatchers("/", "/login/**", "/signUp/**", "/nangman-collection/",
"/nangman-collection/{nangmanLetterId}/like",
"/nangman-collection/{nangmanLetterId}").permitAll()
.antMatchers("/token/**").permitAll() // 토큰 발급을 위한 경로는 모두 허용
.antMatchers("/css/**", "/images/**", "/js/**", "/favicon.ico", "/h2-console/**").permitAll()
.anyRequest().authenticated() // 그 외의 모든 요청은 인증이 필요하다.
.and()
.oauth2Login() // OAuth2 로그인 설정시작
.userInfoEndpoint().userService(customOAuth2UserService) // OAuth2 로그인시 사용자 정보를 가져오는 엔드포인트와 사용자 서비스를 설정
.and()
.failureHandler(oAuth2LoginFailureHandler) // OAuth2 로그인 실패시 처리할 핸들러를 지정해준다.
.successHandler(oAuth2LoginSuccessHandler); // OAuth2 로그인 성공시 처리할 핸들러를 지정해준다.

// JWT 인증 필터를 UsernamePasswordAuthenticationFilter 앞에 추가한다.
return http
.addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class)
.addFilterBefore(jwtExceptionFilter, JwtAuthFilter.class)
.build();
}

}
//package aromanticcat.umcproject.security;
//
//import aromanticcat.umcproject.security.jwt.JwtAuthFilter;
//import aromanticcat.umcproject.security.jwt.JwtExceptionFilter;
//import aromanticcat.umcproject.security.oauth.CustomOAuth2UserService;
//import aromanticcat.umcproject.security.oauth.MyAuthenticationFailureHandler;
//import aromanticcat.umcproject.security.oauth.MyAuthenticationSuccessHandler;
//import lombok.RequiredArgsConstructor;
//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.http.SessionCreationPolicy;
//import org.springframework.security.web.SecurityFilterChain;
//import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
//
//@Configuration
//@EnableWebSecurity
//@RequiredArgsConstructor
//public class SecurityConfig {
//
// private final MyAuthenticationSuccessHandler oAuth2LoginSuccessHandler;
// private final CustomOAuth2UserService customOAuth2UserService;
// private final JwtAuthFilter jwtAuthFilter;
// private final MyAuthenticationFailureHandler oAuth2LoginFailureHandler;
// private final JwtExceptionFilter jwtExceptionFilter;
//
// @Bean
// public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// http
// .httpBasic().disable() // HTTP 기본 인증을 비활성화
// .cors().and() // CORS 활성화
// .csrf().disable() // CSRF 보호 기능 비활성화
// .logout().disable()
// .sessionManagement()
// .sessionCreationPolicy(
// SessionCreationPolicy.STATELESS) // 세션관리 정책을 STATELESS(세션이 있으면 쓰지도 않고, 없으면 만들지도 않는다)
// .and()
// .authorizeRequests() // 요청에 대한 인증 설정
// .antMatchers("/v3/api-docs/**", "/swagger-ui/**", "/swagger-resources/**").permitAll()
// .antMatchers("/", "/login/**", "/signUp/**", "/nangman-collection/",
// "/nangman-collection/{nangmanLetterId}/like",
// "/nangman-collection/{nangmanLetterId},",
// "/missions/**",
// "/address-book/**",
// "/my-collection/letter-paper").permitAll()
// .antMatchers("/token/**").permitAll() // 토큰 발급을 위한 경로는 모두 허용
// .antMatchers("/css/**", "/images/**", "/js/**", "/favicon.ico", "/h2-console/**").permitAll()
// .anyRequest().authenticated() // 그 외의 모든 요청은 인증이 필요하다.
// .and()
// .oauth2Login() // OAuth2 로그인 설정시작
// .userInfoEndpoint().userService(customOAuth2UserService) // OAuth2 로그인시 사용자 정보를 가져오는 엔드포인트와 사용자 서비스를 설정
// .and()
// .failureHandler(oAuth2LoginFailureHandler) // OAuth2 로그인 실패시 처리할 핸들러를 지정해준다.
// .successHandler(oAuth2LoginSuccessHandler); // OAuth2 로그인 성공시 처리할 핸들러를 지정해준다.
//
// // JWT 인증 필터를 UsernamePasswordAuthenticationFilter 앞에 추가한다.
// return http
// .addFilterBefore(jwtAuthFilter, UsernamePasswordAuthenticationFilter.class)
// .addFilterBefore(jwtExceptionFilter, JwtAuthFilter.class)
// .build();
// }
//
//}
55 changes: 28 additions & 27 deletions src/main/java/aromanticcat/umcproject/security/SecurityUserDto.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package aromanticcat.umcproject.security;

import static aromanticcat.umcproject.security.Role.USER;

import aromanticcat.umcproject.entity.Member;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SecurityUserDto {
private String nickname;
private String email;
private Role role;

public Member toEntity() {
return Member.builder()
.email(email)
.nickname(nickname)
.userRole(USER)
.build();
}
}
//package aromanticcat.umcproject.security;
//
//import static aromanticcat.umcproject.security.Role.USER;
//
//import aromanticcat.umcproject.entity.Member;
//import lombok.AllArgsConstructor;
//import lombok.Builder;
//import lombok.Getter;
//import lombok.NoArgsConstructor;
//
//@Getter
//@Builder
//@AllArgsConstructor
//@NoArgsConstructor
//public class SecurityUserDto {
//
// private String nickname;
// private String email;
// private Role role;
//
// public Member toEntity() {
// return Member.builder()
// .email(email)
// .nickname(nickname)
// .userRole(USER)
// .build();
// }
//}
Loading
Loading