728x90

전체 글 506

구조 관련 디자인 패턴

어댑터 패턴 기존에는 Account는 security package(건드릴수없는 코드, library) 에 있었던 LoginHandler를 쓸 수 없었다. Login Handler는 UserDetailsService와 연관되어있고 UserDetailsService는 UserDetails를 return 하기 때문이다. 우리가 원하는 것은 AccountService - UserDetailService , Account - UserDetails 처럼 연결하고 싶다 하지만 AccountUserDetailsService , AccountUserDetails 가 중간에 adapter 역할을 하여 client가 LoginHandler를 원할하게 사용이 가능해졌다. public static void main(Strin..

WEB/Design Pattern 2023.01.27

객체 생성 관련 디자인 패턴

싱글턴 패턴 2 public class Settings3 { private static volatile Settings3 instance; private Settings3() { } public static Settings3 getInstance() { if (instance == null) { synchronized (Settings3.class) { if (instance == null) { instance = new Settings3(); } } } return instance; } } instance가 없는 경우에 multithread 환경에서만 synchronized가 락을 잡고 안전하게 싱글톤을 유지하게 되고 평상시 상황에는 락없이 바로 return 하게 된다. 또한 해당 instance가 필..

WEB/Design Pattern 2023.01.26

The spelled-out intro to language modeling: building makemore

['emma', 'olivia', 'ava', 'isabella', 'sophia', 'charlotte', 'mia', 'amelia', 'harper', 'evelyn'] b = {} for w in words: chs = [''] + list(w) + [''] for ch1, ch2 in zip(chs, chs[1:]): bigram = (ch1, ch2) b[bigram] = b.get(bigram, 0) + 1 sorted(b.items(), key = lambda kv: -kv[1]) [(('n', ''), 6763), (('a', ''), 6640), (('a', 'n'), 5438), (('', 'a'), 4410), (('e', ''), 3983), names.txt에 이름들에 start..

AI/Andrej Karpathy 2023.01.24

The spelled-out intro to neural networks and backpropagation: building micrograd

a = Value(2.0, label='a') b = Value(-3.0, label='b') c = Value(10.0, label='c') e = a*b; e.label = 'e' d = e + c; d.label = 'd' f = Value(-2.0, label='f') L = d * f; L.label = 'L' L 현재 dL/dd = -2 인 상태에서 chain rule 를 통해 dL/de 를 구하려면 dL/de = (dL/dd) * (dd/de) e를 변화했을떄 미치는 L의 변화 = d를 변화했을떄 L의 변화 * e를 변화했을때 d의 변화 (local derivative) + 는 여기서 router의 역할을 하게 된다 그냥 넘어온 dL/dd 를 골고루 뿌려준다. 현재 e,c local deri..

AI/Andrej Karpathy 2023.01.23

실전프로젝트 - 인가 프로세스 DB 연동 서비스 계층 구현

Method 방식 - 개요 서비스 계층의 인가처리 방식 1. 화면 , 메뉴 단위가 아닌 기능 단위로 인가처리 2. 메소드 처리 전.후 로 보안 검사 수행하여 인가처리 AOP 기반으로 동작 프록시와 어드바이스로 메소드 인가처리 수행 보안 설정 방식 어노테이션 권한 설정 방식 = @PreAuthorize("hasRole('USER')"), @PostAuthorize("hasRole('USER')"), @Secured("ROLE_USER") 맵 기반 권한 설정 방식 = 맵 기반 방식으로 외부와 연동하여 메소드 보안 설정 구현 어노테이션 권한 설정 - @PreAuthorize , @PostAuthorize , @Secured , @RolesAllowed @PreAuthorize, @PostAuthorize Sp..

WEB/Security 2023.01.20

실전프로젝트 - 인가 프로세스 DB 연동 웹 계층 구현

db와 연동하여 자원 및 권한을 설정하고 제어함으로 동적 권한 관리가 가능하도록 한다. antMatcher("/user").hasRole("USER") 없앰 웹 게반 인가처리 DB 연동 - 주요 아키텍처 이해 이제 db를 사용하니 http.anMatchers를 사용안할거지만 , 원래는 저렇게 configure해놓으면 Map으로 들고 있다가 AccessDecisionManager에게 비교할 수있게 ref를 제공해준다. 접근을 시도하려는 request's authentication의 authority를 확인하여 허용해줄지 말지를 결정하게 된다. MapBasedMethodSecurityMetadataSource 를 통해서 db에서 authority를 추출하는 방식을 사용할 수 있다. 위에 3개는 이미 구현완료..

WEB/Security 2023.01.16

실전프로젝트 - 인증 프로세스 Ajax 인증 구현

인증 필터 - AjaxAuthenticationFilter AbstractAuthenticationProcessingFilter 상속 필터 작동 조건 = AntPathRequestMatcher("/api/login") 로 요청 정보와 매칭하고 요청 방식이 Ajax이면 필터 작동 public class AjaxLoginProcessFilter extends AbstractAuthenticationProcessingFilter { private ObjectMapper objectMapper = new ObjectMapper(); public AjaxLoginProcessFilter() { super(new AntPathRequestMatcher("/api/login")); } @Override public ..

WEB/Security 2023.01.15

스프링 시큐리티 주요 아키텍처 이해

위임 필터 및 필터 빈 초기화 - DelegatingFilterProxy, FilterChainProxy DelegatingFilterProxy 는 servletContainer에서는 spring 기능을 사용하지 못하니까 요청을 FilterChainProxy에게 넘겨주는 역할을 담당한다. apache tomcat의 ApplicationChainFilter에서 DelegatingFilterProxy로 넘겨주게된다. 필터 초기화와 다중 보안 설정 여러개의 FilterSecuirtyChain 을 만들어서 FilterChainProxy에 등록을 하는과정이다. 각각의 FSC는 antMatcher를 통해 어떤 resource를 담당할지 정하게 된다. FilterChainProxy에서 등록된 여러 FSC중 Reque..

WEB/Security 2023.01.10

스프링 시큐리티 기본 API 및 Filter 이해 (안겹치는것만)

LogOut 처리, LogoutFilter RememberMeAuthentiationFilter 위에 필터가 동작하기 위한 조건 1. Security Context에 Authentication 이 null인경우 2. remember-me cookie값을 가지고 접속한 경우 둘다 충족할 떄 필터에 걸리게 된다. RemberMeService 의 구현체가 2가지 종류가 있다. TokenBased = 메모리기반 PersistentTokenBased = 디비기반 httpSecurity.rememberme() 를 통해 spring 기동시 해당 필터를 만들어주게되고 remberme cookie를 주는 시점은 첫번째로 인증을 성공하여 successfulAuthentication 메소드에서 제공해준다. 신기하게 Prov..

WEB/Security 2023.01.08

OAuth 2.0 Client + Resource Server + Authorization Server 연동

리소스 서버는 Album 자원과 Friend 자원으로 각 실행된다. 처리순서 1. 클라이언트에서 인가서버로 Authorization code grant type으로 토큰을 발급받고 이후 사용자 엔드포인트 요청으로 인증을 진행한다. 2. 클라이언트에서 인증에 성공하면 Album 리소스 서버로 자원요청을 한다. 3. Album 리소스 서버에서 Friend 리소스 서버로 토큰을 가지고 내부 통신을 통해 자원 요청을 한다. 4. 최종적으로 반환받은 Albums 와 Friend 리소스를 클라이언트로 응답한다. Authorization Code 방식으로 인증 및 userinfo 를 요청하는 과정 resource server에게 OAuth2Client 에서 Albums, Friends를 요청하는 과정 중요한것은 re..

WEB/Security 2022.12.28
728x90