분류 전체보기

    Spring Security Session을 이용한 구현 예제

    Spring Security Session을 이용한 구현 예제

    설정에 대한 설명보다는 기능 중점으로 설명을 하기 위해 Spring Boot를 활용하여 간단한 예제를 작성해보도록 하겠습니다. Token 방식을 활용한 것이 아닌 기본 Session 방식을 이용하여 Spring Security를 구현한 예제입니다. 추후에 Token 방식을 활용한 예제를 포스팅하도록 하겠습니다. 의존성 설정 dependencies { // Spring Security implementation 'org.springframework.boot:spring-boot-starter-security' } 보안 구성 파일 작성: WebSecurityConfig.java `WebSecurityConfigurerAdapter`를 상속하고 `@EnableWebSecurity` 어노테이션으로 활성화합니다...

    Spring Security 스프링 시큐리티 이해하기

    Spring Security 스프링 시큐리티 이해하기

    Spring Security Spring Security는 Spring 기반 애플리케이션에서 `보안` 기능을 쉽게 통합할 수 있도록 도와줍니다. 주로 `인증`과 `인가`를 처리하며 사용자의 신원 확인과 권한 부여를 담당합니다. Spring Security의 기능들을 나열하자면 다음과 같습니다. 인증(Authentication) 사용자의 신원을 확인(증명)하고 인증하는 기능을 제공합니다. 사용자가 제공한 자격 증명(아이디/비밀번호 등)을 검증하고, 인증된 사용자에게 접근 권한을 부여합니다. 다양한 인증 방식을 지원하며, 사용자 정의 인증 프로세스를 구현할 수 있습니다. 인가(Authorization) 인증된 사용자에 대한 권한 부여 및 접근 제어를 처리합니다. 사용자의 역할, 권한, 리소스에 대한 접근 권..

    [MyBatis + MySQL] INSERT 시 PK값 가져오기

    [MyBatis + MySQL] INSERT 시 PK값 가져오기

    코딩을 하던 중 PK 값이자 자동 증가하는 id 값을 가져와야 할 일이 생겼다. MySQL 자체 문법으로도 가능한 방법이 있지만 MyBatis에서도 기능이 있다 해서 포스팅해보겠다. Oracle 같은 경우 아래와 같은 방법으로 안되기 때문에 다른 방법(selectKey 태그 사용)으로 구현해야 하기 때문에 따로 찾아보길 바란다. INSERT INTO board( title, content, writer, views ) values( #{title}, #{content}, #{writer}, 0 ) useGeneratedKeys insert나 update됨가 동시에 자동생성된 키를 가져올 수 있는 속성으로 true로 설정 (default: false) keyProperty 리턴 될 key property ..

    [springMVC + Ajax] 게시판 첨부파일 추가

    테이블 추가 ▶attach 테이블 create table attach( uuid varchar(100) primary key, uploadPath varchar(200) not null, fileName varchar(100) not null, fileType char(3) default 'I', board_id bigint ); ALTER TABLE attach ADD FOREIGN KEY(board_id) REFERENCES board(id); uuid: UUID가 포함된 파일 이름 uploadPath: 실제 파일이 업로드된 경로 fileName: 파일 이름 fileType: 파일 종류, 이미지 파일 여부 확인 board_id: 해당 게시물 번호 저장(board 테이블, 외래키 역할) DTO ▶Boa..

    Spring + Ajax 파일 다운로드 시 Internet Explorer, Edge에서 한글이름 깨짐

    기존 코드 @GetMapping(value = "/download", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) @ResponseBody public ResponseEntity downloadFile(String fileName) { Resource resource = new FileSystemResource("D:\\upload\\" + fileName); String resourceName = resource.getFilename(); HttpHeaders headers = new HttpHeaders(); try { headers.add("Content-Disposition", "attachment; filename=" + new String(re..

    Spring + Ajax 파일 다운로드

    첨부파일 다운로드 UploadController.java @GetMapping(value = "/download", produces = MediaType.APPLICATION_OCTET_STREAM_VALUE) @ResponseBody public ResponseEntity downloadFile(String fileName) { Resource resource = new FileSystemResource("D:\\upload\\" + fileName); String resourceName = resource.getFilename(); HttpHeaders headers = new HttpHeaders(); try { headers.add("Content-Disposition", "attachment; ..

    Spring + Ajax 섬네일 파일 생성, 이미지 파일인지 구분, 이미지 클릭 시 원본 이미지 출력

    섬네일 Thumbnailator 라이브러리를 사용하하여 섬네일 파일 생성 설정 ▶pom.xml net.coobird thumbnailator 0.4.8 이미지 파일인지 구분 섬네일은 이미지 파일에만 적용할 수 있기 때문에 이미지 파일인지 구분한다. 아래 코드에 이미지 파일인 경우 섬네일 파일을 생성하는 것을 확인할 수 있다. private boolean checkImageType(File file) { try { String contentType = Files.probeContentType(file.toPath()); return contentType.startsWith("image"); } catch (IOException e) { e.printStackTrace(); } return false; } ..

    Spring + Ajax 중복된 파일 이름 해결

    중복된 파일 이름 해결하는 아이디어 파일 업로드 시간을 이용하는 방법 UUID를 이용해 중복이 발생할 가능성이 적은 문자열을 생성하는 방법 1. 파일 업로드 시간을 이용해 파일 생성 private String getFolder() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); String str = sdf.format(date); return str.replace("-", File.separator); } @PostMapping("/uploadAjaxAction") public void uploadAjaxPost(MultipartFile[] uploadFile) { String uploadFolder..