전체 글

Love what you do
안녕하세요. 이번 게시글에선 기존 세션 기반 인증에서 jwt 토큰 인증으로 변환하는 방법을 작성해보겠습니다. 초기 목표는 기존 스프링 시큐리티 디폴트 구조를 크게 벗어나지 않고 약간의 설정 변경정도로 jwt를 구현하는 것이었습니다. jwt를 프로젝트를 적용하기 위해선 다음과 같은 목표가 필요합니다.  1. 로그인 (로그인 인증)- username, password를 DB검증 후 토큰을 생성하여 반환해야합니다.- 리프레시 토큰 정보는 DB에 저장합니다. 2. 토큰 검증 (토큰 인증 및 인가)- 전달받은 토큰을 인증 및 파싱하여 principal을 가져온 후 (username) 해당 정보로 DB에서 권한을 조회하여 인가합니다.- 리프레시 토큰이 만료되지 않았다면 리프레시 토큰을 갱신하여 DB에 저장합니다. ..
2차원 행렬에서 이진 탐색으로 데이터 찾기row x col 행렬 데이터가 주어졌을 때, target 을 이진 탐색으로 찾는 프로그램을 작성하세요.각 행의 데이터는 오름차순으로 정렬 상태입출력 예시행렬: {{1, 3, 7, 8}, {10, 11, 15, 20}, {21, 30, 35, 60}}target: 3출력: truetarget: 13출력: false public class Main { public static boolean solution(int[][] matrix, int target) { int rows = matrix.length; int cols = matrix[0].length; int result = binarySearch(matrix, targ..
원형 정렬 상태 배열에서의 이진 탐색nums 배열에 원형 상태로 데이터가 정렬되어 있을 때, 이진 탐색으로 데이터를 찾는 프로그램을 작성하세요.O(log n) 유지배열을 재 정렬하지 않고 풀기입출력 예시arr: 4, 5, 6, 7, 8, 0, 1, 2target: 0출력: 5arr: 8, 0, 1, 2, 4, 5, 6, 7,target: 3출력: -1public class Main { public static int solution(int[] arr, int target) { return binarySearch(arr, target, 0, arr.length - 1); } public static int binarySearch(int[] arr, int target, int..
target 값이 arr 내에 있으면 해당 인덱스 반환없으면 해당 값이 있을 경우의 위치에 -1을 곱하고 1을 뺀 값을 반환입출력 예시입력 arr: 1, 2, 5, 10, 20, 30, 40, 50, 60target: 30출력: 5target: 3출력: -3public class Practice { public static int binarySearch(int[] arr, int target, int left, int right) { if (left > right) { //항상 left가 대상인 이유 -> 재귀 끝나는 순간 -> right, left가 되고 사이에 값이 들어가야하므로 left자리가 대상값의 위치가 된다! return (left * ..
정수 배열 nums 가 주어졌을 때 오름차순으로 정렬하기 위해 배열 내에서 정렬이 필요한 구간의 길이를 출력하는 프로그램을 작성하세요. 입출력 예시 입력: 2, 6, 4, 8, 5, 3, 9, 10 출력: 5 입력: 1, 3, 1 출력: 2 내 풀이public class Main { public static int solution(int[] nums) { int startIdx = 0; int endIdx = 0; // max 보다 크면서 이후로 작은 값이 없는 것이 endIdx.. -> 해설과 차이나는 부분! startIdx = getStartIdx(nums); if(startIdx == -1){ return 0; } endIdx = getEndIdx(nums, startIdx); return endI..
이번 게시글에선 저번에 분석한 스프링 시큐리티를 바탕으로 커스텀 구현을 해보겠습니다. 목표는 기존 폼 형식 로그인 방식을 Jwt 로그인 방식으로 변경하는 것입니다.  저번에 분석했던 스프링 시큐리티의 폼 로그인 흐름을 간략히  정리해볼까요?  UsernamePasswordAuthenticationFilter폼 요청으로 미인증된 Authentication 생성, AuthenticationManager에 미인증 Authentication 전달 AuthenticationManager - ProviderManager AuthenticationProvider에 미인증 Authentication 전달 AuthenticationProvider - DaoAuthenticationProviderUserDetailsSer..
기수정렬public class Main { // 기수정렬 -> 큐를 이용하여 낮은 자리수부터 비교.. private static void radixSort(int[] arr) { Queue[] queueArr = new Queue[10]; //0부터 9까지 for (int i = 0; i (); } int maxLen = getMaxLen(arr); int div = 1; int idx = 0; for (int i = 0; i  계수정렬public class Main2 { public static void countingSort(int[] arr) { int maxNumber = Array..
public class Main { public static void quickSort(int[] arr, int left, int right) { if (left >= right) { return; } int pivot = partition(arr, left, right); quickSort(arr, left, pivot - 1); quickSort(arr, pivot + 1, right); } public static int partition(int[] arr, int left, int right) { int pivot = left; int lo = left; //arr[lo]가..
스프링 시큐리티에서 json 형식으로 로그인 하는 것을 구현해보려고 합니다. 그러기 위해서 먼저 스프링 시큐리티에서 제공하는 기본 형식인 폼 로그인(formLogin) 방식에 대해 먼저 분석해보고, 해당 구조를 커스텀해보겠습니다. 스프링 시큐리티가 구성된 프로젝트는 기본적으로 폼 로그인이 적용됩니다. 또한 개발자가 서블릿 기반 시큐리티 설정을 추가하게 되면 아래와 같이 폼 로그인을 별로도 설정할 수 있습니다. @Configuration@EnableWebSecuritypublic class SecurityConfig { @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { ..
public class Main { public static void heapSort(int[] arr) { for (int i = arr.length / 2 - 1; i >= 0; i--) { // 마지막 부모부터 힙정렬하며 올리기 heapify(arr, i, arr.length); } // 모든 부모가 자식보다 큰 상태 //인덱스 0이 최대값 -> 계속 뒤로 보내며 힙정렬하기 //length 마지막에 max를 swap하며 length를 하나씩 줄인다 //마지막 0은 필요없음 (최소값 배치되있음) for (int i = arr.length - 1; i > 0; i--) { ..
꾸준함의 미더덕
꾸준함의 미더덕