-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π[INIT]-#3-SecurityConfig μμ± λ° μ€μ
## κ°μ - λ΄μ©μ μ μ΄μ£ΌμΈμ. ## μμ μ¬ν - λ΄μ©μ μ μ΄μ£ΌμΈμ. ## λ³κ²½λ‘μ§ - λ΄μ©μ μ μ΄μ£ΌμΈμ. #### ν μ€νΈμΈ κ²½μ° μ΄ν λ΄μ© μμ± #### # ν μ€νΈ λ΄μ© (ν μ€ 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
1 parent
7b85d19
commit 4b40eeb
Showing
9 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
57 changes: 57 additions & 0 deletions
57
src/main/java/com/codingwasabi/trti/config/auth/security/MemberAdaptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/codingwasabi/trti/config/auth/security/MemberDetailsServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/com/codingwasabi/trti/config/auth/security/SecurityConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/main/java/com/codingwasabi/trti/domain/member/model/enumValue/Authority.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/codingwasabi/trti/domain/member/repository/MemberRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |