최초 커밋!
This commit is contained in:
16
core/src/main/java/app/module/core/CoreApplication.java
Normal file
16
core/src/main/java/app/module/core/CoreApplication.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package app.module.core;
|
||||
|
||||
import app.module.core.config.application.component.YamlPropertySourceFactory;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableCaching
|
||||
@PropertySource(value = "classpath:core.yml", factory = YamlPropertySourceFactory.class)
|
||||
@PropertySource(
|
||||
value = "classpath:core-${spring.profiles.active}.yml",
|
||||
factory = YamlPropertySourceFactory.class)
|
||||
public class CoreApplication {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package app.module.core.config.adapters.persistence.component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 생성 및 수정 기록을 위한 공용 엔티티 속성. Admin 앱의 경우, LoginUserAuditAware.java (AuditorAware 구현체) 가 반환한 현재 작성자
|
||||
* 정보를 담는다.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class AuditEntity {
|
||||
|
||||
private LocalDateTime createdAt;
|
||||
private String createdBy;
|
||||
private LocalDateTime updatedAt;
|
||||
private String updatedBy;
|
||||
private LocalDateTime deletedAt;
|
||||
private String deletedBy;
|
||||
private Boolean isDeleted;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package app.module.core.config.adapters.persistence.component;
|
||||
|
||||
import app.module.core.config.application.enums.FileUploadType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 파일 업로드 정보를 담는 공용 엔티티 속성. 다른 엔티티에 탑재(embed)되어 사용된다.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FileUploadInfoEmbeddable {
|
||||
|
||||
private FileUploadType type;
|
||||
|
||||
private String path;
|
||||
|
||||
private String name;
|
||||
|
||||
private String originName;
|
||||
|
||||
private Long fileLength;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Admin extends AuditEntity {
|
||||
private String id;
|
||||
private String password;
|
||||
private String email;
|
||||
private LocalDateTime passwordUpdatedAt;
|
||||
private Boolean accountDisabled;
|
||||
private Integer loginFailCnt;
|
||||
private Boolean accountLocked;
|
||||
|
||||
public Admin(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AdminHasRole extends AuditEntity {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String adminId;
|
||||
|
||||
private String roleId;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class Article extends AuditEntity {
|
||||
private Long id;
|
||||
private String title;
|
||||
private String content;
|
||||
private Boolean visible;
|
||||
private LocalDateTime startDate;
|
||||
private LocalDateTime endDate;
|
||||
private Integer orderNo;
|
||||
private List<UploadFile> uploadFiles = Collections.emptyList();
|
||||
private List<ArticleComment> articleComments = Collections.emptyList();
|
||||
|
||||
public Article(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Article(
|
||||
Long id,
|
||||
String title,
|
||||
String content,
|
||||
Boolean visible,
|
||||
LocalDateTime startDate,
|
||||
LocalDateTime endDate,
|
||||
Integer orderNo,
|
||||
List<UploadFile> uploadFiles) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.content = content;
|
||||
this.visible = visible;
|
||||
this.startDate = startDate;
|
||||
this.endDate = endDate;
|
||||
this.orderNo = orderNo;
|
||||
this.uploadFiles = (uploadFiles != null) ? uploadFiles : Collections.emptyList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ArticleComment extends AuditEntity {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String content;
|
||||
|
||||
private Long articleId;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ArticleHasUploadFile extends AuditEntity {
|
||||
private Long articleId;
|
||||
private Long uploadFilesId;
|
||||
|
||||
public ArticleHasUploadFile(Long articleId) {
|
||||
this.articleId = articleId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import app.module.core.config.application.enums.SignUpType;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FrontUser extends AuditEntity {
|
||||
|
||||
private String id;
|
||||
private String password;
|
||||
private String email;
|
||||
private String nickname;
|
||||
private SignUpType signUpType;
|
||||
private LocalDateTime passwordUpdatedAt;
|
||||
private Boolean accountDisabled;
|
||||
private Integer loginFailCnt;
|
||||
private Boolean accountLocked;
|
||||
// private String roleId;
|
||||
private String uploadFileId;
|
||||
|
||||
public FrontUser(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public FrontUser(String id, String email, String nickname, Boolean accountDisabled,
|
||||
Integer loginFailCnt, Boolean accountLocked) {
|
||||
this.id = id;
|
||||
this.email = email;
|
||||
this.nickname = nickname;
|
||||
this.accountDisabled = accountDisabled;
|
||||
this.loginFailCnt = loginFailCnt;
|
||||
this.accountLocked = accountLocked;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class FrontUserHasRole extends AuditEntity {
|
||||
private Long id;
|
||||
private String frontUSerId;
|
||||
private String roleId;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FrontUserHasUploadFile extends AuditEntity {
|
||||
private String frontUserId;
|
||||
private Long uploadFilesId;
|
||||
|
||||
public FrontUserHasUploadFile(String frontUserId) {
|
||||
this.frontUserId = frontUserId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import app.module.core.config.application.enums.SocialType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class FrontUserSocial extends AuditEntity {
|
||||
|
||||
private Integer seq;
|
||||
|
||||
private String userId;
|
||||
|
||||
private SocialType socialType;
|
||||
|
||||
private String socialId;
|
||||
|
||||
private String email;
|
||||
|
||||
private String name;
|
||||
|
||||
private String ci;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 동시접속 사용자 체크를 위한 기록용 엔티티
|
||||
*/
|
||||
@Builder
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class LoggedInUser extends AuditEntity {
|
||||
private AppType appType;
|
||||
private String id;
|
||||
private String clientIP;
|
||||
private LocalDateTime lastLoggedInAt;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.config.application.enums.OperationLogType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class OperationLog extends AuditEntity {
|
||||
|
||||
private Long id;
|
||||
|
||||
private AppType appType;
|
||||
|
||||
private OperationLogType operationLogType;
|
||||
|
||||
private String targetId;
|
||||
|
||||
private String ip;
|
||||
|
||||
private String taskDesc;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import java.util.Date;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Spring Security - Remember me 기능을 위한 엔티티
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class PersistentLogins extends AuditEntity {
|
||||
|
||||
private String series;
|
||||
private String username;
|
||||
private String token;
|
||||
private Date lastUsed;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class Privilege extends AuditEntity {
|
||||
private String id;
|
||||
private String description;
|
||||
private AppType appType;
|
||||
private Integer orderNo;
|
||||
|
||||
public Privilege(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import java.util.Set;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class Role extends AuditEntity {
|
||||
|
||||
private String id;
|
||||
private String description;
|
||||
private AppType appType;
|
||||
private Integer orderNo;
|
||||
private Set<RoleHasPrivilege> hasPrivileges;
|
||||
|
||||
public Role(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Role(String id, Set<RoleHasPrivilege> hasPrivileges) {
|
||||
this.id = id;
|
||||
this.hasPrivileges = hasPrivileges;
|
||||
}
|
||||
|
||||
public Role(String id, String description, AppType appType, Integer orderNo) {
|
||||
this.id = id;
|
||||
this.description = description;
|
||||
this.appType = appType;
|
||||
this.orderNo = orderNo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class RoleHasPrivilege extends AuditEntity {
|
||||
|
||||
private Integer id;
|
||||
|
||||
private String roleId;
|
||||
|
||||
private String privilegeId;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import java.util.Set;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@RequiredArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UICode extends AuditEntity {
|
||||
|
||||
private String id;
|
||||
|
||||
private String parentId;
|
||||
|
||||
private Integer orderNo;
|
||||
|
||||
private String codeText;
|
||||
|
||||
private String codeValue;
|
||||
|
||||
private String msgCode;
|
||||
|
||||
private Boolean inUse;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import java.util.Set;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@Builder(toBuilder = true)
|
||||
@NoArgsConstructor
|
||||
public class URI extends AuditEntity {
|
||||
|
||||
private String id;
|
||||
|
||||
private AppType appType;
|
||||
|
||||
private String parentId;
|
||||
|
||||
private Integer orderNo;
|
||||
|
||||
private String text;
|
||||
|
||||
private String uri;
|
||||
|
||||
private Boolean showOnNavi;
|
||||
|
||||
private String ogTitle;
|
||||
|
||||
private String ogDesc;
|
||||
|
||||
private String ogKeywords;
|
||||
|
||||
private String ogImage;
|
||||
|
||||
/**
|
||||
* JPA 에서 재귀 쿼리를 구현하는 하나의 방법 - https://stackoverflow.com/questions/3638082/recursive-jpa-query
|
||||
* "This will cause multiple queries , but for small menu like things it will be ok."
|
||||
*/
|
||||
private Set<String> children;
|
||||
|
||||
private Set<String> roles;
|
||||
|
||||
public URI(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import app.module.core.config.application.enums.FileUploadType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UploadFile extends AuditEntity {
|
||||
|
||||
private Long id;
|
||||
|
||||
private FileUploadType type;
|
||||
|
||||
private String path;
|
||||
|
||||
private String name;
|
||||
|
||||
private String originName;
|
||||
|
||||
private Long fileLength;
|
||||
|
||||
public UploadFile(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package app.module.core.config.adapters.persistence.entity;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UriHasRole extends AuditEntity {
|
||||
|
||||
private Long id;
|
||||
|
||||
private String uriId;
|
||||
|
||||
private String roleId;
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package app.module.core.config.adapters.persistence.initData;
|
||||
|
||||
import app.module.core.usecase.admin.saveAdmin.ports.SaveAdminPortIn;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@Order(3)
|
||||
public class InitAdminData implements ApplicationRunner {
|
||||
|
||||
private final SaveAdminPortIn saveAdminPortIn;
|
||||
|
||||
@Value("${app.initData.core}")
|
||||
private boolean isCoreDataRequired;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
if (!isCoreDataRequired) {
|
||||
return;
|
||||
}
|
||||
|
||||
saveAdminPortIn.connect(
|
||||
"recycle-super", "recycle1@#$", "super@framework.org", false, false,
|
||||
List.of("ROLE_SUPER"));
|
||||
|
||||
saveAdminPortIn.connect(
|
||||
"recycle-manager",
|
||||
"manager1@#$",
|
||||
"manager@framework.org",
|
||||
false,
|
||||
false,
|
||||
List.of("ROLE_MANAGER"));
|
||||
|
||||
saveAdminPortIn.connect(
|
||||
"recycle-staff", "staff1@#$", "staff@framework.org", false, false,
|
||||
List.of("ROLE_STAFF"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package app.module.core.config.adapters.persistence.initData;
|
||||
|
||||
import app.module.core.config.adapters.persistence.initData.helper.RemoveAllArticleRepo;
|
||||
import app.module.core.usecase.article.createArticle.ports.CreateArticlePortIn;
|
||||
import app.module.core.usecase.article.createArticle.ports.application.domain.CreateArticleCmd;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.stream.IntStream;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class InitArticleData implements ApplicationRunner {
|
||||
|
||||
private final CreateArticlePortIn createArticlePortIn;
|
||||
private final RemoveAllArticleRepo removeAllArticleRepo;
|
||||
|
||||
@Value("${app.initData.core}")
|
||||
private boolean isCoreDataRequired;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
if (!isCoreDataRequired) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* // 전체 데이터 삭제
|
||||
removeAllArticleRepo.deleteAll();
|
||||
|
||||
IntStream.range(0, 25)
|
||||
.forEach(
|
||||
idx ->
|
||||
createArticlePortIn.operate(
|
||||
new CreateArticleCmd(
|
||||
String.format("Article No.%s", idx),
|
||||
String.format("Content No.%s", idx),
|
||||
true,
|
||||
LocalDateTime.now(),
|
||||
LocalDateTime.now().plusMonths(2),
|
||||
null)));*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package app.module.core.config.adapters.persistence.initData;
|
||||
|
||||
import app.module.core.config.application.enums.SignUpType;
|
||||
import app.module.core.usecase.user.createUser.ports.CreateUserPortIn;
|
||||
import app.module.core.usecase.user.createUser.ports.application.domain.CreateUserCmd;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@Order(3)
|
||||
public class InitFrontUserData implements ApplicationRunner {
|
||||
|
||||
private final CreateUserPortIn createUserPortIn;
|
||||
|
||||
@Value("${app.initData.core}")
|
||||
private boolean isCoreDataRequired;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
if (!isCoreDataRequired) {
|
||||
return;
|
||||
}
|
||||
|
||||
createUserPortIn.operate(
|
||||
new CreateUserCmd(
|
||||
"generalUser",
|
||||
"generalUser1@#$",
|
||||
"general-user@recycle.com",
|
||||
"recycle-사용자",
|
||||
SignUpType.NORMAL,
|
||||
false,
|
||||
0,
|
||||
false,
|
||||
Set.of("ROLE_GENERAL")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package app.module.core.config.adapters.persistence.initData;
|
||||
|
||||
import app.module.core.config.adapters.persistence.entity.Privilege;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.usecase.privilege.save.adapters.persistence.PrivilegeSaveRepo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Order(1)
|
||||
public class InitPrivilegeData implements ApplicationRunner {
|
||||
|
||||
private final PrivilegeSaveRepo privilegeRepo;
|
||||
|
||||
@Value("${app.initData.core}")
|
||||
private boolean isCoreDataRequired;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
if (!isCoreDataRequired) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*privilegeRepo.save(new Privilege("ADMIN_API", "ADMIN API 이용 권한", AppType.ADMIN, 0));
|
||||
privilegeRepo.save(new Privilege("ADMIN_ACCESS", "ADMIN 사이트 접근 권한", AppType.ADMIN, 1));*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package app.module.core.config.adapters.persistence.initData;
|
||||
|
||||
import app.module.core.config.adapters.persistence.entity.Privilege;
|
||||
import app.module.core.config.adapters.persistence.entity.Role;
|
||||
import app.module.core.config.adapters.persistence.entity.RoleHasPrivilege;
|
||||
import app.module.core.config.adapters.persistence.repository.PrivilegeRepo;
|
||||
import app.module.core.config.adapters.persistence.repository.RoleRepo;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Order(2)
|
||||
public class InitRoleData implements ApplicationRunner {
|
||||
|
||||
private final RoleRepo roleRepo;
|
||||
private final PrivilegeRepo privilegeViewRepo;
|
||||
|
||||
@Value("${app.initData.core}")
|
||||
private boolean isCoreDataRequired;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
if (!isCoreDataRequired) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 권한 `privilege` 정보 가져오기
|
||||
/*Privilege apiPrivilege = privilegeViewRepo.findById("ADMIN_API").orElseThrow();
|
||||
Privilege privilege = privilegeViewRepo.findById("ADMIN_ACCESS").orElseThrow();*/
|
||||
|
||||
int orderNo = 0;
|
||||
|
||||
/*roleRepo.save(
|
||||
new Role(
|
||||
"ROLE_SUPER",
|
||||
"SUPER 관리자",
|
||||
AppType.ADMIN,
|
||||
orderNo++,
|
||||
Set.of(
|
||||
new RoleHasPrivilege(null, new Role("ROLE_SUPER"), apiPrivilege),
|
||||
new RoleHasPrivilege(null, new Role("ROLE_SUPER"), privilege))));
|
||||
|
||||
roleRepo.save(
|
||||
new Role(
|
||||
"ROLE_MANAGER",
|
||||
"매니저",
|
||||
AppType.ADMIN,
|
||||
orderNo++,
|
||||
Set.of(
|
||||
new RoleHasPrivilege(null, new Role("ROLE_MANAGER"), apiPrivilege),
|
||||
new RoleHasPrivilege(null, new Role("ROLE_MANAGER"), privilege))));
|
||||
|
||||
roleRepo.save(
|
||||
new Role(
|
||||
"ROLE_STAFF",
|
||||
"스텝",
|
||||
AppType.ADMIN,
|
||||
orderNo++,
|
||||
Set.of(
|
||||
new RoleHasPrivilege(null, new Role("ROLE_STAFF"), apiPrivilege),
|
||||
new RoleHasPrivilege(null, new Role("ROLE_STAFF"), privilege))));*/
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package app.module.core.config.adapters.persistence.initData;
|
||||
|
||||
import app.module.core.usecase.uicode.save.ports.UICodeSavePortIn;
|
||||
import app.module.core.usecase.uicode.save.ports.application.domain.UICodeSaveCommand;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class InitUICodeData implements ApplicationRunner {
|
||||
|
||||
private final UICodeSavePortIn uiCodeSavePortIn;
|
||||
|
||||
@Value("${app.initData.core}")
|
||||
private boolean isCoreDataRequired;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
if (!isCoreDataRequired) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String UICODE = "code";
|
||||
final String UICODE_PAGEABLE = "code.pageable";
|
||||
final String UICODE_PAGEABLE_ROWS = "code.pageable.rows";
|
||||
|
||||
// root 노드 - code
|
||||
uiCodeSavePortIn.connect(
|
||||
new UICodeSaveCommand(UICODE, null, null, "UI Code", "", null, true), false);
|
||||
|
||||
// code - board
|
||||
uiCodeSavePortIn.connect(
|
||||
new UICodeSaveCommand(UICODE_PAGEABLE, UICODE, 0, "Pageable", "", null, true), false);
|
||||
|
||||
// code - board - rows
|
||||
uiCodeSavePortIn.connect(
|
||||
new UICodeSaveCommand(UICODE_PAGEABLE_ROWS, UICODE_PAGEABLE, 0, "ROW 갯수", "", null,
|
||||
true),
|
||||
false);
|
||||
|
||||
uiCodeSavePortIn.connect(
|
||||
new UICodeSaveCommand(
|
||||
UICODE_PAGEABLE_ROWS + ".10", UICODE_PAGEABLE_ROWS, 1, "10", "10", null, true),
|
||||
false);
|
||||
|
||||
uiCodeSavePortIn.connect(
|
||||
new UICodeSaveCommand(
|
||||
UICODE_PAGEABLE_ROWS + ".20", UICODE_PAGEABLE_ROWS, 2, "20", "20", null, true),
|
||||
false);
|
||||
|
||||
uiCodeSavePortIn.connect(
|
||||
new UICodeSaveCommand(
|
||||
UICODE_PAGEABLE_ROWS + ".50", UICODE_PAGEABLE_ROWS, 3, "50", "50", null, true),
|
||||
false);
|
||||
|
||||
uiCodeSavePortIn.connect(
|
||||
new UICodeSaveCommand(
|
||||
UICODE_PAGEABLE_ROWS + ".100", UICODE_PAGEABLE_ROWS, 4, "100", "100", null, true),
|
||||
false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,382 @@
|
||||
package app.module.core.config.adapters.persistence.initData;
|
||||
|
||||
import app.module.core.config.adapters.persistence.initData.helper.RemoveAllAdminURIRepo;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.usecase.uri.save.ports.URISavePortIn;
|
||||
import app.module.core.usecase.uri.save.ports.application.domain.URISaveCommand;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@Order(3)
|
||||
public class InitUriAdminData implements ApplicationRunner {
|
||||
|
||||
private final URISavePortIn uriSavePortIn;
|
||||
private final RemoveAllAdminURIRepo removeAllAdminURIRepo;
|
||||
|
||||
@Value("${app.initData.core}")
|
||||
private boolean isCoreDataRequired;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void run(ApplicationArguments args) throws IOException {
|
||||
if (!isCoreDataRequired) {
|
||||
return;
|
||||
}
|
||||
|
||||
removeAllAdminURIRepo.deleteAllByAppType(AppType.ADMIN);
|
||||
|
||||
final String ADMIN = "uri.admin";
|
||||
|
||||
final String ADMIN_BOARD = "uri.admin.board";
|
||||
|
||||
final String ADMIN_ARTICLE = "uri.admin.board.article";
|
||||
final String ADMIN_ARTICLE_CREATE = "uri.admin.board.article.create";
|
||||
final String ADMIN_ARTICLE_UPDATE = "uri.admin.board.article.update.{{pathVar}}";
|
||||
final String ADMIN_ARTICLE_DELETE = "uri.admin.board.article.delete";
|
||||
final String ADMIN_ARTICLE_EXCEL = "uri.admin.board.article.excel";
|
||||
|
||||
final String ADMIN_SETTINGS = "uri.admin.settings";
|
||||
|
||||
final String ADMIN_SETTINGS_ADMIN_GROUP = "uri.admin.settings.admins.group";
|
||||
final String ADMIN_SETTINGS_ADMIN = "uri.admin.settings.admins";
|
||||
final String ADMIN_SETTINGS_ADMIN_CREATE = "uri.admin.settings.admins.create";
|
||||
final String ADMIN_SETTINGS_ADMIN_UPDATE = "uri.admin.settings.admins.update.{{pathVar}}";
|
||||
final String ADMIN_SETTINGS_ADMIN_DELETE = "uri.admin.settings.admins.delete";
|
||||
final String ADMIN_SETTINGS_ADMIN_EXCEL = "uri.admin.settings.admins.excel";
|
||||
final String ADMIN_SETTINGS_ADMIN_ROLE = "uri.admin.settings.adminRoles";
|
||||
final String ADMIN_SETTINGS_ADMIN_PRIVILEGE = "uri.admin.settings.adminPrivilege";
|
||||
|
||||
final String ADMIN_SETTINGS_USER_GROUP = "uri.admin.settings.user.group";
|
||||
final String ADMIN_SETTINGS_USER = "uri.admin.settings.user";
|
||||
final String ADMIN_SETTINGS_USER_UPDATE = "uri.admin.settings.user.update";
|
||||
final String ADMIN_SETTINGS_USER_ROLE = "uri.admin.settings.user.role";
|
||||
final String ADMIN_SETTINGS_USER_PRIVILEGE = "uri.admin.settings.user.privilege";
|
||||
|
||||
final String ADMIN_SETTINGS_URI_ADMIN = "uri.admin.settings.uri.admin";
|
||||
final String ADMIN_SETTINGS_URI_FRONT = "uri.admin.settings.uri.front";
|
||||
final String ADMIN_SETTINGS_CODE = "uri.admin.settings.uicode";
|
||||
|
||||
final String ADMIN_ANALYSIS = "uri.admin.analysis";
|
||||
final String ADMIN_ANALYSIS_OPERATION_LOG = "uri.admin.analysis.operationLog";
|
||||
final String ADMIN_ANALYSIS_OPERATION_LOG_UPDATE =
|
||||
"uri.admin.analysis.operationLog.{{pathVar}}";
|
||||
final String ADMIN_ANALYSIS_OPERATION_LOG_EXCEL = "uri.admin.analysis.operationLog.excel";
|
||||
|
||||
final String ADMIN_ADD_ONS = "uri.admin.addons";
|
||||
final String ADMIN_ADD_ONS_SEND_EMAIL = "uri.admin.addons.email";
|
||||
final String ADMIN_ADD_ONS_SEND_EMAIL_CREATE = "uri.admin.addons.email.create";
|
||||
|
||||
// 최상위 URI 정보
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
null,
|
||||
ADMIN,
|
||||
"메인",
|
||||
"/",
|
||||
true,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER", "ROLE_STAFF"));
|
||||
|
||||
// `1` depth URI 정의 - 시작
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN,
|
||||
ADMIN_SETTINGS,
|
||||
"Settings",
|
||||
"/true",
|
||||
true,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
appendURI(AppType.ADMIN, ADMIN, ADMIN_ANALYSIS, "분석", "/analysis", true,
|
||||
Set.of("ROLE_SUPER"));
|
||||
|
||||
appendURI(AppType.ADMIN, ADMIN, ADMIN_BOARD, "게시판", "/board", true, Set.of("ROLE_SUPER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN,
|
||||
ADMIN_ADD_ONS,
|
||||
"Add-ons (부가기능)",
|
||||
"/add-ons",
|
||||
true,
|
||||
Set.of("ROLE_SUPER"));
|
||||
// `1` depth URI 정의 - 끝
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS,
|
||||
ADMIN_SETTINGS_ADMIN_GROUP,
|
||||
"관리자 & 역할",
|
||||
"/settings/adminGroup",
|
||||
true,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS_ADMIN_GROUP,
|
||||
ADMIN_SETTINGS_ADMIN,
|
||||
"관리자 목록",
|
||||
"/settings/admins",
|
||||
true,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS_ADMIN,
|
||||
ADMIN_SETTINGS_ADMIN_CREATE,
|
||||
"관리자 등록",
|
||||
"/settings/admins/create",
|
||||
false,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS_ADMIN,
|
||||
ADMIN_SETTINGS_ADMIN_UPDATE,
|
||||
"관리자 수정",
|
||||
"/settings/admins/update/{{pathVar}}",
|
||||
false,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS_ADMIN,
|
||||
ADMIN_SETTINGS_ADMIN_DELETE,
|
||||
"관리자 삭제",
|
||||
"/settings/admins/delete",
|
||||
false,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS_ADMIN,
|
||||
ADMIN_SETTINGS_ADMIN_EXCEL,
|
||||
"관리자 엑셀 다운로드",
|
||||
"/settings/admins/excel",
|
||||
false,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS_ADMIN_GROUP,
|
||||
ADMIN_SETTINGS_ADMIN_ROLE,
|
||||
"관리자 역할",
|
||||
"/settings/adminRoles",
|
||||
true,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS_ADMIN_GROUP,
|
||||
ADMIN_SETTINGS_ADMIN_PRIVILEGE,
|
||||
"관리자 권한",
|
||||
"/settings/adminPrivilege",
|
||||
true,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
// 사용자 & 역할 - 시작
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS,
|
||||
ADMIN_SETTINGS_USER_GROUP,
|
||||
"사용자 & 역할",
|
||||
"/settings/userGroup",
|
||||
true,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS_USER_GROUP,
|
||||
ADMIN_SETTINGS_USER,
|
||||
"사용자 목록",
|
||||
"/settings/users",
|
||||
true,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS_USER,
|
||||
ADMIN_SETTINGS_USER_UPDATE,
|
||||
"사용자 수정",
|
||||
"/settings/users/{{pathVar}}",
|
||||
false,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS_USER_GROUP,
|
||||
ADMIN_SETTINGS_USER_ROLE,
|
||||
"사용자 역할",
|
||||
"/settings/userRoles",
|
||||
true,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS_USER_GROUP,
|
||||
ADMIN_SETTINGS_USER_PRIVILEGE,
|
||||
"사용자 권한",
|
||||
"/settings/userPrivilege",
|
||||
true,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
// 사용자 & 역할 - 끝
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS,
|
||||
ADMIN_SETTINGS_URI_ADMIN,
|
||||
"URI 관리 (관리자)",
|
||||
"/settings/uri/ADMIN",
|
||||
true,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS,
|
||||
ADMIN_SETTINGS_URI_FRONT,
|
||||
"URI 관리 (FRONT)",
|
||||
"/settings/uri/FRONT",
|
||||
true,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_SETTINGS,
|
||||
ADMIN_SETTINGS_CODE,
|
||||
"UI 코드 (공통코드)",
|
||||
"/settings/uicode",
|
||||
true,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER"));
|
||||
|
||||
// 예제 게시판 - 시작
|
||||
//
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_BOARD,
|
||||
ADMIN_ARTICLE,
|
||||
"예제 게시판",
|
||||
"/board/articles",
|
||||
true,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER", "ROLE_STAFF"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_ARTICLE,
|
||||
ADMIN_ARTICLE_CREATE,
|
||||
"예제 게시판 등록",
|
||||
"/board/articles/create",
|
||||
false,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER", "ROLE_STAFF"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_ARTICLE,
|
||||
ADMIN_ARTICLE_UPDATE,
|
||||
"예제 게시판 수정",
|
||||
"/board/articles/{{pathVar}}",
|
||||
false,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER", "ROLE_STAFF"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_ARTICLE,
|
||||
ADMIN_ARTICLE_DELETE,
|
||||
"예제 게시판 삭제",
|
||||
"/board/articles/delete",
|
||||
false,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER", "ROLE_STAFF"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_ARTICLE,
|
||||
ADMIN_ARTICLE_EXCEL,
|
||||
"예제 게시판 엑셀 다운로드",
|
||||
"/board/articles/excel",
|
||||
false,
|
||||
Set.of("ROLE_SUPER", "ROLE_MANAGER", "ROLE_STAFF"));
|
||||
// 예제 게시판 - 끝
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_ANALYSIS,
|
||||
ADMIN_ANALYSIS_OPERATION_LOG,
|
||||
"Operation Log (수행로그)",
|
||||
"/analysis/operationlog",
|
||||
true,
|
||||
Set.of("ROLE_SUPER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_ANALYSIS,
|
||||
ADMIN_ANALYSIS_OPERATION_LOG_UPDATE,
|
||||
"수행로그 상세",
|
||||
"/analysis/operationlog/{{pathVar}}",
|
||||
false,
|
||||
Set.of("ROLE_SUPER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_ANALYSIS_OPERATION_LOG,
|
||||
ADMIN_ANALYSIS_OPERATION_LOG_EXCEL,
|
||||
"수행로그 Excel",
|
||||
"/analysis/operationlog/excel",
|
||||
false,
|
||||
Set.of("ROLE_SUPER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_ADD_ONS,
|
||||
ADMIN_ADD_ONS_SEND_EMAIL,
|
||||
"Email 발송",
|
||||
"/addons/email/form",
|
||||
true,
|
||||
Set.of("ROLE_SUPER"));
|
||||
|
||||
appendURI(
|
||||
AppType.ADMIN,
|
||||
ADMIN_ADD_ONS_SEND_EMAIL,
|
||||
ADMIN_ADD_ONS_SEND_EMAIL_CREATE,
|
||||
"Email 입력폼",
|
||||
"/addons/email/form",
|
||||
false,
|
||||
Set.of("ROLE_SUPER"));
|
||||
}
|
||||
|
||||
private void appendURI(
|
||||
AppType appType,
|
||||
String parentId,
|
||||
String menuId,
|
||||
String menuTitle,
|
||||
String uri,
|
||||
boolean showOnNavi,
|
||||
Set<String> roles)
|
||||
throws IOException {
|
||||
uriSavePortIn.connect(
|
||||
new URISaveCommand(
|
||||
menuId,
|
||||
parentId,
|
||||
appType,
|
||||
uri,
|
||||
showOnNavi,
|
||||
menuTitle,
|
||||
null,
|
||||
menuTitle,
|
||||
menuTitle,
|
||||
null,
|
||||
null,
|
||||
roles),
|
||||
null,
|
||||
false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
package app.module.core.config.adapters.persistence.initData;
|
||||
|
||||
import app.module.core.config.adapters.persistence.initData.helper.RemoveAllFrontURIRepo;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import app.module.core.usecase.uri.save.ports.URISavePortIn;
|
||||
import app.module.core.usecase.uri.save.ports.application.domain.URISaveCommand;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
@Order(3)
|
||||
public class InitUriFrontData implements ApplicationRunner {
|
||||
|
||||
private final URISavePortIn uriSavePortIn;
|
||||
private final RemoveAllFrontURIRepo removeAllFrontURIRepo;
|
||||
|
||||
@Value("${app.initData.core}")
|
||||
private boolean isCoreDataRequired;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void run(ApplicationArguments args) throws IOException {
|
||||
if (!isCoreDataRequired) {
|
||||
return;
|
||||
}
|
||||
|
||||
removeAllFrontURIRepo.deleteAllByAppType(AppType.FRONT);
|
||||
|
||||
final String FRONT_ROOT_ID = "uri.front";
|
||||
|
||||
uriSavePortIn.connect(
|
||||
new URISaveCommand(
|
||||
FRONT_ROOT_ID,
|
||||
null,
|
||||
AppType.FRONT,
|
||||
"/",
|
||||
true,
|
||||
"프론트",
|
||||
null,
|
||||
"프론트 홈",
|
||||
"프론트 메인",
|
||||
"front",
|
||||
null,
|
||||
null),
|
||||
null,
|
||||
false);
|
||||
|
||||
// 로그인
|
||||
uriSavePortIn.connect(
|
||||
new URISaveCommand(
|
||||
FRONT_ROOT_ID + ".login",
|
||||
FRONT_ROOT_ID,
|
||||
AppType.FRONT,
|
||||
"/login",
|
||||
false,
|
||||
"로그인",
|
||||
null,
|
||||
"로그인",
|
||||
"로그인 페이지",
|
||||
"front",
|
||||
null,
|
||||
null),
|
||||
null,
|
||||
false);
|
||||
|
||||
// 회원가입
|
||||
uriSavePortIn.connect(
|
||||
new URISaveCommand(
|
||||
FRONT_ROOT_ID + ".user.register",
|
||||
FRONT_ROOT_ID,
|
||||
AppType.FRONT,
|
||||
"/user/register",
|
||||
false,
|
||||
"회원가입",
|
||||
null,
|
||||
"회원가입",
|
||||
"회원가입 페이지",
|
||||
"회원가입",
|
||||
null,
|
||||
null),
|
||||
null,
|
||||
false);
|
||||
|
||||
// 정보수정
|
||||
uriSavePortIn.connect(
|
||||
new URISaveCommand(
|
||||
FRONT_ROOT_ID + ".user.info",
|
||||
FRONT_ROOT_ID,
|
||||
AppType.FRONT,
|
||||
"/user/info",
|
||||
false,
|
||||
"정보수정",
|
||||
null,
|
||||
"정보수정",
|
||||
"정보수정 페이지",
|
||||
"정보수정",
|
||||
null,
|
||||
Set.of("ROLE_GENERAL")),
|
||||
null,
|
||||
false);
|
||||
|
||||
// 예제게시판
|
||||
uriSavePortIn.connect(
|
||||
new URISaveCommand(
|
||||
FRONT_ROOT_ID + ".board.articles",
|
||||
FRONT_ROOT_ID,
|
||||
AppType.FRONT,
|
||||
"/board/articles",
|
||||
true,
|
||||
"예제게시판",
|
||||
null,
|
||||
"예제게시판",
|
||||
"예제게시판 페이지",
|
||||
"예제게시판",
|
||||
null,
|
||||
Set.of("ROLE_GENERAL")),
|
||||
null,
|
||||
false);
|
||||
|
||||
// 예제 게시판 등록
|
||||
uriSavePortIn.connect(
|
||||
new URISaveCommand(
|
||||
FRONT_ROOT_ID + ".board.article.create",
|
||||
FRONT_ROOT_ID,
|
||||
AppType.FRONT,
|
||||
"/board/articles/create",
|
||||
false,
|
||||
"예제 게시판 등록",
|
||||
null,
|
||||
"예제 게시판 등록",
|
||||
"예제 게시판 등록 페이지",
|
||||
"예제 게시판 등록",
|
||||
null,
|
||||
Set.of("ROLE_GENERAL")),
|
||||
null,
|
||||
false);
|
||||
|
||||
// 예제 게시판 상세
|
||||
uriSavePortIn.connect(
|
||||
new URISaveCommand(
|
||||
FRONT_ROOT_ID + ".board.article.{{pathVar}}",
|
||||
FRONT_ROOT_ID,
|
||||
AppType.FRONT,
|
||||
"/board/articles/{{pathVar}}",
|
||||
false,
|
||||
"예제 게시판 상세",
|
||||
null,
|
||||
"예제 게시판 상세",
|
||||
"예제 게시판 상세 페이지",
|
||||
"예제 게시판 상세",
|
||||
null,
|
||||
Set.of("ROLE_GENERAL")),
|
||||
null,
|
||||
false);
|
||||
|
||||
// 예제 게시판 수정
|
||||
uriSavePortIn.connect(
|
||||
new URISaveCommand(
|
||||
FRONT_ROOT_ID + ".board.article.update.{{pathVar}}",
|
||||
FRONT_ROOT_ID,
|
||||
AppType.FRONT,
|
||||
"/board/articles/update/{{pathVar}}",
|
||||
false,
|
||||
"예제 게시판 수정",
|
||||
null,
|
||||
"예제 게시판 수정",
|
||||
"예제 게시판 수정 페이지",
|
||||
"예제 게시판 수정",
|
||||
null,
|
||||
Set.of("ROLE_GENERAL")),
|
||||
null,
|
||||
false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package app.module.core.config.adapters.persistence.initData;
|
||||
|
||||
import app.module.core.usecase.userPrivilege.saveUserPrivilege.ports.SaveUserPrivilegePortIn;
|
||||
import app.module.core.usecase.userPrivilege.saveUserPrivilege.ports.application.domain.SaveUserPrivilegeCmd;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Order(1)
|
||||
public class InitUserPrivilegeData implements ApplicationRunner {
|
||||
|
||||
private final SaveUserPrivilegePortIn saveUserPrivilegePortIn;
|
||||
|
||||
@Value("${app.initData.core}")
|
||||
private boolean isCoreDataRequired;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
if (!isCoreDataRequired) {
|
||||
return;
|
||||
}
|
||||
|
||||
saveUserPrivilegePortIn.operate(new SaveUserPrivilegeCmd("FRONT_API", "Front API 사용권한", 0));
|
||||
saveUserPrivilegePortIn.operate(
|
||||
new SaveUserPrivilegeCmd("FRONT_ACCESS", "Front 사이트 접근 권한", 1));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package app.module.core.config.adapters.persistence.initData;
|
||||
|
||||
import app.module.core.usecase.userRole.saveUserRole.ports.SaveUserRolePortIn;
|
||||
import app.module.core.usecase.userRole.saveUserRole.ports.application.domain.SaveUserRoleCmd;
|
||||
import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Order(2)
|
||||
public class InitUserRoleData implements ApplicationRunner {
|
||||
|
||||
private final SaveUserRolePortIn saveUserRolePortIn;
|
||||
|
||||
@Value("${app.initData.core}")
|
||||
private boolean isCoreDataRequired;
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
if (!isCoreDataRequired) {
|
||||
return;
|
||||
}
|
||||
|
||||
saveUserRolePortIn.operate(
|
||||
new SaveUserRoleCmd("ROLE_GENERAL", "일반 사용자", 0, List.of("FRONT_API", "FRONT_ACCESS")));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package app.module.core.config.adapters.persistence.initData.helper;
|
||||
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface RemoveAllAdminURIRepo {
|
||||
|
||||
void deleteAllByAppType(AppType appType);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package app.module.core.config.adapters.persistence.initData.helper;
|
||||
|
||||
import app.module.core.config.adapters.persistence.entity.Article;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface RemoveAllArticleRepo {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package app.module.core.config.adapters.persistence.initData.helper;
|
||||
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface RemoveAllFrontURIRepo {
|
||||
|
||||
void deleteAllByAppType(AppType appType);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.core.config.adapters.persistence.repository;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface AdminRepo {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package app.module.core.config.adapters.persistence.repository;
|
||||
|
||||
import app.module.core.config.adapters.persistence.entity.ArticleComment;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ArticleCommentRepo {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.core.config.adapters.persistence.repository;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ArticleRepo {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package app.module.core.config.adapters.persistence.repository;
|
||||
|
||||
import app.module.core.config.adapters.persistence.entity.Privilege;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface FrontUserPrivilegeRepo {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.core.config.adapters.persistence.repository;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface FrontUserRepo {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package app.module.core.config.adapters.persistence.repository;
|
||||
|
||||
import app.module.core.config.adapters.persistence.entity.Role;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
@Mapper
|
||||
public interface FrontUserRoleRepo {
|
||||
|
||||
List<Role> findByAppType(AppType appType, Sort sort);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.core.config.adapters.persistence.repository;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface OperationLogRepo {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.module.core.config.adapters.persistence.repository;
|
||||
|
||||
import app.module.core.config.adapters.persistence.entity.Privilege;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
@Mapper
|
||||
public interface PrivilegeRepo {
|
||||
List<Privilege> findByAppType(AppType appType, Sort sort);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package app.module.core.config.adapters.persistence.repository;
|
||||
|
||||
import app.module.core.config.adapters.persistence.entity.Role;
|
||||
import app.module.core.config.application.enums.AppType;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
@Mapper
|
||||
public interface RoleRepo {
|
||||
|
||||
List<Role> findAllByAppType(AppType appType, Sort sort);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.core.config.adapters.persistence.repository;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface UICodeRepo {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.core.config.adapters.persistence.repository;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface URIRepo {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.core.config.adapters.persistence.repository;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface UploadFileRepo {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package app.module.core.config.adapters.web;
|
||||
|
||||
import app.module.core.config.application.exception.NoMatchingURIException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
/**
|
||||
* 인터셉터에서 던진 예외를 GlobalControllerAdvice 에서 처리하지 못한다. 인터셉터에서 예외 발생 시 /error/interceptor URL 로 포워딩 시켜
|
||||
* Controller 단에서 예외를 다시 발생시켜 GlobalControllerAdvice 가 처리할 수 있도록 한다. 참고 -
|
||||
* https://dev-monkey-dugi.tistory.com/136
|
||||
*/
|
||||
@Controller
|
||||
public class InterceptorErrorController {
|
||||
|
||||
@GetMapping("/error/interceptor")
|
||||
public void error(HttpServletRequest request) {
|
||||
String message = (String) request.getAttribute("message");
|
||||
String exception = (String) request.getAttribute("exception");
|
||||
|
||||
switch (exception) {
|
||||
case "NoMatchingURIException":
|
||||
throw new NoMatchingURIException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
package app.module.core.config.adapters.web.advice;
|
||||
|
||||
import app.module.core.config.application.exception.NoMatchingURIException;
|
||||
import app.module.core.config.application.util.CommonUtil;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.ControllerAdvice;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* 전역 예외 제어 객체.
|
||||
*/
|
||||
@ControllerAdvice
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class GlobalControllerAdvice {
|
||||
|
||||
@ExceptionHandler({RuntimeException.class})
|
||||
public Object runtimeException(RuntimeException e, Model model, HttpServletRequest request) {
|
||||
log.error(
|
||||
"[ERROR INFO] - '{}' {}",
|
||||
request.getMethod(),
|
||||
request.getRequestURL()
|
||||
+ (request.getQueryString() == null ? "" : "?" + request.getQueryString()));
|
||||
log.error("[ERROR DETAIL]", e);
|
||||
|
||||
if (CommonUtil.isAjaxRequest(request)) {
|
||||
// ajax 요청일 경우
|
||||
return getResponseBody(e);
|
||||
|
||||
} else if (request.getRequestURI().startsWith("/v1/")) {
|
||||
// API 요청일 경우
|
||||
return getResponseBody(e);
|
||||
} else {
|
||||
// 일반 요청일 경우
|
||||
model.addAttribute("error", e.getClass().getSimpleName());
|
||||
model.addAttribute("message", e.getMessage());
|
||||
|
||||
return "error/500";
|
||||
}
|
||||
}
|
||||
|
||||
@ExceptionHandler({NoMatchingURIException.class})
|
||||
public Object noMatchingURI(NoMatchingURIException e, Model model) {
|
||||
model.addAttribute("error", "NoMatchingURIException");
|
||||
model.addAttribute("message", e.getMessage());
|
||||
|
||||
log.error("NoMatchingURIException - {}", e.getMessage());
|
||||
|
||||
return "error/404";
|
||||
}
|
||||
|
||||
@ExceptionHandler({AccessDeniedException.class})
|
||||
public Object runtimeException(AccessDeniedException e, Model model) {
|
||||
model.addAttribute("error", e.getClass().getSimpleName());
|
||||
model.addAttribute("message", e.getMessage());
|
||||
|
||||
Optional.ofNullable(SecurityContextHolder.getContext().getAuthentication())
|
||||
.ifPresent(
|
||||
authentication -> {
|
||||
model.addAttribute("name", authentication.getName());
|
||||
model.addAttribute("authorities", authentication.getAuthorities());
|
||||
});
|
||||
|
||||
log.error("[error]", e);
|
||||
|
||||
return "error/403";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
public ResponseEntity<GlobalRestExceptionVO> getResponseBody(RuntimeException e) {
|
||||
HttpStatus httpStatus = null;
|
||||
switch (e.getClass().getSimpleName()) {
|
||||
case "UnAcceptableFileException":
|
||||
httpStatus = HttpStatus.UNPROCESSABLE_ENTITY;
|
||||
break;
|
||||
default:
|
||||
httpStatus = HttpStatus.BAD_REQUEST;
|
||||
break;
|
||||
}
|
||||
|
||||
return ResponseEntity.status(httpStatus)
|
||||
.body(new GlobalRestExceptionVO(e.getClass().getSimpleName(), e.getMessage()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package app.module.core.config.adapters.web.advice;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Rest API 예외 처리 DTO
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class GlobalRestExceptionVO {
|
||||
|
||||
private String exception;
|
||||
private String message;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package app.module.core.config.adapters.web.config;
|
||||
|
||||
import app.module.core.config.adapters.web.interceptor.AuditFieldInterceptor;
|
||||
import org.mybatis.spring.boot.autoconfigure.ConfigurationCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class MyBatisConfig {
|
||||
|
||||
@Bean
|
||||
public AuditFieldInterceptor auditFieldInterceptor() {
|
||||
return new AuditFieldInterceptor();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ConfigurationCustomizer mybatisConfigurationCustomizer(AuditFieldInterceptor interceptor) {
|
||||
return configuration -> configuration.addInterceptor(interceptor);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package app.module.core.config.adapters.web.interceptor;
|
||||
|
||||
import app.module.core.config.adapters.persistence.component.AuditEntity;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.executor.Executor;
|
||||
import org.apache.ibatis.mapping.MappedStatement;
|
||||
import org.apache.ibatis.mapping.SqlCommandType;
|
||||
import org.apache.ibatis.plugin.Interceptor;
|
||||
import org.apache.ibatis.plugin.Intercepts;
|
||||
import org.apache.ibatis.plugin.Invocation;
|
||||
import org.apache.ibatis.plugin.Signature;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
@Intercepts({
|
||||
@Signature(type = Executor.class, method = "update", args = {MappedStatement.class, Object.class})
|
||||
})
|
||||
public class AuditFieldInterceptor implements Interceptor {
|
||||
private static final List<String> IGNORE_AUDIT_QUERIES = Arrays.asList(
|
||||
"app.module.core.usecase.supplyhistory.mapper.SupplyRequestHistoryMapper.insertSupplyRequestHistory"
|
||||
// 예외 처리할 쿼리 ID들을 추가하세요.
|
||||
);
|
||||
|
||||
@Override
|
||||
public Object intercept(Invocation invocation) throws Throwable {
|
||||
MappedStatement ms = (MappedStatement) invocation.getArgs()[0];
|
||||
Object parameter = invocation.getArgs()[1];
|
||||
|
||||
SqlCommandType sqlCommandType = ms.getSqlCommandType();
|
||||
String statementId = ms.getId();
|
||||
|
||||
// Audit 대상이 아니거나, 예외 처리 쿼리 리스트에 포함된 경우 바로 진행
|
||||
if (!(parameter instanceof AuditEntity) || IGNORE_AUDIT_QUERIES.contains(statementId)) {
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
String userId = getCurrentUserId();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
AuditEntity auditEntity = (AuditEntity) parameter;
|
||||
|
||||
if (SqlCommandType.INSERT.equals(sqlCommandType)) {
|
||||
auditEntity.setCreatedBy(userId);
|
||||
auditEntity.setCreatedAt(now);
|
||||
auditEntity.setUpdatedBy(userId);
|
||||
auditEntity.setUpdatedAt(now);
|
||||
auditEntity.setIsDeleted(false);
|
||||
} else if (SqlCommandType.UPDATE.equals(sqlCommandType)) {
|
||||
auditEntity.setUpdatedBy(userId);
|
||||
auditEntity.setUpdatedAt(now);
|
||||
}
|
||||
|
||||
return invocation.proceed();
|
||||
}
|
||||
|
||||
private String getCurrentUserId() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication == null || !authentication.isAuthenticated() || authentication.getPrincipal() instanceof String) {
|
||||
return "anonymous";
|
||||
}
|
||||
|
||||
return ((UserDetails) authentication.getPrincipal()).getUsername();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package app.module.core.config.adapters.web.interceptor;
|
||||
|
||||
import app.module.core.usecase.uri.currentmatch.ports.application.domain.URICurrentMatching;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.util.Set;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class URIAuthorizeInterceptor implements HandlerInterceptor {
|
||||
|
||||
/**
|
||||
* 인증 받은 사용자를 대상으로 요청 리소스에 접근가능한 역할(+권한)인지를 검증한다. 인증을 받지 않은 익명 사용자의 경우 해당 인터셉터는 동작하지 않는다.
|
||||
*
|
||||
* @param request
|
||||
* @param response
|
||||
* @param handler
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean preHandle(
|
||||
HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
|
||||
// 이전 UriInterceptor 로 부터 전달받은 값.
|
||||
URICurrentMatching currentURI = (URICurrentMatching) request.getAttribute("currentURI");
|
||||
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
|
||||
Set<String> currentUriRoles = currentURI.getRoles();
|
||||
|
||||
auth.getAuthorities().stream()
|
||||
.filter(grantedAuthority -> currentUriRoles.contains(grantedAuthority.getAuthority()))
|
||||
.findFirst()
|
||||
.orElseThrow(
|
||||
() ->
|
||||
new AccessDeniedException(
|
||||
String.format(
|
||||
"[URIAuthorizeInterceptor - AccessDenied] %s to %s",
|
||||
auth.getName(), currentURI.getUri())));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package app.module.core.config.adapters.web.interceptor.model;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class URITopTierVO {
|
||||
|
||||
private String id;
|
||||
private String text;
|
||||
private String uri;
|
||||
private Boolean showOnNavi;
|
||||
private List<URITopTierVO> children;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package app.module.core.config.adapters.web.rest.error;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class RestErrorVO {
|
||||
|
||||
private List<RestObjectErrorVO> objectErrors;
|
||||
private List<RestFieldErrorVO> fieldErrors;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.module.core.config.adapters.web.rest.error;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* Rest API Validation 실패 처리 DTO
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class RestFieldErrorVO {
|
||||
|
||||
private String field;
|
||||
private String message;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package app.module.core.config.adapters.web.rest.error;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class RestObjectErrorVO {
|
||||
|
||||
private String message;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.module.core.config.adapters.web.rest.response;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@Builder
|
||||
@Data
|
||||
public class RestResponse<T> {
|
||||
|
||||
private String message;
|
||||
|
||||
private T item;
|
||||
private List<T> items;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.core.config.adapters.web.security.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CorePrivilege {
|
||||
private String id;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package app.module.core.config.adapters.web.security.domain;
|
||||
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CoreRole {
|
||||
private String id;
|
||||
private String description;
|
||||
private List<CorePrivilege> privileges;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package app.module.core.config.adapters.web.security.domain;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import lombok.Getter;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.oauth2.core.user.DefaultOAuth2User;
|
||||
|
||||
@Getter
|
||||
public class SocialUser extends DefaultOAuth2User {
|
||||
|
||||
private final String username;
|
||||
private final String password;
|
||||
private final boolean enabled;
|
||||
private final boolean accountNonExpired;
|
||||
private final boolean credentialsNonExpired;
|
||||
private final boolean accountNonLocked;
|
||||
private final String nickname;
|
||||
private final long remainPasswordDays;
|
||||
|
||||
public SocialUser(
|
||||
Collection<? extends GrantedAuthority> authorities,
|
||||
Map<String, Object> attributes,
|
||||
String nameAttributeKey,
|
||||
String username,
|
||||
String password,
|
||||
boolean enabled,
|
||||
boolean accountNonExpired,
|
||||
boolean credentialsNonExpired,
|
||||
boolean accountNonLocked,
|
||||
String nickname,
|
||||
long remainPasswordDays) {
|
||||
super(authorities, attributes, nameAttributeKey);
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.enabled = enabled;
|
||||
this.accountNonExpired = accountNonExpired;
|
||||
this.credentialsNonExpired = credentialsNonExpired;
|
||||
this.accountNonLocked = accountNonLocked;
|
||||
this.nickname = nickname;
|
||||
this.remainPasswordDays = remainPasswordDays;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package app.module.core.config.adapters.web.security.entrypoint;
|
||||
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class CustomAuthenticationEntryPoint implements AuthenticationEntryPoint {
|
||||
|
||||
@Override
|
||||
public void commence(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
AuthenticationException authException)
|
||||
throws IOException, ServletException {
|
||||
|
||||
// AJAX 요청인지 확인
|
||||
if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) {
|
||||
response.setContentType("application/json;charset=UTF-8");
|
||||
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
||||
response
|
||||
.getWriter()
|
||||
.write(
|
||||
String.format(
|
||||
"{\"error\":\"UNAUTHORIZED\", \"message\":\"로그인이 필요합니다.\", \"path\":\"%s\", \"status\":403}",
|
||||
request.getRequestURI()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package app.module.core.config.application.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
// escape 필드 치환을 위한 annotation
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.FIELD)
|
||||
public @interface EscapeXSS {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package app.module.core.config.application.aop;
|
||||
|
||||
import app.module.core.config.application.annotation.EscapeXSS;
|
||||
import java.lang.reflect.Field;
|
||||
import org.apache.commons.text.StringEscapeUtils;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* XSS 공격을 방지하기 위한 Aspect 클래스입니다.
|
||||
*
|
||||
* @EscapeXSS 어노테이션이 붙은 String 필드의 값을 HTML 이스케이프 처리합니다.
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class XssEscapeAspect {
|
||||
|
||||
/**
|
||||
* app.module 패키지 의 usecase 하위 패키지의 모든 메소드 실행을 가로채는 Around 어드바이스입니다.
|
||||
*
|
||||
* @param joinPoint 가로챈 메소드의 실행 시점을 나타내는 객체
|
||||
* @return 원본 메소드의 실행 결과
|
||||
* @throws Throwable 메소드 실행 중 발생할 수 있는 예외
|
||||
*/
|
||||
// 성능에 대한 영향을 고려해 usecase 하위 패키지로 설정. 패턴에 따라 더 구체적인 경로가 있을수록 성능에 영향이 줄어듬
|
||||
@Around("execution(* app.module.*.usecase..*.*(..)) && args(..)")
|
||||
public Object escapeXss(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
Object[] args = joinPoint.getArgs();
|
||||
// 각 인자에 대해 처리를 수행합니다.
|
||||
for (Object arg : args) {
|
||||
if (arg != null) {
|
||||
// 인자 객체의 모든 필드를 가져옵니다.
|
||||
Field[] fields = arg.getClass().getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
// @EscapeXSS 어노테이션이 붙어있고, String 타입인 필드만 처리합니다.
|
||||
if (field.isAnnotationPresent(EscapeXSS.class)
|
||||
&& field.getType() == String.class) {
|
||||
// private 필드에 접근할 수 있도록 설정합니다.
|
||||
field.setAccessible(true);
|
||||
// 필드의 현재 값을 가져옵니다.
|
||||
String value = (String) field.get(arg);
|
||||
if (value != null) {
|
||||
// HTML 이스케이프 처리를 수행하고 결과를 다시 필드에 설정합니다.
|
||||
field.set(arg, StringEscapeUtils.escapeHtml4(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return joinPoint.proceed(args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package app.module.core.config.application.beans;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.tika.Tika;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Description;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class CoreBeans {
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper() {
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
// 자바 LocalDateTime 타입을 인식시키기 위해 선언.
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
// LocalDateTime 타입을 JSON 으로 직렬화하는 과정에서 ISO string 타입으로 변환하기 위한 선언.
|
||||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
// 값이 없는 텅빈 객체도 파싱할 수 있도록 선언.
|
||||
objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
|
||||
// 자바 객체 속성에 없는 필드가 있어도 역직렬화가 진행되도록 선언.
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
return objectMapper;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Description("Apache Tika - a content analysis toolkit")
|
||||
public Tika tika() {
|
||||
return new Tika();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public BCryptPasswordEncoder passwordEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package app.module.core.config.application.component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
public interface AuditOutput {
|
||||
|
||||
String getCreatedBy();
|
||||
|
||||
LocalDateTime getCreatedAt();
|
||||
|
||||
String getUpdatedBy();
|
||||
|
||||
LocalDateTime getUpdatedAt();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package app.module.core.config.application.component;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 상세 화면에서 목록 페이지의 페이징 정보를 기억하기 위함.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
public class ListPageableInfo {
|
||||
|
||||
private int page;
|
||||
private String sort;
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package app.module.core.config.application.component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Objects;
|
||||
import java.util.Properties;
|
||||
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
|
||||
import org.springframework.core.env.PropertiesPropertySource;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.core.io.support.EncodedResource;
|
||||
import org.springframework.core.io.support.PropertySourceFactory;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
public class YamlPropertySourceFactory implements PropertySourceFactory {
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public PropertySource<?> createPropertySource(String name, EncodedResource resource)
|
||||
throws IOException {
|
||||
YamlPropertiesFactoryBean factory = new YamlPropertiesFactoryBean();
|
||||
factory.setResources(resource.getResource());
|
||||
Properties properties = factory.getObject();
|
||||
assert properties != null;
|
||||
return new PropertiesPropertySource(
|
||||
Objects.requireNonNull(resource.getResource().getFilename()), properties);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package app.module.core.config.application.converter;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.databind.JsonSerializer;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* RestController 응답시 LocalDateTime 필드 속성의 JSON 직렬화를 위해 선언됨.
|
||||
*/
|
||||
public class CustomLocalDateTimeSerializer extends JsonSerializer<LocalDateTime> {
|
||||
|
||||
private static final DateTimeFormatter formatter =
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
||||
|
||||
@Override
|
||||
public void serialize(
|
||||
LocalDateTime localDateTime,
|
||||
JsonGenerator jsonGenerator,
|
||||
SerializerProvider serializerProvider)
|
||||
throws IOException {
|
||||
jsonGenerator.writeString(formatter.format(localDateTime));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package app.module.core.config.application.converter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.thymeleaf.util.StringUtils;
|
||||
|
||||
/**
|
||||
* String 문자열을 LocalDateTime 으로 변환해주는 Converter. 현재 사용하지 않는다!
|
||||
*/
|
||||
@Component
|
||||
public class StringToLocalDateTimeConverter implements Converter<String, LocalDateTime> {
|
||||
|
||||
@Override
|
||||
public LocalDateTime convert(String source) {
|
||||
return StringUtils.isEmpty(source) ? null : LocalDateTime.parse(source);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package app.module.core.config.application.enums;
|
||||
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum AcceptableFileType {
|
||||
// 이미지 파일
|
||||
IMAGE(
|
||||
Set.of("jpg", "jpeg", "png", "gif", "bmp"),
|
||||
Set.of(
|
||||
"image/jpeg",
|
||||
"image/pjpeg",
|
||||
"image/png",
|
||||
"image/gif",
|
||||
"image/bmp",
|
||||
"image/x-windows-bmp")),
|
||||
// Office - Excel 파일
|
||||
EXCEL(
|
||||
Set.of("xlsx", "xlsm", "xlsb", "xltx", "xltm", "xls", "xlt", "xlam", "xla", "xlw", "xlr"),
|
||||
Set.of(
|
||||
"application/excel",
|
||||
"application/vnd.ms-excel",
|
||||
"application/x-excel",
|
||||
"application/x-tika-ooxml",
|
||||
"application/x-tika-msoffice",
|
||||
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"application/x-msexcel")),
|
||||
// Office - Power Point
|
||||
PPT(
|
||||
Set.of("ppt", "pptx"),
|
||||
Set.of(
|
||||
"application/mspowerpoint",
|
||||
"application/powerpoint",
|
||||
"application/vnd.ms-powerpoint",
|
||||
"application/x-tika-ooxml",
|
||||
"application/x-mspowerpoint")),
|
||||
// Office - Word
|
||||
WORD(
|
||||
Set.of("doc", "docx"),
|
||||
Set.of(
|
||||
"application/msword",
|
||||
"application/vnd.ms-word.document.macroEnabled.12",
|
||||
"application/x-tika-ooxml",
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document")),
|
||||
// 한글
|
||||
HWP(
|
||||
Set.of("hwp", "hwpx"),
|
||||
Set.of(
|
||||
"application/x-hwp",
|
||||
"application/haansofthwp",
|
||||
"application/vnd.hancom.hwp",
|
||||
"application/x-tika-msoffice",
|
||||
"application/vnd.hancom.hwpx")),
|
||||
// TXT
|
||||
TXT(Set.of("txt"), Set.of("text/plain")),
|
||||
// CSV
|
||||
CSV(Set.of("csv"), Set.of("text/csv", "text/plain")),
|
||||
// PDF
|
||||
PDF(Set.of("pdf"), Set.of("application/pdf")),
|
||||
// ZIP
|
||||
ZIP(
|
||||
Set.of("zip", "gzip", "gz"),
|
||||
Set.of(
|
||||
"application/x-compressed",
|
||||
"application/x-zip-compressed",
|
||||
"application/zip",
|
||||
"multipart/x-zip",
|
||||
"application/x-gzip",
|
||||
"multipart/x-gzip"));
|
||||
|
||||
private final Set<String> extensions;
|
||||
private final Set<String> mimeTypes;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.module.core.config.application.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum AppType {
|
||||
FRONT("FRONT APP"),
|
||||
ADMIN("ADMIN APP");
|
||||
private final String desc;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.module.core.config.application.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum ContentDispositionType {
|
||||
INLINE("인라인 방식"),
|
||||
ATTACHMENT("리소스 강제 다운로드 방식");
|
||||
private final String desc;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.module.core.config.application.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum FileStorageType {
|
||||
LOCAL("로컬 스토리지"),
|
||||
S3("AWS S3 스토리지");
|
||||
private final String desc;
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package app.module.core.config.application.enums;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
|
||||
public enum FileUploadType {
|
||||
// URI og:image 용 이미지 파일
|
||||
OG_IMAGE(FileStorageType.LOCAL, "/ogImage", Set.of(AcceptableFileType.IMAGE)),
|
||||
// WEB Editor 이미지 파일
|
||||
EDITOR_IMAGE(FileStorageType.LOCAL, "/editorImage", Set.of(AcceptableFileType.IMAGE)),
|
||||
// 예제 게시판 대표 이미지
|
||||
EXAMPLE_REP(FileStorageType.LOCAL, "/exampleBoard", Set.of(AcceptableFileType.IMAGE)),
|
||||
// 예제 게시판 PUBLIC 다건 파일 업로드
|
||||
EXAMPLE_PUBLIC(
|
||||
FileStorageType.LOCAL,
|
||||
"/exampleBoard",
|
||||
Set.of(
|
||||
AcceptableFileType.IMAGE,
|
||||
AcceptableFileType.EXCEL,
|
||||
AcceptableFileType.PPT,
|
||||
AcceptableFileType.HWP,
|
||||
AcceptableFileType.WORD,
|
||||
AcceptableFileType.CSV,
|
||||
AcceptableFileType.TXT,
|
||||
AcceptableFileType.PDF,
|
||||
AcceptableFileType.ZIP)),
|
||||
// 예제 게시판 PRIVATE 다건 파일 업로드
|
||||
EXAMPLE_PRIVATE(
|
||||
FileStorageType.LOCAL,
|
||||
"/exampleBoard",
|
||||
Set.of(
|
||||
AcceptableFileType.IMAGE,
|
||||
AcceptableFileType.EXCEL,
|
||||
AcceptableFileType.PPT,
|
||||
AcceptableFileType.HWP,
|
||||
AcceptableFileType.WORD,
|
||||
AcceptableFileType.CSV,
|
||||
AcceptableFileType.TXT,
|
||||
AcceptableFileType.PDF,
|
||||
AcceptableFileType.ZIP)),
|
||||
// 사용자 프로필 이미지
|
||||
PROFILE_IMG(FileStorageType.LOCAL, "/profileImage", Set.of(AcceptableFileType.IMAGE));
|
||||
|
||||
private final FileStorageType fileStorageType;
|
||||
private final String subPath;
|
||||
private final Set<AcceptableFileType> acceptableFileTypes;
|
||||
|
||||
// enum 자료형을 json 으로 변환시 enum name 을 참조하기 위함
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.module.core.config.application.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum OperationLogType {
|
||||
LOGIN_SUCCESS("접속 성공"),
|
||||
LOGIN_FAIL("접속 실패"),
|
||||
ROLE_UPDATE("권한 수정"),
|
||||
ACCOUNT_LOCKED("계정 잠김");
|
||||
|
||||
private final String desc;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.module.core.config.application.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum OrderDir {
|
||||
DESC("내림차순"),
|
||||
ASC("오름차순");
|
||||
private final String desc;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package app.module.core.config.application.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum PublicAccess {
|
||||
STATIC("정적 자원", "/static/**"),
|
||||
PUBLIC_INLINE("공개파일 inline 참조", "/content-disposition/inline/**"),
|
||||
PUBLIC_ATTACH("공개파일 attachment 참조", "/content-disposition/attachment/**"),
|
||||
CACHE_REFRESH("캐시 리프레시", "/refresh/cacheable/**"),
|
||||
PUBLIC_API("공개 API", "/api/public/**"),
|
||||
ERROR("에러 페이지", "/error"),
|
||||
FAVICON("파비콘", "/favicon.ico"),
|
||||
LOGIN("로그인 페이지", "/login"),
|
||||
LOGOUT("로그아웃", "/logout"),
|
||||
INTERCEPTOR_ERROR("인터셉터 에러 포워딩", "/error/interceptor");
|
||||
|
||||
private final String desc;
|
||||
private final String path;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package app.module.core.config.application.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum SaveType {
|
||||
CREATE,
|
||||
UPDATE;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package app.module.core.config.application.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum SignUpType {
|
||||
NORMAL("일반 회원가입"),
|
||||
SOCIAL("소셜 로그인 회원가입");
|
||||
|
||||
private final String desc;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package app.module.core.config.application.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum SocialType {
|
||||
KAKAO("카카오 로그인", "kakao"),
|
||||
NAVER("네이버 로그인", "naver"),
|
||||
APPLE("애플 로그인", "apple");
|
||||
|
||||
private final String desc;
|
||||
private final String registrationId;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.core.config.application.exception;
|
||||
|
||||
public class AlreadyExistItemException extends RuntimeException {
|
||||
|
||||
public AlreadyExistItemException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.core.config.application.exception;
|
||||
|
||||
public class AlreadyExistsRoleException extends RuntimeException {
|
||||
|
||||
public AlreadyExistsRoleException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package app.module.core.config.application.exception;
|
||||
|
||||
public class NoMatchingURIException extends RuntimeException {
|
||||
|
||||
public NoMatchingURIException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public NoMatchingURIException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.core.config.application.exception;
|
||||
|
||||
public class NonRemovableItemException extends RuntimeException {
|
||||
|
||||
public NonRemovableItemException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package app.module.core.config.application.exception;
|
||||
|
||||
import app.module.core.config.application.enums.FileUploadType;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 파일 업로드 시 Validation 에 위배될 때 발생하는 커스텀 RuntimeException
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class UnAcceptableFileException extends RuntimeException {
|
||||
|
||||
private String message;
|
||||
private FileUploadType fileUploadType;
|
||||
|
||||
public UnAcceptableFileException(FileUploadType fileUploadType, String message) {
|
||||
super(message);
|
||||
this.fileUploadType = fileUploadType;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package app.module.core.config.application.util;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Base64;
|
||||
import javax.crypto.BadPaddingException;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.spec.IvParameterSpec;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AESEncryptUtil {
|
||||
|
||||
@Value("${encrypt.aes.key}")
|
||||
private String key;
|
||||
|
||||
@Value("${encrypt.aes.iv}")
|
||||
private String iv;
|
||||
|
||||
public String encrypt(String text)
|
||||
throws NoSuchPaddingException, NoSuchAlgorithmException, BadPaddingException,
|
||||
IllegalBlockSizeException, InvalidAlgorithmParameterException, InvalidKeyException {
|
||||
Cipher cipher = Cipher.getInstance(getTransformation());
|
||||
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES");
|
||||
IvParameterSpec ivParamSpec = new IvParameterSpec(iv.getBytes());
|
||||
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivParamSpec);
|
||||
|
||||
byte[] encrypted = cipher.doFinal(text.getBytes(StandardCharsets.UTF_8));
|
||||
return Base64.getEncoder().encodeToString(encrypted);
|
||||
}
|
||||
|
||||
public String decrypt(String cipherText)
|
||||
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
|
||||
InvalidKeyException, BadPaddingException, IllegalBlockSizeException {
|
||||
Cipher cipher = Cipher.getInstance(getTransformation());
|
||||
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES");
|
||||
IvParameterSpec ivParamSpec = new IvParameterSpec(iv.getBytes());
|
||||
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivParamSpec);
|
||||
|
||||
byte[] decodedBytes = Base64.getDecoder().decode(cipherText);
|
||||
byte[] decrypted = cipher.doFinal(decodedBytes);
|
||||
return new String(decrypted, StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
private String getTransformation() {
|
||||
return "AES/CBC/PKCS5Padding";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package app.module.core.config.application.util;
|
||||
|
||||
import app.module.core.config.adapters.web.security.domain.SocialUser;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.oauth2.core.user.DefaultOAuth2User;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.Errors;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
|
||||
public class CommonUtil {
|
||||
|
||||
/**
|
||||
* 문자열의 마지막 lastChar 를 제거 후 반환
|
||||
*
|
||||
* @param str 문자열
|
||||
* @param lastChar 제거할 마지막 문자
|
||||
* @return 마지막 문자가 제거된 문자열
|
||||
*/
|
||||
public static String removeLastChar(String str, String lastChar) {
|
||||
if (str == null) {
|
||||
return "";
|
||||
}
|
||||
return str.endsWith(lastChar) ? str.substring(0, str.length() - lastChar.length()) : str;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ajax 요청 여부 판단
|
||||
*
|
||||
* @param request HttpServletRequest
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isAjaxRequest(HttpServletRequest request) {
|
||||
return "XMLHttpRequest".equals(request.getHeader("X-Requested-With"));
|
||||
}
|
||||
|
||||
public static String getFileExtension(String filename) {
|
||||
return Optional.ofNullable(filename)
|
||||
.filter(f -> f.contains("."))
|
||||
.map(f -> f.substring(filename.lastIndexOf(".") + 1).toLowerCase())
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public static String getClientIP(HttpServletRequest request) {
|
||||
String ip = request.getHeader("X-Forwarded-For");
|
||||
|
||||
if (ip == null) {
|
||||
ip = request.getHeader("Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null) {
|
||||
ip = request.getHeader("WL-Proxy-Client-IP");
|
||||
}
|
||||
if (ip == null) {
|
||||
ip = request.getHeader("HTTP_CLIENT_IP");
|
||||
}
|
||||
if (ip == null) {
|
||||
ip = request.getHeader("HTTP_X_FORWARDED_FOR");
|
||||
}
|
||||
if (ip == null) {
|
||||
ip = request.getRemoteAddr();
|
||||
}
|
||||
|
||||
return ip;
|
||||
}
|
||||
|
||||
public static String getLoginUsername() {
|
||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (authentication == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object principal = authentication.getPrincipal();
|
||||
String username = null;
|
||||
|
||||
if (principal instanceof UserDetails) {
|
||||
username = ((UserDetails) principal).getUsername();
|
||||
} else if (principal instanceof DefaultOAuth2User) {
|
||||
SocialUser socialUser = (SocialUser) principal;
|
||||
username = socialUser.getUsername();
|
||||
}
|
||||
|
||||
return username;
|
||||
}
|
||||
|
||||
public static HttpServletRequest getRequest() {
|
||||
HttpServletRequest request = null;
|
||||
if (RequestContextHolder.getRequestAttributes() != null) {
|
||||
request =
|
||||
((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
public static void addFlashAlertMessages(HttpSession session, String msg) {
|
||||
List<String> flashMessages =
|
||||
session.getAttribute("flashAlertMessages") != null
|
||||
? (List<String>) session.getAttribute("flashAlertMessages")
|
||||
: new ArrayList<>();
|
||||
|
||||
flashMessages.add(msg);
|
||||
session.setAttribute("flashAlertMessages", flashMessages);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package app.module.core.config.application.util;
|
||||
|
||||
import app.module.core.config.adapters.web.rest.error.RestErrorVO;
|
||||
import app.module.core.config.adapters.web.rest.error.RestFieldErrorVO;
|
||||
import app.module.core.config.adapters.web.rest.error.RestObjectErrorVO;
|
||||
import app.module.core.usecase.uri.ancestry.ports.application.domain.URIAncestry;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.validation.FieldError;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.thymeleaf.util.StringUtils;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class CoreUtil {
|
||||
|
||||
private final MessageUtil messageUtil;
|
||||
|
||||
/**
|
||||
* thymeleaf 에서 사용 목적. URI 목록 중 findId 와 매칭되는 URI 가 있는지 여부
|
||||
*
|
||||
* @param uriList URI 목록
|
||||
* @param findId 찾는 URI 아이디
|
||||
* @return boolean 매칭 여부
|
||||
*/
|
||||
public boolean containsCurrentURI(List<URIAncestry> uriList, String findId) {
|
||||
return uriList.stream().anyMatch(node -> node.getId().equals(findId));
|
||||
}
|
||||
|
||||
public String getUriTitle(URIAncestry uri) {
|
||||
return StringUtils.isEmpty(messageUtil.getMessage(uri.getId()))
|
||||
? uri.getText()
|
||||
: messageUtil.getMessage(uri.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* ObjectError 목록을 DTO 객체로 변환
|
||||
*
|
||||
* @param objectErrors ObjectError 목록
|
||||
* @return List<RestObjectErrorDto>
|
||||
*/
|
||||
public List<RestObjectErrorVO> getRestObjectErrors(List<ObjectError> objectErrors) {
|
||||
return objectErrors.stream()
|
||||
.map(
|
||||
objectError ->
|
||||
RestObjectErrorVO.builder()
|
||||
.message(
|
||||
!StringUtils.isEmpty(objectError.getDefaultMessage())
|
||||
? objectError.getDefaultMessage()
|
||||
: messageUtil.getMessage(
|
||||
objectError.getCode(), objectError.getArguments()))
|
||||
.build())
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public ResponseEntity<?> getErrorInfo(BindingResult bindingResult) {
|
||||
return ResponseEntity.status(HttpStatus.UNPROCESSABLE_ENTITY)
|
||||
.body(
|
||||
RestErrorVO.builder()
|
||||
.objectErrors(getRestObjectErrors(bindingResult.getGlobalErrors()))
|
||||
.fieldErrors(getRestFieldErrors(bindingResult.getFieldErrors()))
|
||||
.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* bindResult 의 fieldErrors 정보를 DTO(RestFieldErrorDto) 목록으로 변환해서 전달
|
||||
*
|
||||
* @param fieldErrors bindResult 의 fieldErrors
|
||||
* @return List<RestFieldErrorDto>
|
||||
*/
|
||||
public List<RestFieldErrorVO> getRestFieldErrors(List<FieldError> fieldErrors) {
|
||||
return fieldErrors.stream()
|
||||
.map(
|
||||
fieldError ->
|
||||
new RestFieldErrorVO(
|
||||
fieldError.getField(),
|
||||
!StringUtils.isEmpty(fieldError.getDefaultMessage())
|
||||
? fieldError.getDefaultMessage()
|
||||
: messageUtil.getMessage(fieldError.getCode(),
|
||||
fieldError.getArguments())))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package app.module.core.config.application.util;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.openxml4j.opc.OPCPackage;
|
||||
import org.apache.poi.poifs.crypt.EncryptionInfo;
|
||||
import org.apache.poi.poifs.crypt.EncryptionMode;
|
||||
import org.apache.poi.poifs.crypt.Encryptor;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ExcelUtil {
|
||||
|
||||
@Value("${excel.password}")
|
||||
private String excelPassword;
|
||||
|
||||
public void createCells(Row row, Object... objects) {
|
||||
Arrays.stream(objects)
|
||||
.forEach(
|
||||
obj -> {
|
||||
Cell cell = row.createCell(row.getPhysicalNumberOfCells());
|
||||
String simpleName = obj == null ? "" : obj.getClass().getSimpleName();
|
||||
log.debug(String.format("check object's simple name: %s", simpleName));
|
||||
|
||||
switch (simpleName) {
|
||||
case "String":
|
||||
cell.setCellValue((String) obj);
|
||||
break;
|
||||
case "Integer":
|
||||
cell.setCellValue((Integer) obj);
|
||||
break;
|
||||
case "Long":
|
||||
cell.setCellValue((Long) obj);
|
||||
break;
|
||||
case "Double":
|
||||
cell.setCellValue((Double) obj);
|
||||
break;
|
||||
case "Float":
|
||||
cell.setCellValue((Float) obj);
|
||||
break;
|
||||
case "Boolean":
|
||||
cell.setCellValue((Boolean) obj);
|
||||
break;
|
||||
case "Date":
|
||||
case "LocalDateTime":
|
||||
cell.setCellValue((Date) obj);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void generateWithPassword(HttpServletResponse response, Workbook wb, String filename) {
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
response.setHeader(
|
||||
"Content-Disposition", String.format("attachment;filename=%s.xlsx", filename));
|
||||
|
||||
try (ByteArrayOutputStream workbookOutputStream = new ByteArrayOutputStream();
|
||||
OutputStream responseOutputStream = response.getOutputStream()) {
|
||||
wb.write(workbookOutputStream);
|
||||
POIFSFileSystem fs = new POIFSFileSystem();
|
||||
|
||||
Encryptor enc = new EncryptionInfo(EncryptionMode.agile).getEncryptor();
|
||||
enc.confirmPassword(excelPassword);
|
||||
|
||||
OPCPackage opc =
|
||||
OPCPackage.open(new ByteArrayInputStream(workbookOutputStream.toByteArray()));
|
||||
opc.save(enc.getDataStream(fs));
|
||||
opc.close();
|
||||
|
||||
fs.writeFilesystem(responseOutputStream);
|
||||
wb.close();
|
||||
} catch (IOException | InvalidFormatException | GeneralSecurityException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void generateWithoutPassword(HttpServletResponse response, Workbook wb,
|
||||
String filename) {
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
response.setHeader(
|
||||
"Content-Disposition", String.format("attachment;filename=%s.xlsx", filename));
|
||||
|
||||
try (OutputStream responseOutputStream = response.getOutputStream()) {
|
||||
wb.write(responseOutputStream);
|
||||
wb.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package app.module.core.config.application.util;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
/**
|
||||
* 이미지 crop 과 resize http://egloos.zum.com/kingori/v/4486279
|
||||
*/
|
||||
public class ImageUtil {
|
||||
|
||||
public static BufferedImage cropImageByMaxWidthAndRatio(
|
||||
InputStream inputStream, int maxWidth, double xyRatio) throws IOException {
|
||||
BufferedImage originalImg = ImageIO.read(inputStream);
|
||||
|
||||
// get the center point for crop
|
||||
int[] centerPoint = {originalImg.getWidth() / 2, originalImg.getHeight() / 2};
|
||||
|
||||
// calculate crop area
|
||||
int cropWidth = originalImg.getWidth();
|
||||
int cropHeight = originalImg.getHeight();
|
||||
|
||||
if (cropHeight > cropWidth * xyRatio) {
|
||||
// long image
|
||||
cropHeight = (int) (cropWidth * xyRatio);
|
||||
} else {
|
||||
// wide image
|
||||
cropWidth = (int) ((float) cropHeight / xyRatio);
|
||||
}
|
||||
|
||||
// set target image size
|
||||
int targetWidth = cropWidth;
|
||||
int targetHeight = cropHeight;
|
||||
|
||||
if (targetWidth > maxWidth) {
|
||||
// too big image
|
||||
targetWidth = maxWidth;
|
||||
targetHeight = (int) (targetWidth * xyRatio);
|
||||
}
|
||||
|
||||
// processing image
|
||||
BufferedImage targetImage =
|
||||
new BufferedImage(targetWidth, targetHeight, BufferedImage.TYPE_INT_RGB);
|
||||
|
||||
Graphics2D graphics2D = targetImage.createGraphics();
|
||||
graphics2D.setBackground(Color.WHITE);
|
||||
graphics2D.setPaint(Color.WHITE);
|
||||
graphics2D.fillRect(0, 0, targetWidth, targetHeight);
|
||||
graphics2D.setRenderingHint(
|
||||
RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
||||
graphics2D.drawImage(
|
||||
originalImg,
|
||||
0,
|
||||
0,
|
||||
targetWidth,
|
||||
targetHeight,
|
||||
centerPoint[0] - (cropWidth / 2),
|
||||
centerPoint[1] - (cropHeight / 2),
|
||||
centerPoint[0] + (cropWidth / 2),
|
||||
centerPoint[1] + (cropHeight / 2),
|
||||
null);
|
||||
|
||||
return targetImage;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package app.module.core.config.application.util;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.context.MessageSource;
|
||||
import org.springframework.context.NoSuchMessageException;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.ObjectError;
|
||||
import org.thymeleaf.util.StringUtils;
|
||||
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class MessageUtil {
|
||||
|
||||
private final MessageSource messageSource;
|
||||
|
||||
public String getMessage(String code, Object... args) {
|
||||
String message = "";
|
||||
try {
|
||||
message = messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
|
||||
} catch (NoSuchMessageException ignored) {
|
||||
}
|
||||
return message;
|
||||
}
|
||||
|
||||
public String getErrorMessage(ObjectError error) {
|
||||
return !StringUtils.isEmpty(error.getDefaultMessage())
|
||||
? error.getDefaultMessage()
|
||||
: getMessage(error.getCode(), error.getArguments());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package app.module.core.config.application.util;
|
||||
|
||||
public class PropertyUtil {
|
||||
|
||||
public static boolean isCoreDataRequired() {
|
||||
return System.getProperty("app.initData.core", "").equals("true");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package app.module.core.usecase.admin.getAdmins.adapters.persistence;
|
||||
|
||||
import app.module.core.config.adapters.persistence.repository.AdminRepo;
|
||||
import app.module.core.usecase.admin.getAdmins.adapters.persistence.model.GetAdminsDto;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.GetAdminsPortOut;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdmins;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdminsCmd;
|
||||
|
||||
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdminsRole;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
import org.springframework.data.domain.PageImpl;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
class GetAdminsDao implements GetAdminsPortOut {
|
||||
|
||||
private final GetAdminsMapper getAdminsMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Page<GetAdmins> connect(Pageable pageable, GetAdminsCmd filterCommand) {
|
||||
// 관리자 목록 조회
|
||||
List<GetAdminsDto> admins = getAdminsMapper.findAll(filterCommand, pageable);
|
||||
|
||||
// 관리자의 역할 목록 조회
|
||||
List<GetAdminsRole> roles = getAdminsMapper.findRolesWithPrivilegesByAdminIds(
|
||||
admins.stream().map(GetAdminsDto::getId).toList());
|
||||
|
||||
return new PageImpl<>(
|
||||
admins.stream()
|
||||
.map(admin -> new GetAdmins(
|
||||
admin.getId(),
|
||||
admin.getCreatedBy(),
|
||||
admin.getCreatedAt(),
|
||||
admin.getUpdatedBy(),
|
||||
admin.getUpdatedAt(),
|
||||
admin.getEmail(),
|
||||
admin.getAccountDisabled(),
|
||||
admin.getAccountLocked(),
|
||||
admin.getTotal(),
|
||||
roles.stream()
|
||||
.filter(r -> r.getAdminId().equals(admin.getId()))
|
||||
.collect(Collectors.toList())
|
||||
)).toList(),
|
||||
pageable,
|
||||
admins.isEmpty() ? 0 : admins.get(0).getTotal());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package app.module.core.usecase.admin.getAdmins.adapters.persistence;
|
||||
|
||||
import app.module.core.usecase.admin.getAdmins.adapters.persistence.model.GetAdminsDto;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdmins;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdminsCmd;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdminsRole;
|
||||
import java.util.List;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
@Mapper
|
||||
public interface GetAdminsMapper {
|
||||
List<GetAdminsDto> findAll(@Param("cmd") GetAdminsCmd cmd, @Param("pageable") Pageable pageable);
|
||||
List<GetAdminsRole> findRolesWithPrivilegesByAdminIds(@Param("ids") List<String> ids);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package app.module.core.usecase.admin.getAdmins.adapters.persistence.model;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class GetAdminsDto {
|
||||
private String id;
|
||||
private String createdBy;
|
||||
private LocalDateTime createdAt;
|
||||
private String updatedBy;
|
||||
private LocalDateTime updatedAt;
|
||||
private String email;
|
||||
private Boolean accountDisabled;
|
||||
private Boolean accountLocked;
|
||||
private Integer total;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package app.module.core.usecase.admin.getAdmins.ports;
|
||||
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdmins;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdminsCmd;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
public interface GetAdminsPortIn {
|
||||
|
||||
Page<GetAdmins> connect(Pageable pageable, GetAdminsCmd filterCommand);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package app.module.core.usecase.admin.getAdmins.ports;
|
||||
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdmins;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdminsCmd;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
||||
public interface GetAdminsPortOut {
|
||||
|
||||
Page<GetAdmins> connect(Pageable pageable, GetAdminsCmd filterCommand);
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package app.module.core.usecase.admin.getAdmins.ports.application;
|
||||
|
||||
import app.module.core.usecase.admin.getAdmins.ports.GetAdminsPortIn;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.GetAdminsPortOut;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdmins;
|
||||
import app.module.core.usecase.admin.getAdmins.ports.application.domain.GetAdminsCmd;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
class GetAdminsService implements GetAdminsPortIn {
|
||||
|
||||
private final GetAdminsPortOut portOut;
|
||||
|
||||
@Override
|
||||
public Page<GetAdmins> connect(Pageable pageable, GetAdminsCmd listCmd) {
|
||||
return portOut.connect(pageable, listCmd);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package app.module.core.usecase.admin.getAdmins.ports.application.domain;
|
||||
|
||||
import app.module.core.config.application.component.AuditOutput;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Getter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class GetAdmins implements AuditOutput {
|
||||
private String id;
|
||||
private String createdBy;
|
||||
private LocalDateTime createdAt;
|
||||
private String updatedBy;
|
||||
private LocalDateTime updatedAt;
|
||||
private String email;
|
||||
private Boolean accountDisabled;
|
||||
private Boolean accountLocked;
|
||||
private Integer total;
|
||||
private List<GetAdminsRole> roles;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user