Skip to content

Commit

Permalink
🌞[INIT]-#3-SecurityConfig 생성 및 μ„€μ •
Browse files Browse the repository at this point in the history
## κ°œμš”
- λ‚΄μš©μ„ μ μ–΄μ£Όμ„Έμš”.

## μž‘μ—…μ‚¬ν•­
- λ‚΄μš©μ„ μ μ–΄μ£Όμ„Έμš”.

## λ³€κ²½λ‘œμ§
- λ‚΄μš©μ„ μ μ–΄μ£Όμ„Έμš”.

#### ν…ŒμŠ€νŠΈμΈ 경우 μ΄ν•˜ λ‚΄μš© μž‘μ„± ####
# ν…ŒμŠ€νŠΈ λ‚΄μš© (ν•œ 쀄 72자 λ‚΄)

*어떀것을 ν…ŒμŠ€νŠΈν–ˆκ³ , ν…ŒμŠ€νŠΈ 성곡 μ—¬λΆ€ μž‘μ„±*

#### (이상) ####

# CREATE _ yellow
🌞[INIT] : 초기 생성
πŸ”₯[FEAT] : μƒˆ κΈ°λŠ₯ κ΅¬ν˜„
πŸ“[LIB]  : 라이브러리 μΆ”κ°€

# MODIFY _ white
πŸ“ˆ[UPDATE] : μ½”λ“œ μˆ˜μ • 및 ν–₯상 (였λ₯˜ μˆ˜μ •κ³Ό λ‹€λ₯΄λ‹€)
πŸ”§[FIX]    : 버그 및 였λ₯˜ μˆ˜μ •, ν•΄κ²°
πŸ’¨[MOVE]   : ν”„λ‘œμ νŠΈ λ‚΄ 파일 μ£Όμ†Œ λ³€κ²½ μ‹œ 
     (* λͺ¨λ“  νŒ€μ›κ³Ό μƒμ˜ ν›„ 높은 λΈŒλžœμΉ˜μ—μ„œ 진행)
πŸ–[RENAME] : ν”„λ‘œμ νŠΈ λ‚΄ 파일 λͺ… λ³€κ²½ μ‹œ 
     (* λͺ¨λ“  νŒ€μ›κ³Ό μƒμ˜ ν›„ 높은 λΈŒλžœμΉ˜μ—μ„œ 진행)
πŸŒͺ️[REF]: μ½”λ“œ λ¦¬νŒ©ν† λ§ 
     (μ½”λ“œ μ „λ©΄ μˆ˜μ • μ‹œ, λͺ¨λ“  νŒ€μ›κ³Ό μƒμ˜ ν›„ 브랜치 μΆ©λŒμ— μ£Όμ˜ν•΄μ„œ 진행)

# REMOVE _ black
🌚[CLEAR]  : μ½”λ“œ μ‚­μ œ
πŸš₯[TIDY]   : μ€‘λ³΅λ˜λŠ” μ½”λ“œ, κΈ°λŠ₯κ³Ό κ΄€λ ¨μ—†λŠ” μ½”λ“œ λ“± 정리
πŸ’£[REMOVE] : 파일 μ‚­μ œ (* λͺ¨λ“  νŒ€μ›κ³Ό μƒμ˜ ν›„ 높은 λΈŒλžœμΉ˜μ—μ„œ 진행)

# TEST 
πŸ“–[TEST]   : ν…ŒμŠ€νŠΈ μ½”λ“œ 생성

# GIT
πŸ”€[MERGE] : 기타 브랜치 머지

# ELSE
⚠️[EMG]  : κΈ΄κΈ‰ν•œ μž‘μ—… μˆ˜ν–‰ 
πŸ“œ[DOCS] : λ¬Έμ„œ μž‘μ—… 
     (README, RESTDOCS λ“±, ν”„λ‘œμ νŠΈ μŠ€μ½”ν”„μ— λ§žλŠ” λΈŒλžœμΉ˜μ—μ„œ 진행)
  • Loading branch information
daehwan2yo committed Dec 22, 2021
1 parent 7b85d19 commit 4b40eeb
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 4 deletions.
Binary file modified .gradle/7.3.2/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/7.3.2/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.codingwasabi.trti.config.auth.security;

import com.codingwasabi.trti.domain.member.model.entity.Member;
import lombok.Getter;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.ArrayList;
import java.util.Collection;

public class MemberAdaptor implements UserDetails {

@Getter
public final Member member;

public MemberAdaptor(Member member) {
this.member = member;
}

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
Collection<GrantedAuthority> authorities = new ArrayList<>();
authorities.add(new SimpleGrantedAuthority(member.getAuthority().getRole()));
return authorities;
}

@Override
public String getPassword() {
return null;
}

@Override
public String getUsername() {
return member.getEmail();
}

@Override
public boolean isAccountNonExpired() {
return true;
}

@Override
public boolean isAccountNonLocked() {
return true;
}

@Override
public boolean isCredentialsNonExpired() {
return true;
}

@Override
public boolean isEnabled() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.codingwasabi.trti.config.auth.security;

import com.codingwasabi.trti.domain.member.model.entity.Member;
import com.codingwasabi.trti.domain.member.repository.MemberRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class MemberDetailsServiceImpl implements UserDetailsService {
private final MemberRepository memberRepository;

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
// Error code μΆ”κ°€ μ˜ˆμ •
Member member = memberRepository.findByEmail(username)
.orElseThrow(() -> new IllegalArgumentException("ERROR"));

return new MemberAdaptor(member);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.codingwasabi.trti.config.auth.security;

import lombok.RequiredArgsConstructor;
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.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;

@Configuration
@EnableWebSecurity
@RequiredArgsConstructor
public class SecurityConfig extends WebSecurityConfigurerAdapter {
private final String[] AUTHENTICATED_URI_LIST = {
""
};

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.httpBasic().disable()
.csrf().disable()
.cors()
.and()
.exceptionHandling()
//.authenticationEntryPoint(jwtEntryPoint)
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()

// 일단 λ‹€ ν—ˆμš©
.anyRequest().permitAll()
;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.codingwasabi.trti.domain.member.model.entity;

import com.codingwasabi.trti.domain.common.Period;
import com.codingwasabi.trti.domain.member.model.enumValue.Authority;
import com.codingwasabi.trti.domain.member.model.enumValue.Gender;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.*;

@Entity
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
Expand All @@ -31,4 +31,13 @@ public class Member extends Period {
private String ageRange;

private String imagePath;

@Column
@Builder.Default
@Enumerated(EnumType.STRING)
private Authority authority = Authority.USER;

public Authority getAuthority() {
return authority;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.codingwasabi.trti.domain.member.model.enumValue;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum Authority {
USER("ROLE_USER"),
ADMIN("ROLE_ADMIN");

private String role;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.codingwasabi.trti.domain.member.repository;

import com.codingwasabi.trti.domain.member.model.entity.Member;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Optional;

public interface MemberRepository extends JpaRepository<Member, Long> {
Optional<Member> findByEmail(String username);
}

0 comments on commit 4b40eeb

Please sign in to comment.