-
Notifications
You must be signed in to change notification settings - Fork 388
[2단계 - 로그인 구현하기] 상돌(이상진) 미션 제출합니다. #646
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
Changes from all commits
32f26c2
4fe78cc
aa8696a
a726a3c
2537d06
a714e5a
27c9983
6afa63f
7a29f8a
d86ba66
2e2f23a
d3af719
cc45a5e
8b01768
6618122
a66d132
048c263
a429369
433d41d
7781280
f034f40
5925543
15adb68
9fdcccd
b712e75
d8c737d
a44e28e
ff51208
202f711
38833b5
3c59f40
a1f6854
068883a
de48f3f
8372959
f056c5f
6f3f4b7
09e13b4
b8c5de7
a27514d
329bb3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,38 @@ | ||
| package cache.com.example.cachecontrol; | ||
|
|
||
| import java.time.Duration; | ||
|
|
||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.http.CacheControl; | ||
| import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
| import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
| import org.springframework.web.servlet.mvc.WebContentInterceptor; | ||
|
|
||
| @Configuration | ||
| public class CacheWebConfig implements WebMvcConfigurer { | ||
|
|
||
| @Override | ||
| public void addInterceptors(final InterceptorRegistry registry) { | ||
| registry.addInterceptor(getNoCacheInterceptor()); | ||
| registry.addInterceptor(getResourceCacheInterceptor()); | ||
| } | ||
|
|
||
| // add no-cache, private cache | ||
| private WebContentInterceptor getNoCacheInterceptor() { | ||
| CacheControl cacheControl = CacheControl.noCache().cachePrivate(); | ||
|
|
||
| return createWebContentInterceptorByCache(cacheControl, "/"); | ||
| } | ||
|
|
||
| private WebContentInterceptor getResourceCacheInterceptor() { | ||
| CacheControl cacheControl = CacheControl.maxAge(Duration.ofDays(365)).cachePublic(); | ||
|
|
||
| return createWebContentInterceptorByCache(cacheControl, "/resources/**"); | ||
| } | ||
|
|
||
| private WebContentInterceptor createWebContentInterceptorByCache(CacheControl cacheControl, String path) { | ||
| WebContentInterceptor webContentInterceptor = new WebContentInterceptor(); | ||
| webContentInterceptor.addCacheMapping(cacheControl, path); | ||
| return webContentInterceptor; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,18 @@ | ||
| package cache.com.example.etag; | ||
|
|
||
| import org.springframework.boot.web.servlet.FilterRegistrationBean; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.web.filter.ShallowEtagHeaderFilter; | ||
|
|
||
| @Configuration | ||
| public class EtagFilterConfiguration { | ||
|
|
||
| // @Bean | ||
| // public FilterRegistrationBean<ShallowEtagHeaderFilter> shallowEtagHeaderFilter() { | ||
| // return null; | ||
| // } | ||
| @Bean | ||
| public FilterRegistrationBean<ShallowEtagHeaderFilter> shallowEtagHeaderFilter() { | ||
| FilterRegistrationBean<ShallowEtagHeaderFilter> registrationBean = new FilterRegistrationBean<>(); | ||
| registrationBean.setFilter(new ShallowEtagHeaderFilter()); | ||
| registrationBean.addUrlPatterns("/etag", "/resources/*"); | ||
| return registrationBean; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,8 +4,8 @@ | |
|
|
||
| public class Application { | ||
|
|
||
| public static void main(String[] args) { | ||
| final var tomcat = new Tomcat(); | ||
| tomcat.start(); | ||
| } | ||
| public static void main(String[] args) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 탭사이즈 몇으로 사용하고 계신가요??
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
4로 사용하고 있습니다 ㅎㅎ 탭사이즈에 제약이 있었나용?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제약은 없는걸로 아는데 원래 있던 코드의 탭 사이즈가 달라져서 여쭤봤어요!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
인텔리제이 포맷 파일을 https://naver.github.io/hackday-conventions-java/ 를 쓰고있어요😄 |
||
| final var tomcat = new Tomcat(); | ||
| tomcat.start(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,39 @@ | ||
| package com.techcourse.db; | ||
|
|
||
| import com.techcourse.model.User; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| public class InMemoryUserRepository { | ||
|
|
||
| private static final Map<String, User> database = new ConcurrentHashMap<>(); | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| static { | ||
| final User user = new User(1L, "gugu", "password", "hkkang@woowahan.com"); | ||
| database.put(user.getAccount(), user); | ||
| } | ||
|
|
||
| public static void save(User user) { | ||
| database.put(user.getAccount(), user); | ||
| } | ||
| import com.techcourse.model.User; | ||
|
|
||
| public static Optional<User> findByAccount(String account) { | ||
| return Optional.ofNullable(database.get(account)); | ||
| } | ||
| public class InMemoryUserRepository { | ||
|
|
||
| private InMemoryUserRepository() {} | ||
| private static final Logger log = LoggerFactory.getLogger(InMemoryUserRepository.class); | ||
| private static final Map<String, User> database = new ConcurrentHashMap<>(); | ||
|
|
||
| static { | ||
| final User user = new User(1L, "gugu", "password", "hkkang@woowahan.com"); | ||
| database.put(user.getAccount(), user); | ||
| } | ||
|
|
||
| public static void save(User user) { | ||
| if (database.containsKey(user.getAccount())) { | ||
| throw new IllegalArgumentException("account is already exist"); | ||
| } | ||
| database.put(user.getAccount(), user); | ||
| } | ||
|
|
||
| public static Optional<User> findByAccount(String account) { | ||
| if (account == null) { | ||
| log.info("account not exist"); | ||
| return Optional.empty(); | ||
| } | ||
| return Optional.ofNullable(database.get(account)); | ||
| } | ||
|
|
||
| private InMemoryUserRepository() { | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,59 @@ | ||
| package com.techcourse.model; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class User { | ||
|
|
||
| private final Long id; | ||
| private final String account; | ||
| private final String password; | ||
| private final String email; | ||
|
|
||
| public User(Long id, String account, String password, String email) { | ||
| this.id = id; | ||
| this.account = account; | ||
| this.password = password; | ||
| this.email = email; | ||
| } | ||
|
|
||
| public User(String account, String password, String email) { | ||
| this(null, account, password, email); | ||
| } | ||
|
|
||
| public boolean checkPassword(String password) { | ||
| return this.password.equals(password); | ||
| } | ||
|
|
||
| public String getAccount() { | ||
| return account; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "User{" + | ||
| "id=" + id + | ||
| ", account='" + account + '\'' + | ||
| ", email='" + email + '\'' + | ||
| ", password='" + password + '\'' + | ||
| '}'; | ||
| } | ||
| private static final Logger log = LoggerFactory.getLogger(User.class); | ||
| private final Long id; | ||
| private final String account; | ||
| private final String password; | ||
| private final String email; | ||
|
|
||
| public User(Long id, String account, String password, String email) { | ||
| validateIsNotEmptyValue(account, password, email); | ||
| this.id = id; | ||
| this.account = account; | ||
| this.password = password; | ||
| this.email = email; | ||
| } | ||
|
|
||
| private void validateIsNotEmptyValue(String account, String password, String email) { | ||
| if (account == null || account.isBlank()) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. user 검증 추가 좋네요 👍🏻
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
감사링 ㅎㅎ |
||
| throw new IllegalArgumentException("Account is empty"); | ||
| } | ||
| if (password == null || password.isBlank()) { | ||
| throw new IllegalArgumentException("Password is empty"); | ||
| } | ||
| if (email == null || email.isBlank()) { | ||
| throw new IllegalArgumentException("Email is empty"); | ||
| } | ||
| } | ||
|
|
||
| public User(String account, String password, String email) { | ||
| this(null, account, password, email); | ||
| } | ||
|
|
||
| public boolean checkPassword(String password) { | ||
| if (password == null) { | ||
| log.info("password not exist"); | ||
| return false; | ||
| } | ||
| return this.password.equals(password); | ||
| } | ||
|
|
||
| public String getAccount() { | ||
| return account; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "User{" + | ||
| "id=" + id + | ||
| ", account='" + account + '\'' + | ||
| ", email='" + email + '\'' + | ||
| ", password='" + password + '\'' + | ||
| '}'; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
루트 경로에만 적용되지 않을까요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
학습 테스트의 testNoCachePrivate()가 휴리스틱 캐싱을 적용해보는 것이 의도라고 생각해서 정해진 경로만 지정하였습니다 😄