shjung 1 year ago
parent
commit
e3ebc416dd
42 changed files with 2773 additions and 448 deletions
  1. 1682 0
      App_Data/mip_data/mip/logs/mip_sdk.miplog
  2. BIN
      App_Data/mip_data/mip/mip.policies.sqlite3
  3. BIN
      App_Data/mip_data/mip/mip.protection.sqlite3
  4. BIN
      App_Data/mip_data/mip/telemetry
  5. BIN
      App_Data/mip_data/mip/telemetry-shm
  6. BIN
      App_Data/mip_data/mip/telemetry-wal
  7. 1 0
      conf/AipGatewayApi.pid
  8. 6 3
      pom.xml
  9. 10 2
      src/main/java/com/aip/gateway/api/AipGatewayApiApplication.java
  10. 2 2
      src/main/java/com/aip/gateway/api/aip/manager/AbstractManager.java
  11. 97 7
      src/main/java/com/aip/gateway/api/aip/manager/AipFileManager.java
  12. 191 317
      src/main/java/com/aip/gateway/api/aip/manager/FileManager.java
  13. 13 6
      src/main/java/com/aip/gateway/api/aip/model/AipFileInfo.java
  14. 16 0
      src/main/java/com/aip/gateway/api/aip/model/AipFileStatus.java
  15. 1 1
      src/main/java/com/aip/gateway/api/aip/model/AipProtection.java
  16. 62 0
      src/main/java/com/aip/gateway/api/aip/utils/AipFileStream.java
  17. 59 0
      src/main/java/com/aip/gateway/api/aip/utils/AipFileUtils.java
  18. 16 11
      src/main/java/com/aip/gateway/api/controller/ApiAipController.java
  19. 20 14
      src/main/java/com/aip/gateway/api/controller/ApiDbController.java
  20. 24 16
      src/main/java/com/aip/gateway/api/controller/ApiFileController.java
  21. 23 15
      src/main/java/com/aip/gateway/api/controller/ApiStreamController.java
  22. 14 8
      src/main/java/com/aip/gateway/api/controller/BaseController.java
  23. 89 0
      src/main/java/com/aip/gateway/api/interceptor/AipApiControllerInterceptor.java
  24. 11 3
      src/main/java/com/aip/gateway/api/model/app/AipSettings.java
  25. 7 2
      src/main/java/com/aip/gateway/api/model/request/RequestStream.java
  26. 1 1
      src/main/java/com/aip/gateway/api/model/request/RequestStreamAllSet.java
  27. 1 1
      src/main/java/com/aip/gateway/api/model/request/RequestStreamDel.java
  28. 1 1
      src/main/java/com/aip/gateway/api/model/request/RequestStreamSet.java
  29. 1 2
      src/main/java/com/aip/gateway/api/model/response/ApiResponseModel.java
  30. 22 4
      src/main/java/com/aip/gateway/api/model/response/ResponseBase.java
  31. 7 4
      src/main/java/com/aip/gateway/api/model/response/ResponseFile.java
  32. 15 4
      src/main/java/com/aip/gateway/api/model/response/ResponseInfo.java
  33. 14 5
      src/main/java/com/aip/gateway/api/model/response/ResponseStream.java
  34. 4 2
      src/main/java/com/aip/gateway/api/process/DbmsDataProcess.java
  35. 32 2
      src/main/java/com/aip/gateway/api/repository/AipFileRepository.java
  36. 5 0
      src/main/java/com/aip/gateway/api/repository/AppRepository.java
  37. 91 0
      src/main/java/com/aip/gateway/api/repository/GlobalConstants.java
  38. 90 0
      src/main/java/com/aip/gateway/api/security/WebMvcConfig.java
  39. 81 0
      src/main/java/com/aip/gateway/api/service/impl/AbstractAipService.java
  40. 22 4
      src/main/java/com/aip/gateway/api/service/impl/ApiFileService.java
  41. 30 4
      src/main/java/com/aip/gateway/api/service/impl/ApiStreamService.java
  42. 12 7
      src/test/java/com/aip/gateway/api/AipGatewayApiApplicationTests.java

File diff suppressed because it is too large
+ 1682 - 0
App_Data/mip_data/mip/logs/mip_sdk.miplog


BIN
App_Data/mip_data/mip/mip.policies.sqlite3


BIN
App_Data/mip_data/mip/mip.protection.sqlite3


BIN
App_Data/mip_data/mip/telemetry


BIN
App_Data/mip_data/mip/telemetry-shm


BIN
App_Data/mip_data/mip/telemetry-wal


+ 1 - 0
conf/AipGatewayApi.pid

@@ -0,0 +1 @@
+23628

+ 6 - 3
pom.xml

@@ -83,8 +83,7 @@
 		<dependency>
 			<groupId>com.microsoft.azure</groupId>
 			<artifactId>msal4j</artifactId>
-			<version>LATEST</version>
-<!--			<version>1.11.0</version>-->
+			<version>1.15.0</version>
 		</dependency>
 		<dependency>
 			<groupId>com.microsoft.azure</groupId>
@@ -101,7 +100,11 @@
 			<artifactId>guava</artifactId>
 			<version>33.1.0-jre</version>
 		</dependency>
-
+		<dependency>
+			<groupId>commons-io</groupId>
+			<artifactId>commons-io</artifactId>
+			<version>2.11.0</version>
+		</dependency>
 
 		<dependency>
 			<groupId>org.springdoc</groupId>

+ 10 - 2
src/main/java/com/aip/gateway/api/AipGatewayApiApplication.java

@@ -2,6 +2,8 @@ package com.aip.gateway.api;
 
 import com.aip.gateway.api.app.AppUtils;
 import com.aip.gateway.api.config.ApplicationConfig;
+import com.aip.gateway.api.process.DbmsDataProcess;
+import com.aip.gateway.api.repository.AipFileRepository;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.InitializingBean;
@@ -63,8 +65,14 @@ public class AipGatewayApiApplication implements CommandLineRunner, ApplicationL
 		log.info("** startup: {}", applicationConfig.getBootingDateTime());
 		log.info("************************************************************************************");
 
-		//IApiDbService aipDbService = (IApiDbService)AppUtils.getBean(ApiDbService.class);
-		//aipDbService.loadAipConfig();
+		DbmsDataProcess dbmsDataProcess = (DbmsDataProcess)AppUtils.getBean(DbmsDataProcess.class);
+		dbmsDataProcess.run();
+
+		AipFileRepository aipFileRepository = (AipFileRepository)AppUtils.getBean(AipFileRepository.class);
+		if (!aipFileRepository.initialize()) {
+			log.error("AipFileRepository.initialize Failed. System Terminated.");
+			System.exit(0);
+		}
 
 		// schedule enable
 		applicationConfig.setStartSchedule(true);

+ 2 - 2
src/main/java/com/aip/gateway/api/aip/manager/AbstractManager.java

@@ -10,8 +10,8 @@ import lombok.extern.slf4j.Slf4j;
 @Data
 abstract class AbstractManager {
 
-    private int lastErrNo;
-    private String lastErrMsg;
+    protected int lastErrNo;
+    protected String lastErrMsg;
 
     protected void setError(int errNo, String errMsg1, String errMsg2) {
         lastErrNo = errNo;

+ 97 - 7
src/main/java/com/aip/gateway/api/aip/manager/AipFileManager.java

@@ -1,9 +1,7 @@
 package com.aip.gateway.api.aip.manager;
 
 import com.aip.gateway.api.aip.AuthDelegateImpl;
-import com.aip.gateway.api.aip.model.AipConfig;
-import com.aip.gateway.api.aip.model.AipLabel;
-import com.aip.gateway.api.aip.model.AipTemplate;
+import com.aip.gateway.api.aip.model.*;
 import com.aip.gateway.api.aip.utils.Utilities;
 import com.microsoft.informationprotection.*;
 import com.microsoft.informationprotection.file.FileHandler;
@@ -14,6 +12,7 @@ import lombok.extern.slf4j.Slf4j;
 import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 @Slf4j
 @Getter
@@ -113,22 +112,113 @@ public class AipFileManager extends  AipFileManagerBase {
         }
     }
 
+    public AipFileInfo getFileInfo(String fileName) {
+        if (!checkLoading()) {
+            return new AipFileInfo(10, "AIP 라이브러리가 초기화 되지 않았습니다.");
+        }
+        AipFileInfo fileInfo = _fileManager.getFileInfo(fileName);
+        if (fileInfo == null) {
+            setError(_fileManager.getLastErrNo(), "AipFileManager::GetFileInfo Failed.", _fileManager.getLastErrMsg());
+            return new AipFileInfo(11, _fileManager.getLastErrMsg());
+        }
+        return fileInfo;
+    }
+    public AipFileInfo getFileInfo(IStream fileStream, String outputFileName) {
+        if (!checkLoading()) {
+            return new AipFileInfo(10, "AIP 라이브러리가 초기화 되지 않았습니다.");
+        }
+        AipFileInfo fileInfo = _fileManager.getFileInfo(fileStream, outputFileName);
+        if (fileInfo == null) {
+            setError(_fileManager.getLastErrNo(), "AipFileManager::GetFileInfo Failed.", _fileManager.getLastErrMsg());
+            return new AipFileInfo(11, _fileManager.getLastErrMsg());
+        }
+        return fileInfo;
+    }
+
+    public AipFileStatus getAipFileStatus(String fileName) {
+        try {
+            IFileStatus fileStatus = FileHandler.GetFileStatus(fileName, _mipContext);
+            return AipFileStatus.builder()
+                    .isLabeled(fileStatus.IsLabeled())
+                    .isProtected(fileStatus.IsProtected())
+                    .containsProtectedObjects(fileStatus.ContainsProtectedObjects())
+                    .build();
+        }
+        catch (Exception ex) {
+            setError(81, "AipFileManager::GetAipFileStatus Failed.", ex.getMessage());
+        }
+        return null;
+    }
+
+
+    public SetFileInfo setLabel(String fileName, String actualFileName, String email, String labelId, String templateId, String comments) {
+        // 레이블 및 템플릿 정보 가져오기
+        if (Objects.equals(comments, "")) {
+            comments = "SetLabel";
+        }
+        return _fileManager.setLabel(fileName, actualFileName, email, labelId, templateId, comments);
+    }
+    public SetFileInfo setLabel(IStream fileStream, String actualFileName, String email, String labelId, String templateId, String comments) {
+        if (Objects.equals(comments, "")) {
+            comments = "SetLabel by " + email;
+        }
+        // 레이블 및 템플릿 정보 가져오기
+        return _fileManager.setLabel(fileStream, actualFileName, email, labelId, templateId, comments);
+    }
+
+    public SetFileInfo deleteLabel(String fileName, String actualFileName, String email, String comments, boolean isDelProtection) {
+        if (Objects.equals(comments, "")) {
+            comments = "Delete Label by " + email;
+        }
+        return _fileManager.deleteLabel(fileName, actualFileName, email, comments, isDelProtection);
+    }
+    public SetFileInfo deleteLabel(IStream fileStream, String actualFileName, String email, String comments, boolean isDelProtection) {
+        if (Objects.equals(comments, "")) {
+            comments = "Delete Label by " + email;
+        }
+        return _fileManager.deleteLabel(fileStream, actualFileName, email, comments, isDelProtection);
+    }
+
+    public SetFileInfo setProtection(String fileName, String actualFileName, String email, String templateId, String comments) {
+        if (Objects.equals(comments, "")) {
+            comments = "SetProtection by " + email;
+        }
+        return _fileManager.setProtection(fileName, actualFileName, email, templateId, comments);
+    }
+    public SetFileInfo setProtection(IStream fileStream, String actualFileName, String email, String templateId, String comments) {
+        if (Objects.equals(comments, "")) {
+            comments = "SetProtection by " + email;
+        }
+        return _fileManager.setProtection(fileStream, actualFileName, email, templateId, comments);
+    }
 
+    public SetFileInfo deleteProtection(String fileName, String actualFileName, String email, String comments) {
+        if (Objects.equals(comments, "")) {
+            comments = "Delete Protection by " + email;
+        }
+        return _fileManager.removeProtection(fileName, actualFileName, email, comments);
+    }
+    public SetFileInfo deleteProtection(IStream fileStream, String actualFileName, String email, String comments) {
+        if (Objects.equals(comments, "")) {
+            comments = "Delete Protection by " + email;
+        }
+        return _fileManager.removeProtection(fileStream, actualFileName, email, comments);
+    }
 
 
-    public boolean IsProtected(IStream inputStream, String filePath) {
+    public boolean isProtected(IStream inputStream, String filePath) {
         IFileStatus status = FileHandler.GetFileStatus(inputStream, filePath, _mipContext);
         return status.IsProtected();
     }
-    public boolean IsLabeledOrProtected(IStream inputStream, String filePath) {
+    public boolean isLabeledOrProtected(IStream inputStream, String filePath) {
         IFileStatus status = FileHandler.GetFileStatus(inputStream, filePath, _mipContext);
         return (status.IsLabeled() || status.IsProtected());
     }
-    public boolean IsProtected(String filePath) {
+    public boolean isProtected(String filePath) {
         IFileStatus status = FileHandler.GetFileStatus(filePath, _mipContext);
         return status.IsProtected();
     }
-    public boolean IsLabeledOrProtected(String filePath) {
+    public boolean isLabeledOrProtected(String filePath) {
         IFileStatus status = FileHandler.GetFileStatus(filePath, _mipContext);
         return (status.IsLabeled() || status.IsProtected());
     }

+ 191 - 317
src/main/java/com/aip/gateway/api/aip/manager/FileManager.java

@@ -4,9 +4,11 @@ import com.aip.gateway.api.aip.AuthDelegateImpl;
 import com.aip.gateway.api.aip.ConsentDelegateImpl;
 import com.aip.gateway.api.aip.model.*;
 import com.aip.gateway.api.aip.utils.Utilities;
+import com.aip.gateway.api.aip.utils.AipFileUtils;
 import com.microsoft.informationprotection.*;
 import com.microsoft.informationprotection.file.*;
 import com.microsoft.informationprotection.internal.callback.FileHandlerObserver;
+import com.microsoft.informationprotection.internal.file.PFileExtensionBehavior;
 import com.microsoft.informationprotection.protection.IProtectionHandler;
 import com.microsoft.informationprotection.protection.Rights;
 import lombok.extern.slf4j.Slf4j;
@@ -15,6 +17,7 @@ import java.io.File;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.Objects;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
@@ -51,6 +54,7 @@ public class FileManager extends AbstractManager {
         }
         catch(InterruptedException ie) {
             setError(1, "FileManager::createProfile InterruptedException Exception.", ie.getMessage());
+            Thread.currentThread().interrupt();
             return false;
         }
         catch(ExecutionException eex) {
@@ -87,6 +91,7 @@ public class FileManager extends AbstractManager {
         }
         catch(InterruptedException ie) {
             setError(1, "FileManager::createEngine InterruptedException Exception.", ie.getMessage());
+            Thread.currentThread().interrupt();
             return false;
         }
         catch(ExecutionException eex) {
@@ -121,13 +126,33 @@ public class FileManager extends AbstractManager {
             return 0;
         }
     }
+
+    public AipFileInfo getFileInfo(IStream fileStream, String outputFileName) {
+        IFileHandler handler = createFileHandler(fileStream, outputFileName);
+        if (handler == null) {
+            //AipFileUtils.delete(outputFileName);
+            return null;
+        }
+        AipFileInfo result = getFileInfo(handler);
+        try {
+            result.setFileSize(fileStream.size());
+            //AipFileUtils.delete(outputFileName);
+        }
+        catch (Exception ex) {
+            result.setFileSize(0);
+            lastErrMsg = ex.getMessage();
+        }
+        return result;
+    }
     public AipFileInfo getFileInfo(String fileName) {
-        var handler = createFileHandler(fileName, fileName);
+        IFileHandler handler = createFileHandler(fileName, fileName);
         if (handler == null) {
             return null;
         }
         AipFileInfo result = getFileInfo(handler);
-        result.setFileSize(getFileSize(fileName));
+        if (result != null) {
+            result.setFileSize(getFileSize(fileName));
+        }
         return result;
     }
 
@@ -136,15 +161,9 @@ public class FileManager extends AbstractManager {
             return null;
         }
 
-        AipFileInfo fileInfo = AipFileInfo.builder()
-                .errorCode(0)
-                .errorMessage("")
-                .content(null)
-                .label(null)
-                .protection(null)
-                .outputFileName("")
-                .fileSize(0)
-                .build();
+        AipFileInfo fileInfo = new AipFileInfo(0, "");
+
+        log.error("AipFileInfo: {}", handler.getOutputFileName());
 
         fileInfo.setOutputFileName(handler.getOutputFileName());
 
@@ -167,7 +186,7 @@ public class FileManager extends AbstractManager {
                     .contentId(protection.getContentId())
                     .auditedExtractAllowed(protection.getAuditedExtractAllowed())
                     .blockSize(protection.getBlockSize())
-                    .potectionDescriptor(null)
+                    .protectionDescriptor(null)
                     .useDeprecatedAlgorithms(protection.getUseDeprecatedAlgorithms())
                     .build();
 
@@ -194,7 +213,7 @@ public class FileManager extends AbstractManager {
                     descriptor.getLabelInformation().setLabelId(data.getLabelInfo().getLabelId());
                     descriptor.getLabelInformation().setTenantId(data.getLabelInfo().getTenantId());
                 }
-                fileInfo.getProtection().setPotectionDescriptor(descriptor);
+                fileInfo.getProtection().setProtectionDescriptor(descriptor);
             }
         }
         return fileInfo;
@@ -213,17 +232,18 @@ public class FileManager extends AbstractManager {
     }
     private IFileHandler createFileHandler(String inputFile, String outputFile) {
         try {
-            File file = new File(inputFile);
-            if (file.exists()) {
+            if (!AipFileUtils.isExists(inputFile)) {
                 setError(91, "FileManager::createFileHandler Failed.", "요청한 파일이 존재하지 않습니다. " + inputFile);
                 return null;
             }
             FileHandlerObserver observer = new FileHandlerObserver();
             Future<IFileHandler> handlerFuture = _engine.createFileHandlerAsync(inputFile, outputFile, true, observer, null);
             return handlerFuture.get();
-        }
-        catch(Exception e) {
-            setError(91, "FileManager::CreateFileHandler Failed.", e.getMessage());
+        } catch (InterruptedException e) {
+            setError(93, "FileManager::CreateFileHandler InterruptedException Exception.", e.getMessage());
+            Thread.currentThread().interrupt();
+        } catch (ExecutionException e) {
+            setError(94, "FileManager::CreateFileHandler ExecutionException Exception.", e.getMessage());
         }
         return null;
     }
@@ -232,9 +252,8 @@ public class FileManager extends AbstractManager {
             setError(91, "FileManager::CreateFileHandler Failed.", "요청한 스트림의 정보가 없습니다.");
             return null;
         }
-
         if (outputFile == null || outputFile.isEmpty()) {
-            setError(91, "FileManager::CreateFileHandler Failed.", "요청한 출력 파일 이릅이 존재하지 않습니다.");
+            setError(92, "FileManager::CreateFileHandler Failed.", "요청한 출력 파일 이릅이 존재하지 않습니다.");
             return null;
         }
 
@@ -242,39 +261,32 @@ public class FileManager extends AbstractManager {
             FileHandlerObserver observer = new FileHandlerObserver();
             Future<IFileHandler> handlerFuture = _engine.createFileHandlerAsync(inputStream, outputFile, true, observer, null);
             return handlerFuture.get();
+        } catch (InterruptedException e) {
+            setError(93, "FileManager::CreateFileHandler InterruptedException Exception.", e.getMessage());
+            Thread.currentThread().interrupt();
+        } catch (ExecutionException e) {
+            setError(94, "FileManager::CreateFileHandler ExecutionException Exception.", e.getMessage());
         }
-        catch (Exception ex) {
-            setError(91, "FileManager::CreateFileHandler Failed.", ex.getMessage());
-        }
+
         return null;
     }
     public SetFileInfo setLabel(String fileName, String actualFileName, String email, String labelId, String templateId, String comments) {
-        SetFileInfo result = new SetFileInfo();
-
-        var handler = createFileHandler(fileName, actualFileName);
-        if (handler == null)
-        {
-            result.errorNo = 201;
-            result.errorMsg = getLastErrMsg();
-            return result;
-        }
-        result.fileSize = getFileSize(fileName);
-        return setLabel(handler, actualFileName, email, labelId, templateId, comments, result);
+        IFileHandler handler = createFileHandler(fileName, actualFileName);
+        return setLabel(handler, actualFileName, email, labelId, templateId, comments, getFileSize(fileName));
+    }
+    public SetFileInfo setLabel(IStream fileStream, String actualFileName, String email, String labelId, String templateId, String comments) {
+        IFileHandler handler = createFileHandler(fileStream, actualFileName);
+        return setLabel(handler, actualFileName, email, labelId, templateId, comments, fileStream.size());
     }
-    public SetFileInfo setLabel(String fileStream, String actualFileName, String email, String labelId, String templateId, String comments) {
+    private SetFileInfo setLabel(IFileHandler handler, String actualFileName, String email, String labelId, String templateId, String comments, long fileSize) {
         SetFileInfo result = new SetFileInfo();
-
-        var handler = createFileHandler(fileStream, actualFileName);
-        if (handler == null)
-        {
+        if (handler == null) {
             result.errorNo = 201;
             result.errorMsg = getLastErrMsg();
             return result;
         }
-        result.fileSize = fileStream.Length;
-        return SetLabel(handler, actualFileName, email, labelId, templateId, comments, result);
-    }
-    public SetFileInfo setLabel(IFileHandler handler, String actualFileName, String email, String labelId, String templateId, String comments, SetFileInfo result) {
+        result.fileSize = fileSize;
+
         Label label = getLabelById(labelId);
         if (label == null) {
             result.errorNo = 202;
@@ -282,57 +294,32 @@ public class FileManager extends AbstractManager {
             return result;
         }
 
-        if (comments == "") {
-            comments = "SetLabel";
-        }
-        LabelingOptions labelingOptions = new LabelingOptions()
-        {
-            AssignmentMethod = AssignmentMethod.Auto, //Standard,
-            JustificationMessage = comments,
-            IsDowngradeJustified = true
-        };
+        LabelingOptions labelingOptions = getLabelingOptions(AssignmentMethod.AUTO, comments, true);
 
-        String ownerEmail = email;
-        if (handler.Label != null && handler.Label.Label != null) {
-            result.labelGuid = handler.Label.Label.Id;
-        }
-        if (handler.Protection != null) {
-            ownerEmail = handler.Protection.Owner;
-            result.fileOwner = handler.Protection.Owner;
-            if (handler.Protection.ProtectionDescriptor != null) {
-                result.templateGuid = handler.Protection.ProtectionDescriptor.TemplateId;
-            }
-        }
+        String ownerEmail = getOrgFileInfo(handler, email, result);
 
-        var protectionSettings = new ProtectionSettings
-        {
-            PFileExtensionBehavior = PFileExtensionBehavior.Default,
-        };
-        if (ownerEmail != "") {
-            protectionSettings.DelegatedUserEmail = ownerEmail;
+        ProtectionSettings protectionSettings = new ProtectionSettings();
+        protectionSettings.setPFileExtensionBehavior(PFileExtensionBehavior.Default);
+        if (!Objects.equals(ownerEmail, "")) {
+            protectionSettings.setDelegatedUserEmail(ownerEmail);
         }
 
         try {
-            handler.SetLabel(label, labelingOptions, protectionSettings);
-            if (templateId != "")
-            {
+            handler.setLabel(label, labelingOptions, protectionSettings);
+            if (templateId != "") {
                 ProtectionDescriptor protectionDescriptor = new ProtectionDescriptor(templateId);
-                handler.SetProtection(protectionDescriptor, protectionSettings);
+                handler.setProtection(protectionDescriptor, protectionSettings);
             }
         }
         catch (Exception ex) {
             result.errorNo = 203;
-            result.errorMsg = ex.Message;
-            SetError(53, "FileManager::SetLabel Failed.", ex.Message);
+            result.errorMsg = ex.getMessage();
+            setError(53, "FileManager::SetLabel Failed.", ex.getMessage());
             return result;
         }
 
-        boolean isCommited = false;
-        if (handler.isModified()) {
-            isCommited = Task.Run(async () => await handler.CommitAsync(actualFileName)).Result;
-
-        }
-        if (isCommited) {
+        boolean isCommitted = commitAsync(handler, actualFileName, result);
+        if (isCommitted) {
             //handler.NotifyCommitSuccessful(fileName);
             result.newFileSize = getFileSize(actualFileName);
             result.newFileLabelGuid = labelId;
@@ -345,94 +332,45 @@ public class FileManager extends AbstractManager {
             result.errorMsg = "AIP File CommitAsync Failed.";
             setError(53, "FileManager::SetLabel Failed.", "Label Id: " + labelId + ", SetLabel Failed.");
         }
-        AipFileInfo info = getFileInfo(actualFileName);
-        if (info != null) {
-            if (info.Label != null) {
-                result.newFileLabelGuid = info.Label.Id;
-            }
-            if (info.Protection != null) {
-                result.newFileOwner = info.Protection.Owner;
-                if (info.Protection.ProtectionDescriptor != null)
-                {
-                    result.newFileTemplateGuid = info.Protection.ProtectionDescriptor.TemplateId;
-                }
-            }
-        }
+        getActionFileInfo(actualFileName, result);
         return result;
     }
 
-    public SetFileInfo deleteLabel(String fileName, String actualFileName, String email, String comments, String isDelProtection) {
-        SetFileInfo result = new SetFileInfo();
-
-        var outFileName = actualFileName == string.Empty ? fileName : actualFileName;
-        var handler = createFileHandler(fileName, outFileName);
-        if (handler == null)
-        {
-            result.errorNo = 201;
-            result.errorMsg = getLastErrMsg();
-            return result;
-        }
-        result.fileSize = getFileSize(fileName);
-        return deleteLabel(handler, actualFileName, email, comments, isDelProtection, result);
+    public SetFileInfo deleteLabel(String fileName, String actualFileName, String email, String comments, boolean isDelProtection) {
+        String outFileName = actualFileName.isEmpty() ? fileName : actualFileName;
+        IFileHandler handler = createFileHandler(fileName, outFileName);
+        return deleteLabel(handler, actualFileName, email, comments, isDelProtection, getFileSize(fileName));
     }
     public SetFileInfo deleteLabel(IStream fileStream, String actualFileName, String email, String comments, boolean isDelProtection) {
+        IFileHandler handler = createFileHandler(fileStream, actualFileName);
+        return deleteLabel(handler, actualFileName, email, comments, isDelProtection, fileStream.size());
+    }
+    public SetFileInfo deleteLabel(IFileHandler handler, String actualFileName, String email, String comments, boolean isDelProtection, long fileSize) {
         SetFileInfo result = new SetFileInfo();
-
-        var handler = createFileHandler(fileStream, actualFileName);
         if (handler == null) {
             result.errorNo = 201;
             result.errorMsg = getLastErrMsg();
             return result;
         }
-        result.fileSize = fileStream.Length;
-        return deleteLabel(handler, actualFileName, email, comments, isDelProtection, result);
-    }
-    public SetFileInfo deleteLabel(IFileHandler handler, String actualFileName, String email, String comments, boolean isDelProtection, SetFileInfo result) {
-        if (comments == "")
-        {
-            comments = "Delete Label by " + email;
-        }
-        LabelingOptions invokeLabelingOptions = new LabelingOptions()
-        {
-            AssignmentMethod = AssignmentMethod.Privileged, //because we are removing a high priority label
-            JustificationMessage = comments,
-            IsDowngradeJustified = true
-        };
+        result.fileSize = fileSize;
 
-        String ownerEmail = email;
-        if (handler.Label != null && handler.Label.Label != null)
-        {
-            result.labelGuid = handler.Label.Label.Id;
-        }
-        if (handler.Protection != null)
-        {
-            ownerEmail = handler.Protection.Owner;
-            result.fileOwner = handler.Protection.Owner;
-            if (handler.Protection.ProtectionDescriptor != null)
-            {
-                result.templateGuid = handler.Protection.ProtectionDescriptor.TemplateId;
-            }
-        }
+        LabelingOptions invokeLabelingOptions = getLabelingOptions(AssignmentMethod.PRIVILEGED, comments, true);
+
+        String ownerEmail = getOrgFileInfo(handler, email, result);
 
-        var protectionSettings = new ProtectionSettings
-        {
-            PFileExtensionBehavior = PFileExtensionBehavior.Default,
-        };
-        if (ownerEmail != "")
-        {
-            protectionSettings.DelegatedUserEmail = ownerEmail;
+        ProtectionSettings protectionSettings = new ProtectionSettings();
+        protectionSettings.setPFileExtensionBehavior(PFileExtensionBehavior.Default);
+        if (!Objects.equals(ownerEmail, "")) {
+            protectionSettings.setDelegatedUserEmail(ownerEmail);
         }
 
-        try
-        {
-            if (isDelProtection && handler.Protection != null)
-            {
-                if (handler.Protection.AccessCheck(Rights.Extract) || handler.Protection.AccessCheck(Rights.Owner))
-                {
-                    handler.RemoveProtection();
+        try {
+            if (isDelProtection && handler.getProtection() != null) {
+                if (handler.getProtection().getAccessCheck(Rights.Extract) || handler.getProtection().getAccessCheck(Rights.Owner)) {
+                    handler.removeProtection();
                 }
             }
-            handler.DeleteLabel(invokeLabelingOptions);
+            handler.deleteLabel(invokeLabelingOptions);
         }
         catch (Exception ex) {
             result.errorNo = 203;
@@ -441,12 +379,7 @@ public class FileManager extends AbstractManager {
             return result;
         }
 
-        boolean isCommited = false;
-        if (handler.isModified())
-        {
-            isCommited = Task.Run(async () => await handler.CommitAsync(actualFileName)).Result;
-        }
-
+        boolean isCommited = commitAsync(handler, actualFileName, result);
         if (isCommited) {
             //handler.NotifyCommitSuccessful(fileName);
             result.newFileSize = getFileSize(actualFileName);
@@ -455,111 +388,52 @@ public class FileManager extends AbstractManager {
             result.newFileOwner = ownerEmail;
             result.newFileTemplateGuid = "";
         }
-        else
-        {
+        else {
             result.errorNo = 204;
             result.errorMsg = "AIP File CommitAsync Failed.";
             setError(54, "FileManager::DeleteLabel Failed.", "DeleteLabel Failed by " + ownerEmail);
         }
-        AipFileInfo info = getFileInfo(actualFileName);
-        if (info != null)
-        {
-            if (info.Label != null)
-            {
-                result.newFileLabelGuid = info.Label.Id;
-            }
-            if (info.Protection != null)
-            {
-                result.newFileOwner = info.Protection.Owner;
-                if (info.Protection.ProtectionDescriptor != null)
-                {
-                    result.newFileTemplateGuid = info.Protection.ProtectionDescriptor.TemplateId;
-                }
-            }
-        }
+        getActionFileInfo(actualFileName, result);
         return result;
     }
 
     public SetFileInfo setProtection(String fileName, String actualFileName, String email, String templateId, String comments) {
-        SetFileInfo result = new SetFileInfo();
-
-        var handler = createFileHandler(fileName, actualFileName);
-        if (handler == null)
-        {
-            result.errorNo = 201;
-            result.errorMsg = getLastErrMsg();
-            return result;
-        }
-        result.fileSize = getFileSize(fileName);
-        return setProtection(handler, actualFileName, email, templateId, comments, result);
+        IFileHandler handler = createFileHandler(fileName, actualFileName);
+        return setProtection(handler, actualFileName, email, templateId, comments, getFileSize(fileName));
     }
     public SetFileInfo setProtection(IStream fileStream, String actualFileName, String email, String templateId, String comments) {
+        IFileHandler handler = createFileHandler(fileStream, actualFileName);
+        return setProtection(handler, actualFileName, email, templateId, comments, fileStream.size());
+    }
+    public SetFileInfo setProtection(IFileHandler handler, String actualFileName, String email, String templateId, String comments, long fileSize) {
         SetFileInfo result = new SetFileInfo();
-
-        var handler = createFileHandler(fileStream, actualFileName);
-        if (handler == null)
-        {
+        if (handler == null) {
             result.errorNo = 201;
             result.errorMsg = getLastErrMsg();
             return result;
         }
-        result.fileSize = fileStream.size();
-        return setProtection(handler, actualFileName, email, templateId, comments, result);
-    }
-    public SetFileInfo setProtection(IFileHandler handler, String actualFileName, String email, String templateId, String comments, SetFileInfo result) {
-        if (comments == "") {
-            comments = "SetProtection";
-        }
+        result.fileSize = fileSize;
 
-        String ownerEmail = email;
-        if (handler.Label != null && handler.Label.Label != null)
-        {
-            result.labelGuid = handler.Label.Label.Id;
-        }
-        if (handler.Protection != null)
-        {
-            ownerEmail = handler.Protection.Owner;
-            result.fileOwner = handler.Protection.Owner;
-            if (handler.Protection.ProtectionDescriptor != null) {
-                result.templateGuid = handler.Protection.ProtectionDescriptor.TemplateId;
-            }
-        }
+        String ownerEmail = getOrgFileInfo(handler, email, result);
 
         try {
             ProtectionDescriptor protectionDescriptor = new ProtectionDescriptor(templateId);
-            ProtectionSettings protectionSettings = new ProtectionSettings
-            {
-                PFileExtensionBehavior = PFileExtensionBehavior.Default,
-            };
-            if (ownerEmail != "")
-            {
-                protectionSettings.DelegatedUserEmail = ownerEmail;
+            ProtectionSettings protectionSettings = new ProtectionSettings();
+            protectionSettings.setPFileExtensionBehavior(PFileExtensionBehavior.Default);
+            if (!Objects.equals(ownerEmail, "")) {
+                protectionSettings.setDelegatedUserEmail(ownerEmail);
             }
-            handler.SetProtection(protectionDescriptor, protectionSettings);
+            handler.setProtection(protectionDescriptor, protectionSettings);
         }
-        catch (Exception ex)
-        {
+        catch (Exception ex) {
             result.errorNo = 204;
             result.errorMsg = ex.getMessage();
-            SetError(54, "FileManager::SetProtect Failed.", ex.getMessage());
+            setError(54, "FileManager::SetProtect Failed.", ex.getMessage());
             return result;
         }
 
-        boolean isCommited = false;
-        if (handler.isModified()) {
-            try {
-                isCommited = Task.Run(async () => await handler.CommitAsync(actualFileName)).Result;
-            }
-            catch (Exception ex) {
-                // TODO: Exception catch 해야함.......... 여기서 캣치하면 정확한 오류 메시지를 확인 할 수 없음.
-                result.errorNo = 205;
-                result.errorMsg = "AIP File CommitAsync Failed." + ex.getMessage();
-                setError(55, "FileManager::SetProtection CommitAsync Failed.", ex.getMessage());
-            }
-        }
-
-        if (isCommited)
-        {
+        boolean isCommited = commitAsync(handler, actualFileName, result);
+        if (isCommited) {
             //handler.NotifyCommitSuccessful(fileName);
             result.newFileSize = getFileSize(actualFileName);
             //result.newFileLabelGuid = string.Empty;
@@ -567,87 +441,45 @@ public class FileManager extends AbstractManager {
             result.newFileOwner = ownerEmail;
             result.newFileTemplateGuid = "";
         }
-        else
-        {
+        else {
             result.errorNo = 206;
             result.errorMsg = "AIP File CommitAsync Failed.";
-            SetError(56, "FileManager::SetProtect Failed.", "Template Id: " + templateId + ", SetProtect Failed.");
-        }
-        AipFileInfo info = getFileInfo(actualFileName);
-        if (info != null) {
-            if (info.Label != null) {
-                result.newFileLabelGuid = info.Label.Id;
-            }
-            if (info.Protection != null) {
-                result.newFileOwner = info.Protection.Owner;
-                if (info.Protection.ProtectionDescriptor != null)
-                {
-                    result.newFileTemplateGuid = info.Protection.ProtectionDescriptor.TemplateId;
-                }
-            }
+            setError(56, "FileManager::SetProtect Failed.", "Template Id: " + templateId + ", SetProtect Failed.");
         }
+        getActionFileInfo(actualFileName, result);
         return result;
     }
 
     public SetFileInfo removeProtection(String fileName, String actualFileName, String email, String comments) {
-        SetFileInfo result = new SetFileInfo();
-
-        var handler = createFileHandler(fileName, actualFileName);
-        if (handler == null) {
-            result.errorNo = 201;
-            result.errorMsg = getLastErrMsg();
-            return result;
-        }
-        result.fileSize = getFileSize(fileName);
-        return removeProtection(handler, actualFileName, email, comments, result);
+        IFileHandler handler = createFileHandler(fileName, actualFileName);
+        return removeProtection(handler, actualFileName, email, comments, getFileSize(fileName));
     }
     public SetFileInfo removeProtection(IStream fileStream, String actualFileName, String email, String comments) {
+        IFileHandler handler = createFileHandler(fileStream, actualFileName);
+        return removeProtection(handler, actualFileName, email, comments, fileStream.size());
+    }
+    public SetFileInfo removeProtection(IFileHandler handler, String actualFileName, String email, String comments, long fileSize) {
         SetFileInfo result = new SetFileInfo();
-
-        var handler = CreateFileHandler(fileStream, actualFileName);
-        if (handler == null)
-        {
+        if (handler == null) {
             result.errorNo = 201;
             result.errorMsg = getLastErrMsg();
             return result;
         }
-        result.fileSize = fileStream.size();
-        return removeProtection(handler, actualFileName, email, comments, result);
-    }
-    public SetFileInfo removeProtection(IFileHandler handler, String actualFileName, String email, String comments, SetFileInfo result) {
-        String ownerEmail = email;
-        if (handler.Label != null && handler.Label.Label != null) {
-            result.labelGuid = handler.Label.Label.Id;
-        }
-        if (handler.Protection != null) {
-            ownerEmail = handler.Protection.Owner;
-        }
+        result.fileSize = fileSize;
+        String ownerEmail = getOrgFileInfo(handler, email, result);
 
-        if (comments == "") {
-            comments = "Delete Protection by " + ownerEmail;
-        }
-        LabelingOptions invokeLabelingOptions = new LabelingOptions()
-        {
-            AssignmentMethod = AssignmentMethod.Privileged, //because we are removing a high priority label
-            JustificationMessage = comments,
-            IsDowngradeJustified = true,
-        };
-
-        var protectionSettings = new ProtectionSettings
-        {
-            PFileExtensionBehavior = PFileExtensionBehavior.Default,
-        };
-        if (ownerEmail != "") {
-            protectionSettings.DelegatedUserEmail = ownerEmail;
+        ProtectionSettings protectionSettings = new ProtectionSettings();
+        protectionSettings.setPFileExtensionBehavior(PFileExtensionBehavior.Default);
+        if (!Objects.equals(ownerEmail, "")) {
+            protectionSettings.setDelegatedUserEmail(ownerEmail);
         }
 
         try {
-            if (handler.Protection != null) {
+            if (handler.getProtection() != null) {
                 // 원본 파일 형식이 레이블 지정을 지원하지 않는 경우 보호를 제거하면 레이블이 손실됩니다.
                 // 기본 형식이 레이블 지정을 지원하는 경우 레이블 메타데이터가 유지됩니다.
-                if (handler.Protection.AccessCheck(Rights.Extract) || handler.Protection.AccessCheck(Rights.Owner))
-                {
-                    handler.RemoveProtection();
+                if (handler.getProtection().getAccessCheck(Rights.Extract) || handler.getProtection().getAccessCheck(Rights.Owner)) {
+                    handler.removeProtection();
                 }
                 //Use the GetTemporaryDecryptedStream() or GetTemporaryDecryptedFile() API to create a temp decrypted output to render in your application.
             }
@@ -664,11 +496,7 @@ public class FileManager extends AbstractManager {
             return result;
         }
 
-        boolean isCommited = false;
-        if (handler.isModified()) {
-            isCommited = Task.Run(async () => await handler.CommitAsync(actualFileName)).Result;
-        }
-
+        boolean isCommited = commitAsync(handler, actualFileName, result);
         if (isCommited) {
             //handler.NotifyCommitSuccessful(fileName);
             result.newFileSize = getFileSize(actualFileName);
@@ -682,20 +510,66 @@ public class FileManager extends AbstractManager {
             result.errorMsg = "AIP File CommitAsync Failed.";
             setError(53, "FileManager::RemoveProtection Failed.", "RemoveProtection Failed by " + ownerEmail);
         }
+        getActionFileInfo(actualFileName, result);
+        return result;
+    }
+
+    private LabelingOptions getLabelingOptions(AssignmentMethod assignmentMethod, String justificationMessage, boolean isDowngradeJustified) {
+        LabelingOptions labelingOptions = new LabelingOptions();
+        labelingOptions.setAssignmentMethod(assignmentMethod);
+        labelingOptions.setJustificationMessage(justificationMessage);
+        labelingOptions.setDowngradeJustified(isDowngradeJustified);
+        return labelingOptions;
+    }
+    private String getOrgFileInfo(IFileHandler handler, String email, SetFileInfo result) {
+        String ownerEmail = email;
+        if (handler.getLabel() != null && handler.getLabel().label != null) {
+            result.labelGuid = handler.getLabel().label.getId();
+        }
+        if (handler.getProtection() != null) {
+            ownerEmail = handler.getProtection().getOwner();
+            result.fileOwner = handler.getProtection().getOwner();
+            if (handler.getProtection().getProtectionDescriptor() != null) {
+                result.templateGuid = handler.getProtection().getProtectionDescriptor().getTemplateId();
+            }
+        }
+        return ownerEmail;
+    }
+
+    private void getActionFileInfo(String actualFileName, SetFileInfo result) {
         AipFileInfo info = getFileInfo(actualFileName);
         if (info != null) {
-            if (info.Label != null) {
-                result.newFileLabelGuid = info.Label.Id;
+            if (info.getLabel() != null) {
+                result.newFileLabelGuid = info.getLabel().getId();
             }
-            if (info.Protection != null) {
-                result.newFileOwner = info.Protection.Owner;
-                if (info.Protection.ProtectionDescriptor != null)
+            if (info.getProtection() != null) {
+                result.newFileOwner = info.getProtection().getOwner();
+                if (info.getProtection().getProtectionDescriptor() != null)
                 {
-                    result.newFileTemplateGuid = info.Protection.ProtectionDescriptor.TemplateId;
+                    result.newFileTemplateGuid = info.getProtection().getProtectionDescriptor().getTemplateId();
                 }
             }
         }
-        return result;
+    }
+
+    private boolean commitAsync(IFileHandler handler, String actualFileName, SetFileInfo result) {
+        boolean isCommitted = false;
+        if (handler.isModified()) {
+            Future<Boolean> future = handler.commitAsync(actualFileName);
+            try {
+                isCommitted = future.get();
+            } catch (InterruptedException e) {
+                result.errorNo = 301;
+                result.errorMsg = "AIP File CommitAsync InterruptedException Exception.";
+                setError(61, "FileManager::commitAsync Failed.", e.getMessage());
+                Thread.currentThread().interrupt();
+            } catch (ExecutionException e) {
+                result.errorNo = 302;
+                result.errorMsg = "AIP File CommitAsync ExecutionException Exception.";
+                setError(62, "FileManager::commitAsync Failed.", e.getMessage());
+            }
+        }
+        return isCommitted;
     }
 
 //    public async Task<Stream> GetDecryptedStreamAsync(Stream inputStream, string filename)
@@ -705,8 +579,8 @@ public class FileManager extends AbstractManager {
 //    }
     // Protect the input bytes.
     public byte[] protect(IProtectionHandler handler, byte[] data) {
-        long buffersize = handler.getProtectedContentLength(data.length, true);
-        byte[] outputBuffer = new byte[(int) buffersize];
+        long bufferSize = handler.getProtectedContentLength(data.length, true);
+        byte[] outputBuffer = new byte[(int) bufferSize];
 
         handler.encryptBuffer(0, data, outputBuffer, true);
         return outputBuffer;
@@ -716,13 +590,13 @@ public class FileManager extends AbstractManager {
         long buffersize = data.length;
         byte[] clearBuffer = new byte[(int) buffersize];
 
-        var bytesDecrypted = handler.decryptBuffer(0, data, clearBuffer, true);
+        long bytesDecrypted = handler.decryptBuffer(0, data, clearBuffer, true);
 
         byte[] outputBuffer = new byte[(int) bytesDecrypted];
-        for (int i = 0; i < bytesDecrypted; i++)
-        {
-            outputBuffer[i] = clearBuffer[i];
-        }
+        System.arraycopy(clearBuffer, 0, outputBuffer, 0, (int)bytesDecrypted);
+//        for (int i = 0; i < bytesDecrypted; i++) {
+//            outputBuffer[i] = clearBuffer[i];
+//        }
         return outputBuffer;
     }
 

+ 13 - 6
src/main/java/com/aip/gateway/api/aip/model/AipFileInfo.java

@@ -1,12 +1,11 @@
 package com.aip.gateway.api.aip.model;
 
 import io.swagger.annotations.ApiModel;
-import lombok.Builder;
 import lombok.Data;
 
 @ApiModel("AipFileInfo(File AIP Information")
 @Data
-@Builder
+//@Builder
 public class AipFileInfo {
 
     public enum AipProtectionType {
@@ -20,12 +19,20 @@ public class AipFileInfo {
     private String errorMessage;
 
     private AipContentLabel content;
-
     private AipLabel label;
-
     private AipProtection protection;
-
     private long fileSize;
-
     private String outputFileName;
+
+    public AipFileInfo(int errorCode, String errorMessage) {
+        this.errorCode = errorCode;
+        this.errorMessage = errorMessage;
+
+        this.content = null;
+        this.label = null;
+        this.protection = null;
+        this.fileSize = 0;
+        this.outputFileName = "";
+    }
+
 }

+ 16 - 0
src/main/java/com/aip/gateway/api/aip/model/AipFileStatus.java

@@ -0,0 +1,16 @@
+package com.aip.gateway.api.aip.model;
+
+import io.swagger.annotations.ApiModel;
+import lombok.Builder;
+import lombok.Data;
+
+@ApiModel("AipFileStatus(File AIP Status")
+@Data
+@Builder
+public class AipFileStatus {
+
+    private boolean isProtected;
+    private boolean isLabeled;
+    private boolean containsProtectedObjects;
+
+}

+ 1 - 1
src/main/java/com/aip/gateway/api/aip/model/AipProtection.java

@@ -11,7 +11,7 @@ import lombok.NoArgsConstructor;
 @Builder
 public class AipProtection {
 
-    private AipProtectionDescriptor potectionDescriptor;
+    private AipProtectionDescriptor protectionDescriptor;
 
     /// <summary>Email address of content owner</summary>
     private String owner;

+ 62 - 0
src/main/java/com/aip/gateway/api/aip/utils/AipFileStream.java

@@ -0,0 +1,62 @@
+package com.aip.gateway.api.aip.utils;
+
+import com.microsoft.informationprotection.IStream;
+
+import java.util.Base64;
+
+public class AipFileStream implements IStream {
+
+    private byte[] fileData;
+
+    public AipFileStream(String fileDataString) {
+        this.fileData = Base64.getDecoder().decode(fileDataString);;
+    }
+
+    @Override
+    public long read(byte[] bytes, long l) {
+        int readLength = (int)Math.min(l, fileData.length);
+        bytes = new byte[readLength];
+        System.arraycopy(fileData, 0, bytes, 0, readLength);
+        return readLength;
+    }
+
+    @Override
+    public long write(byte[] bytes) {
+        return 0;
+    }
+
+    @Override
+    public boolean flush() {
+        return true;
+    }
+
+    @Override
+    public void seek(long l) {
+
+    }
+
+    @Override
+    public boolean canRead() {
+        return true;
+    }
+
+    @Override
+    public boolean canWrite() {
+        return false;
+    }
+
+    @Override
+    public long position() {
+        return 0;
+    }
+
+    @Override
+    public long size() {
+        return this.fileData.length;
+    }
+
+    @Override
+    public void size(long l) {
+
+    }
+}

+ 59 - 0
src/main/java/com/aip/gateway/api/aip/utils/AipFileUtils.java

@@ -0,0 +1,59 @@
+package com.aip.gateway.api.aip.utils;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.springframework.util.StringUtils;
+
+import java.io.File;
+import java.io.IOException;
+
+@Slf4j
+public class AipFileUtils {
+
+    public static long getSize(String fileName) {
+        File file = new File(fileName);
+        return file.length();
+    }
+
+    public static boolean isExists(String fileName) {
+        File file = new File(fileName);
+        return file.exists();
+    }
+
+    public static String getFileName(String fileName) {
+        String name = FilenameUtils.getName(fileName);
+        return name;
+    }
+    public static String getFileNameWithoutExtension(String fileName) {
+        return StringUtils.stripFilenameExtension(getFileName(fileName));
+    }
+    public static String getExtension(String fileName) {
+        String fileExt = StringUtils.getFilenameExtension(fileName);
+        if (fileExt == null) {
+            return ".";
+        }
+        return "." + fileExt.toLowerCase();
+    }
+
+    public static boolean delete(String fileName) {
+        File file = new File(fileName);
+        if (file.exists()) {
+            return file.delete();
+        }
+        return false;
+    }
+
+    public static boolean streamToFile(byte[] byteArrayData, String fileName) {
+        boolean result = true;
+        try {
+            FileUtils.writeByteArrayToFile(new File(fileName), byteArrayData);
+        }
+        catch (IOException e) {
+            log.error("streamToFile: IOException: {}, {}", fileName, e.getMessage());
+            result = false;
+        }
+        return result;
+    }
+
+}

+ 16 - 11
src/main/java/com/aip/gateway/api/controller/ApiAipController.java

@@ -4,6 +4,7 @@ import com.aip.gateway.api.aip.model.AipLabel;
 import com.aip.gateway.api.aip.model.AipTemplate;
 import com.aip.gateway.api.model.response.ApiResponseModel;
 import com.aip.gateway.api.repository.AppRepository;
+import com.aip.gateway.api.repository.GlobalConstants;
 import com.aip.gateway.api.service.IApiAipService;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.v3.oas.annotations.Operation;
@@ -41,16 +42,17 @@ public class ApiAipController extends  BaseController {
             @RequestParam("apiKey") String apiKey,
             HttpServletRequest request)
     {
+        GlobalConstants.setAuthorization(request, GlobalConstants.API_AIP_DOWNLOAD, apiKey, null);
         try {
             int authError = this.appRepo.checkApiKeyValidation(apiKey, getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.downloadAipInfo());
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/aip/download, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -63,21 +65,22 @@ public class ApiAipController extends  BaseController {
             HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_AIP_LABELS, apiKey, null);
             int authError = this.appRepo.checkApiKeyValidation(apiKey, getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             List<AipLabel> response = this.service.getLabels();
             return ResponseEntity.ok().body(ApiResponseModel.builder()
                     .success(true)
-                    .statusCode(HttpStatus.OK)
+                    .statusCode(HttpStatus.OK.value())
                     .message("success")
                     .result(response)
                     .build());
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/aip/labels, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -90,21 +93,22 @@ public class ApiAipController extends  BaseController {
             HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_AIP_POLICIES, apiKey, null);
             int authError = this.appRepo.checkApiKeyValidation(apiKey, getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             List<AipLabel> response = this.service.getPolicies();
             return ResponseEntity.ok().body(ApiResponseModel.builder()
                     .success(true)
-                    .statusCode(HttpStatus.OK)
+                    .statusCode(HttpStatus.OK.value())
                     .message("success")
                     .result(response)
                     .build());
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/aip/policies, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -117,21 +121,22 @@ public class ApiAipController extends  BaseController {
             HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_AIP_PROTECTIONS, apiKey, null);
             int authError = this.appRepo.checkApiKeyValidation(apiKey, getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             List<AipTemplate> response = this.service.getProtections();
             return ResponseEntity.ok().body(ApiResponseModel.builder()
                     .success(true)
-                    .statusCode(HttpStatus.OK)
+                    .statusCode(HttpStatus.OK.value())
                     .message("success")
                     .result(response)
                     .build());
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/aip/protections, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 

+ 20 - 14
src/main/java/com/aip/gateway/api/controller/ApiDbController.java

@@ -6,6 +6,7 @@ import com.aip.gateway.api.dto.LinkedServerDto;
 import com.aip.gateway.api.dto.LinkedSystemDto;
 import com.aip.gateway.api.model.response.ApiResponseModel;
 import com.aip.gateway.api.repository.AppRepository;
+import com.aip.gateway.api.repository.GlobalConstants;
 import com.aip.gateway.api.service.IApiDbService;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.v3.oas.annotations.Operation;
@@ -44,15 +45,16 @@ public class ApiDbController extends  BaseController {
             HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_DB_RELOAD, apiKey, null);
             int authError = this.appRepo.checkApiKeyValidation(apiKey, getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.reloadDatabase());
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/db/reload, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -65,21 +67,22 @@ public class ApiDbController extends  BaseController {
             HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_DB_LINKED_SYSTEMS, apiKey, null);
             int authError = this.appRepo.checkApiKeyValidation(apiKey, getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             List<LinkedSystemDto> response = this.service.getLinkedSystems();
             return ResponseEntity.ok().body(ApiResponseModel.builder()
                     .success(true)
-                    .statusCode(HttpStatus.OK)
+                    .statusCode(HttpStatus.OK.value())
                     .message("success")
                     .result(response)
                     .build());
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/db/linked-systems, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -92,21 +95,22 @@ public class ApiDbController extends  BaseController {
             HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_DB_LINKED_SERVERS, apiKey, null);
             int authError = this.appRepo.checkApiKeyValidation(apiKey, getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             List<LinkedServerDto> response = this.service.getLinkedServers();
             return ResponseEntity.ok().body(ApiResponseModel.builder()
                     .success(true)
-                    .statusCode(HttpStatus.OK)
+                    .statusCode(HttpStatus.OK.value())
                     .message("success")
                     .result(response)
                     .build());
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/db/linked-servers, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -119,21 +123,22 @@ public class ApiDbController extends  BaseController {
             HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_DB_LINKED_API_KEYS, apiKey, null);
             int authError = this.appRepo.checkApiKeyValidation(apiKey, getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             List<LinkedApiKeyDto> response = this.service.getLinkedApiKeys();
             return ResponseEntity.ok().body(ApiResponseModel.builder()
                     .success(true)
-                    .statusCode(HttpStatus.OK)
+                    .statusCode(HttpStatus.OK.value())
                     .message("success")
                     .result(response)
                     .build());
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/db/linked-api-keys, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -146,21 +151,22 @@ public class ApiDbController extends  BaseController {
             HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_DB_LINKED_DECRYPT_KEYS, apiKey, null);
             int authError = this.appRepo.checkApiKeyValidation(apiKey, getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             List<LinkedDecryptKeyDto> response = this.service.getLinkedDecryptKeys();
             return ResponseEntity.ok().body(ApiResponseModel.builder()
                     .success(true)
-                    .statusCode(HttpStatus.OK)
+                    .statusCode(HttpStatus.OK.value())
                     .message("success")
                     .result(response)
                     .build());
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/db/linked-decrypt-keys, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 

+ 24 - 16
src/main/java/com/aip/gateway/api/controller/ApiFileController.java

@@ -6,6 +6,7 @@ import com.aip.gateway.api.model.request.RequestFileDel;
 import com.aip.gateway.api.model.request.RequestFileSet;
 import com.aip.gateway.api.model.response.ApiResponseModel;
 import com.aip.gateway.api.repository.AppRepository;
+import com.aip.gateway.api.repository.GlobalConstants;
 import com.aip.gateway.api.service.IApiFileService;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.v3.oas.annotations.Operation;
@@ -41,15 +42,16 @@ public class ApiFileController extends  BaseController {
             @RequestBody @Valid final RequestFile req, HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_FILE_INFO, req.getApiKey(), req);
             int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.getInfo(req));
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/file/info, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -62,15 +64,16 @@ public class ApiFileController extends  BaseController {
             @RequestBody @Valid final RequestFileSet req, HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_FILE_SET_LABEL, req.getApiKey(), req);
             int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.setLabel(req));
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/file/set-label, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -83,15 +86,16 @@ public class ApiFileController extends  BaseController {
             @RequestBody @Valid final RequestFileDel req, HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_FILE_DELETE_LABEL, req.getApiKey(), req);
             int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.delLabel(req));
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/file/delete-label, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -104,15 +108,16 @@ public class ApiFileController extends  BaseController {
             @RequestBody @Valid final RequestFileSet req, HttpServletRequest request)
     {
         try {
-             int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_FILE_SET_PROTECTION, req.getApiKey(), req);
+            int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
              if (authError != 0) {
-                 return responseApiKeyValidationError(authError);
+                 return responseApiKeyValidationError(request, authError);
              }
              return responseSuccess(this.service.setProtection(req));
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/file/set-protection, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -125,15 +130,16 @@ public class ApiFileController extends  BaseController {
             @RequestBody @Valid final RequestFileDel req, HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_FILE_DELETE_PROTECTIN, req.getApiKey(), req);
             int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.delProtection(req));
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/file/delete-protection, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -141,20 +147,21 @@ public class ApiFileController extends  BaseController {
     @ApiResponse(responseCode = "200", description = "File AIP Label Or Protection set success.")
     @ApiOperation(value = "File AIP Label Or Protection 설정", response = ApiResponseModel.class, responseContainer = "ArrayList")
     @PostMapping(value = "set-label-protection", produces = {"application/json; charset=utf8"})
-    public ResponseEntity<ApiResponseModel> setProtection(
+    public ResponseEntity<ApiResponseModel> setLabelProtection(
             @Parameter(name = "req", description = "File AIP Label Or Protection 설정 요청 데이터", required = true)
             @RequestBody @Valid final RequestFileAllSet req, HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_FILE_SET_LABEL_PROTECTION, req.getApiKey(), req);
             int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.setLabelProtection(req));
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/file/set-label-protection, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -167,15 +174,16 @@ public class ApiFileController extends  BaseController {
             @RequestBody @Valid final RequestFileDel req, HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_FILE_DELETE_LABEL_PROTECTION, req.getApiKey(), req);
             int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.delLabelProtection(req));
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/file/delete-label-protection, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 

+ 23 - 15
src/main/java/com/aip/gateway/api/controller/ApiStreamController.java

@@ -6,6 +6,7 @@ import com.aip.gateway.api.model.request.RequestStreamDel;
 import com.aip.gateway.api.model.request.RequestStreamSet;
 import com.aip.gateway.api.model.response.ApiResponseModel;
 import com.aip.gateway.api.repository.AppRepository;
+import com.aip.gateway.api.repository.GlobalConstants;
 import com.aip.gateway.api.service.IApiStreamService;
 import io.swagger.annotations.ApiOperation;
 import io.swagger.v3.oas.annotations.Operation;
@@ -41,15 +42,16 @@ public class ApiStreamController extends  BaseController {
             @RequestBody @Valid final RequestStream req, HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_STREAM_INFO, req.getApiKey(), req);
             int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.getInfo(req));
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/stream/info, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -62,15 +64,16 @@ public class ApiStreamController extends  BaseController {
             @RequestBody @Valid final RequestStreamSet req, HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_STREAM_SET_LABEL, req.getApiKey(), req);
             int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.setLabel(req));
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/stream/set-label, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -83,15 +86,16 @@ public class ApiStreamController extends  BaseController {
             @RequestBody @Valid final RequestStreamDel req, HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_STREAM_DELETE_LABEL, req.getApiKey(), req);
             int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.delLabel(req));
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/stream/delete-label, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -104,15 +108,16 @@ public class ApiStreamController extends  BaseController {
             @RequestBody @Valid final RequestStreamSet req, HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_STREAM_SET_PROTECTION, req.getApiKey(), req);
             int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.setProtection(req));
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/stream/set-protection, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -125,15 +130,16 @@ public class ApiStreamController extends  BaseController {
             @RequestBody @Valid final RequestStreamDel req, HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_STREAM_DELETE_PROTECTIN, req.getApiKey(), req);
             int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.delProtection(req));
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/stream/delete-protection, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -141,20 +147,21 @@ public class ApiStreamController extends  BaseController {
     @ApiResponse(responseCode = "200", description = "Stream AIP Label Or Protection set success.")
     @ApiOperation(value = "Stream AIP Label Or Protection 설정", response = ApiResponseModel.class, responseContainer = "ArrayList")
     @PostMapping(value = "set-label-protection", produces = {"application/json; charset=utf8"})
-    public ResponseEntity<ApiResponseModel> setProtection(
+    public ResponseEntity<ApiResponseModel> setLabelProtection(
             @Parameter(name = "req", description = "Stream AIP Label Or Protection 설정 요청 데이터", required = true)
             @RequestBody @Valid final RequestStreamAllSet req, HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_STREAM_SET_LABEL_PROTECTION, req.getApiKey(), req);
             int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.setLabelProtection(req));
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/stream/set-label-protection, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 
@@ -167,15 +174,16 @@ public class ApiStreamController extends  BaseController {
             @RequestBody @Valid final RequestStreamDel req, HttpServletRequest request)
     {
         try {
+            GlobalConstants.setAuthorization(request, GlobalConstants.API_STREAM_DELETE_LABEL_PROTECTION, req.getApiKey(), req);
             int authError = this.appRepo.checkApiKeyValidation(req.getApiKey(), getRemoteIP(request));
             if (authError != 0) {
-                return responseApiKeyValidationError(authError);
+                return responseApiKeyValidationError(request, authError);
             }
             return responseSuccess(this.service.delLabelProtection(req));
         }
         catch (Exception e) {
             log.error("exception: /v1/aip-api/stream/delete-label-protection, {}", e.getMessage());
-            return responseException(e);
+            return responseException(request, e);
         }
     }
 

+ 14 - 8
src/main/java/com/aip/gateway/api/controller/BaseController.java

@@ -1,6 +1,7 @@
 package com.aip.gateway.api.controller;
 
 import com.aip.gateway.api.model.response.*;
+import com.aip.gateway.api.repository.GlobalConstants;
 import jakarta.servlet.http.HttpServletRequest;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
@@ -34,13 +35,14 @@ public class BaseController {
         {
             ipAddr = "127.0.0.1";   //==> localhost
         }
+        request.setAttribute(GlobalConstants.API_IP_ADDRESS, ipAddr);
         return ipAddr;
     }
 
     protected ResponseEntity<ApiResponseModel> responseSuccess(GeneralResponse response) {
         return ResponseEntity.ok().body(ApiResponseModel.builder()
                 .success(true)
-                .statusCode(HttpStatus.OK)
+                .statusCode(HttpStatus.OK.value())
                 .message("success")
                 .result(response)
                 .build());
@@ -49,7 +51,7 @@ public class BaseController {
     protected ResponseEntity<ApiResponseModel> responseSuccess(ResponseInfo response) {
         return ResponseEntity.ok().body(ApiResponseModel.builder()
                 .success(true)
-                .statusCode(HttpStatus.OK)
+                .statusCode(HttpStatus.OK.value())
                 .message("success")
                 .result(response)
                 .build());
@@ -58,7 +60,7 @@ public class BaseController {
     protected ResponseEntity<ApiResponseModel> responseSuccess(ResponseFile response) {
         return ResponseEntity.ok().body(ApiResponseModel.builder()
                 .success(true)
-                .statusCode(HttpStatus.OK)
+                .statusCode(HttpStatus.OK.value())
                 .message("success")
                 .result(response)
                 .build());
@@ -67,22 +69,24 @@ public class BaseController {
     protected  ResponseEntity<ApiResponseModel> responseSuccess(ResponseStream response) {
         return ResponseEntity.ok().body(ApiResponseModel.builder()
                 .success(true)
-                .statusCode(HttpStatus.OK)
+                .statusCode(HttpStatus.OK.value())
                 .message("success")
                 .result(response)
                 .build());
     }
 
-    protected  ResponseEntity<ApiResponseModel> responseException(Exception ex) {
+    protected  ResponseEntity<ApiResponseModel> responseException(HttpServletRequest request, Exception ex) {
+        request.setAttribute(GlobalConstants.API_RESULT_CODE, HttpStatus.INTERNAL_SERVER_ERROR.value());
+        request.setAttribute(GlobalConstants.API_RESULT_MESSAGE, ex.getMessage());
         return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(ApiResponseModel.builder()
                 .success(false)
-                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR)
+                .statusCode(HttpStatus.INTERNAL_SERVER_ERROR.value())
                 .message(ex.getMessage())
                 .result(null)
                 .build());
     }
 
-    protected  ResponseEntity<ApiResponseModel> responseApiKeyValidationError(int error) {
+    protected  ResponseEntity<ApiResponseModel> responseApiKeyValidationError(HttpServletRequest request, int error) {
         String errorMessage = "";
         if (error == 1) {
             errorMessage = "등록되어 있지 않은 API KEY 입니다.";
@@ -96,9 +100,11 @@ public class BaseController {
         else {
             errorMessage = "API KEY 유효성 검사 중 시스템 내부 오류가 발생하였습니다.";
         }
+        request.setAttribute(GlobalConstants.API_RESULT_CODE, error);
+        request.setAttribute(GlobalConstants.API_RESULT_MESSAGE, errorMessage);
         return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponseModel.builder()
                 .success(false)
-                .statusCode(HttpStatus.BAD_REQUEST)
+                .statusCode(HttpStatus.BAD_REQUEST.value())
                 .message(errorMessage)
                 .result(null)
                 .build());

+ 89 - 0
src/main/java/com/aip/gateway/api/interceptor/AipApiControllerInterceptor.java

@@ -0,0 +1,89 @@
+package com.aip.gateway.api.interceptor;
+
+import com.aip.gateway.api.entity.TbAipCallLog;
+import com.aip.gateway.api.process.DbmsData;
+import com.aip.gateway.api.process.DbmsDataProcess;
+import com.aip.gateway.api.process.DbmsDataType;
+import com.aip.gateway.api.repository.GlobalConstants;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.HttpStatus;
+import org.springframework.web.servlet.HandlerInterceptor;
+import org.springframework.web.servlet.ModelAndView;
+import org.springframework.web.util.ContentCachingResponseWrapper;
+
+import java.io.UnsupportedEncodingException;
+import java.time.LocalDateTime;
+import java.util.UUID;
+
+@Slf4j
+public class AipApiControllerInterceptor implements HandlerInterceptor {
+
+    private final DbmsDataProcess dbmsDataProcess;
+    private final ObjectMapper objectMapper;
+    public AipApiControllerInterceptor(DbmsDataProcess dbmsDataProcess) {
+        this.dbmsDataProcess = dbmsDataProcess;
+        objectMapper = new ObjectMapper();
+    }
+
+    private String getResponseBody(HttpServletResponse response) {
+        ContentCachingResponseWrapper responseWrapper = (ContentCachingResponseWrapper) response;
+        byte[] contentAsByteArray = responseWrapper.getContentAsByteArray();
+        try {
+            return new String(contentAsByteArray, response.getCharacterEncoding());
+        } catch (UnsupportedEncodingException e) {
+            log.error("getResponseBody UnsupportedEncodingException: {}", e.getMessage());
+            return "";
+        }
+    }
+
+    @Override
+    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+        // API GUID 생성
+        String apiGuid = UUID.randomUUID().toString();
+        request.setAttribute(GlobalConstants.API_GUID, apiGuid);
+        request.setAttribute(GlobalConstants.API_START_TM, LocalDateTime.now());
+        request.setAttribute(GlobalConstants.API_START_MILLISECONDS, System.currentTimeMillis());
+        log.error("AipApiControllerInterceptor: preHandle ==> {}, {}", request.getRequestURI(), apiGuid);
+        return true;
+    }
+
+    @Override
+    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
+        // 요청 처리 후 실행되는 로직 (필요한 경우 사용)
+        log.error("AipApiControllerInterceptor: postHandle ==> {}", request);
+    }
+
+    @Override
+    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
+        // 응답 완료 후 실행되는 로직 (필요한 경우 사용)
+        long endTime = System.currentTimeMillis();
+        long startTime = (long)request.getAttribute(GlobalConstants.API_START_MILLISECONDS);
+        int errorCode = 0;
+        String errorMessage = "";
+        int responseStatusCode = response.getStatus();
+        log.error("responseStatusCode: {}, {}", responseStatusCode, HttpStatus.OK.value());
+        if (responseStatusCode != HttpStatus.OK.value()) {
+            errorCode = (int)request.getAttribute(GlobalConstants.API_RESULT_CODE);
+            errorMessage = (String)request.getAttribute(GlobalConstants.API_RESULT_MESSAGE);
+        }
+
+        TbAipCallLog callLog = TbAipCallLog.builder()
+                .apiEndPoint(request.getRequestURI())
+                .apiGuid(GlobalConstants.getApiGuid(request))
+                .ipAddress((String)request.getAttribute(GlobalConstants.API_IP_ADDRESS))
+                .requestAt((LocalDateTime) request.getAttribute(GlobalConstants.API_START_TM))
+                .responseAt(LocalDateTime.now())
+                .responseStatusCode(responseStatusCode)
+                .errorCode(errorCode)
+                .errorMessage(errorMessage)
+                .responseTime((int)(endTime - startTime))
+                .build();
+        dbmsDataProcess.add(new DbmsData(DbmsDataType.DBMS_DATA_API_CALL_LOG, false, callLog));
+
+        log.error("AipApiControllerInterceptor: afterCompletion ==> {}", request.getAttribute(GlobalConstants.API_GUID));
+    }
+
+}

+ 11 - 3
src/main/java/com/aip/gateway/api/model/app/AipSettings.java

@@ -7,6 +7,8 @@ import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 
+import java.io.File;
+
 @Slf4j
 @Data
 @AllArgsConstructor
@@ -34,18 +36,18 @@ public class AipSettings {
     private String supportedFileExt;    // 지원하는 파일 확장자
     private String protectedFileExt;    // 암호화 시에 변환되는 파일 확장자
 
-    public AipConfig getConfig()
-    {
+    public AipConfig getConfig() {
         return AipConfig.builder()
                 .appName(appName)
                 .appVersion(appVersion)
                 .clientId(clientId)
                 .tenantId(tenantId)
                 .mipData(mipData)
+                .loginType(getLoginType())
                 .domain(domain)
                 .eMail(eMail)
                 .secretValue(secretValue)
-                .loginType(getLoginType())
+                .certThumbPrint(certThumbPrint)
                 .build();
     }
 
@@ -95,9 +97,15 @@ public class AipSettings {
         }
         else if (orgKey.equalsIgnoreCase("SourceFileDir")) {
             sourceFileDir = value;
+            if (!sourceFileDir.substring(sourceFileDir.length()-1).equals(File.separator)) {
+                sourceFileDir = sourceFileDir + File.separator;
+            }
         }
         else if (orgKey.equalsIgnoreCase("TargetFileDir")) {
             targetFileDir = value;
+            if (!targetFileDir.substring(targetFileDir.length()-1).equals(File.separator)) {
+                targetFileDir = targetFileDir + File.separator;
+            }
         }
         else if (orgKey.equalsIgnoreCase("SetLabelId")) {
             setLabelId = value;

+ 7 - 2
src/main/java/com/aip/gateway/api/model/request/RequestStream.java

@@ -1,6 +1,8 @@
 package com.aip.gateway.api.model.request;
 
+import com.fasterxml.jackson.annotation.JsonProperty;
 import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.EqualsAndHashCode;
 import lombok.Getter;
 import lombok.Setter;
@@ -15,10 +17,13 @@ import lombok.ToString;
 @ApiModel("RequestStream(STREAM 요청")
 public class RequestStream extends RequestBase {
 
+    @ApiModelProperty("File 이름")  // Y BLOB
     private String dispFileName;
-    private byte[] fileData;
+    @ApiModelProperty("File Stream Data")  // Y BLOB
+    @JsonProperty("fileData")
+    private String fileData;
 
-    public RequestStream(String apiKey, String email, String apiGuid, String decryptKey, String dispFileName, byte[] fileData) {
+    public RequestStream(String apiKey, String email, String apiGuid, String decryptKey, String dispFileName, String fileData) {
         super(apiKey, email, apiGuid, decryptKey);
         this.dispFileName = dispFileName;
         this.fileData = fileData;

+ 1 - 1
src/main/java/com/aip/gateway/api/model/request/RequestStreamAllSet.java

@@ -19,7 +19,7 @@ public class RequestStreamAllSet extends RequestStream {
     private String templateGuid;
     private String comment;
 
-    public RequestStreamAllSet(String apiKey, String email, String apiGuid, String decryptKey, String dispFileName, byte[] fileData) {
+    public RequestStreamAllSet(String apiKey, String email, String apiGuid, String decryptKey, String dispFileName, String fileData) {
         super(apiKey, email, apiGuid, decryptKey, dispFileName, fileData);
     }
 }

+ 1 - 1
src/main/java/com/aip/gateway/api/model/request/RequestStreamDel.java

@@ -14,7 +14,7 @@ public class RequestStreamDel extends RequestStream {
 
     private String comment;
 
-    public RequestStreamDel(String apiKey, String email, String apiGuid, String decryptKey, String dispFileName, byte[] fileData, String comment) {
+    public RequestStreamDel(String apiKey, String email, String apiGuid, String decryptKey, String dispFileName, String fileData, String comment) {
         super(apiKey, email, apiGuid, decryptKey, dispFileName, fileData);
         this.comment = comment;
     }

+ 1 - 1
src/main/java/com/aip/gateway/api/model/request/RequestStreamSet.java

@@ -15,7 +15,7 @@ public class RequestStreamSet extends RequestStream {
     private String aipGuid;
     private String comment;
 
-    public RequestStreamSet(String apiKey, String email, String apiGuid, String decryptKey, String dispFileName, byte[] fileData) {
+    public RequestStreamSet(String apiKey, String email, String apiGuid, String decryptKey, String dispFileName, String fileData) {
         super(apiKey, email, apiGuid, decryptKey, dispFileName, fileData);
     }
 }

+ 1 - 2
src/main/java/com/aip/gateway/api/model/response/ApiResponseModel.java

@@ -4,7 +4,6 @@ import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Builder;
 import lombok.Data;
-import org.springframework.http.HttpStatusCode;
 
 @Data
 @Builder
@@ -16,7 +15,7 @@ public class ApiResponseModel {
     @ApiModelProperty("API 호출 결과 메지지")
     private String message;
     @ApiModelProperty("HttpStatusCode")
-    private HttpStatusCode statusCode;
+    private int statusCode;
 
     @ApiModelProperty("API 호출 결과 데이터")
     private Object result;

+ 22 - 4
src/main/java/com/aip/gateway/api/model/response/ResponseBase.java

@@ -1,15 +1,14 @@
 package com.aip.gateway.api.model.response;
 
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import io.swagger.annotations.ApiModel;
-import lombok.Builder;
 import lombok.Data;
-import com.fasterxml.jackson.annotation.JsonIgnore;
 
 import java.io.Serial;
 import java.io.Serializable;
 
 @Data
-@Builder
+//@Builder
 @ApiModel("ResponseBase(응답 베이스")
 public class ResponseBase implements Serializable {
     @Serial
@@ -34,7 +33,7 @@ public class ResponseBase implements Serializable {
     @JsonIgnore
     private String fileExt;
     @JsonIgnore
-    private String fileSize;
+    private long fileSize;
 
     /// 결과 파일 정보
     @JsonIgnore
@@ -49,4 +48,23 @@ public class ResponseBase implements Serializable {
     private String newFileExt;
     @JsonIgnore
     private long newFileSize;
+
+    public ResponseBase(int errorCode, String errorMessage, String dispFileName, String fileId, String fileName, String fileLabelGuid, String fileProtectionGuid, String fileOwner, String fileExt, long fileSize, String newFileName, String newFileLabelGuid, String newFileProtectionGuid, String newFileOwner, String newFileExt, long newFileSize) {
+        this.errorCode = errorCode;
+        this.errorMessage = errorMessage;
+        this.dispFileName = dispFileName;
+        this.fileId = fileId;
+        this.fileName = fileName;
+        this.fileLabelGuid = fileLabelGuid;
+        this.fileProtectionGuid = fileProtectionGuid;
+        this.fileOwner = fileOwner;
+        this.fileExt = fileExt;
+        this.fileSize = fileSize;
+        this.newFileName = newFileName;
+        this.newFileLabelGuid = newFileLabelGuid;
+        this.newFileProtectionGuid = newFileProtectionGuid;
+        this.newFileOwner = newFileOwner;
+        this.newFileExt = newFileExt;
+        this.newFileSize = newFileSize;
+    }
 }

+ 7 - 4
src/main/java/com/aip/gateway/api/model/response/ResponseFile.java

@@ -1,7 +1,10 @@
 package com.aip.gateway.api.model.response;
 
 import io.swagger.annotations.ApiModel;
-import lombok.*;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
 
 @EqualsAndHashCode(callSuper = true)
 //@Data
@@ -14,8 +17,8 @@ public class ResponseFile extends ResponseBase {
 
     private String outputFileName;
 
-    public ResponseFile(int errorCode, String errorMessage, String dispFileName, String fileId, String fileName, String fileLabelGuid, String fileProtectionGuid, String fileOwner, String fileExt, String fileSize, String newFileName, String newFileLabelGuid, String newFileProtectionGuid, String newFileOwner, String newFileExt, long newFileSize, String outputFileName) {
-        super(errorCode, errorMessage, dispFileName, fileId, fileName, fileLabelGuid, fileProtectionGuid, fileOwner, fileExt, fileSize, newFileName, newFileLabelGuid, newFileProtectionGuid, newFileOwner, newFileExt, newFileSize);
-        this.outputFileName = outputFileName;
+    public ResponseFile(int errorCode, String errorMessage) {
+        super(errorCode, errorMessage, "", "", "", "", "", "", "", 0, "", "", "", "", "", 0);
+        outputFileName = "";
     }
 }

+ 15 - 4
src/main/java/com/aip/gateway/api/model/response/ResponseInfo.java

@@ -1,9 +1,10 @@
 package com.aip.gateway.api.model.response;
 
+import com.aip.gateway.api.utils.TimeUtils;
 import io.swagger.annotations.ApiModel;
 import lombok.*;
 
-import java.sql.Date;
+import java.util.Date;
 
 @EqualsAndHashCode(callSuper = true)
 //@Data
@@ -14,7 +15,7 @@ import java.sql.Date;
 @ApiModel("ResponseInfo(FILE INFO 응답")
 public class ResponseInfo extends ResponseBase {
 
-    private boolean isLabled;
+    private boolean isLabeled;
     private boolean isProtected;
 
     private Date creationTime;
@@ -25,7 +26,17 @@ public class ResponseInfo extends ResponseBase {
     private String templateId;
     private String templateName;
 
-    ResponseInfo(int errorCode, String errorMessage, String dispFileName, String fileId, String fileName, String fileLabelGuid, String fileProtectionGuid, String fileOwner, String fileExt, String fileSize, String newFileName, String newFileLabelGuid, String newFileProtectionGuid, String newFileOwner, String newFileExt, long newFileSize) {
-        super(errorCode, errorMessage, dispFileName, fileId, fileName, fileLabelGuid, fileProtectionGuid, fileOwner, fileExt, fileSize, newFileName, newFileLabelGuid, newFileProtectionGuid, newFileOwner, newFileExt, newFileSize);
+    public ResponseInfo(int errorCode, String errorMessage) {
+        super(errorCode, errorMessage, "", "", "", "", "", "", "", 0, "", "", "", "", "", 0);
+        isLabeled = false;
+        isProtected = false;
+        creationTime = TimeUtils.getCurrentDate();
+        owner = "";
+        contentId = "";
+        labelId = "";
+        labelName = "";
+        templateId = "";
+        templateName = "";
     }
+
 }

+ 14 - 5
src/main/java/com/aip/gateway/api/model/response/ResponseStream.java

@@ -1,8 +1,13 @@
 package com.aip.gateway.api.model.response;
 
-import io.swagger.annotations.ApiModel;
-import lombok.*;
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
 
 @EqualsAndHashCode(callSuper = true)
 //@Data
@@ -13,12 +18,16 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
 @ApiModel("ResponseStream(STREAM 응답")
 public class ResponseStream extends ResponseBase {
 
-    private byte[] fileData;
+    @ApiModelProperty("File Stream Data")  // Y BLOB
+    @JsonProperty("fileData")
+    private String fileData;
 
     @JsonIgnore
     private String outputFileName;
 
-    ResponseStream(int errorCode, String errorMessage, String dispFileName, String fileId, String fileName, String fileLabelGuid, String fileProtectionGuid, String fileOwner, String fileExt, String fileSize, String newFileName, String newFileLabelGuid, String newFileProtectionGuid, String newFileOwner, String newFileExt, long newFileSize) {
-        super(errorCode, errorMessage, dispFileName, fileId, fileName, fileLabelGuid, fileProtectionGuid, fileOwner, fileExt, fileSize, newFileName, newFileLabelGuid, newFileProtectionGuid, newFileOwner, newFileExt, newFileSize);
+    public ResponseStream(int errorCode, String errorMessage) {
+        super(errorCode, errorMessage, "", "", "", "", "", "", "", 0, "", "", "", "", "", 0);
+        fileData = null;
+        outputFileName = "";
     }
 }

+ 4 - 2
src/main/java/com/aip/gateway/api/process/DbmsDataProcess.java

@@ -74,11 +74,13 @@ public class DbmsDataProcess {
             switch(type) {
                 case DBMS_DATA_API_CALL_LOG:
                     TbAipCallLog callLog = (TbAipCallLog)data.getData();
-                    this.mapper.insertAipCallLog(callLog);
+                    cnt = this.mapper.insertAipCallLog(callLog);
+                    log.info("DBMS_DATA_API_CALL_LOG: {} EA.", cnt);
                     break;
                 case DBMS_DATA_AIP_FILE_JOB_LOG:
                     TbAipFileJobLog fileJobLog = (TbAipFileJobLog)data.getData();
-                    this.mapper.insertAipFileJobLog(fileJobLog);
+                    cnt = this.mapper.insertAipFileJobLog(fileJobLog);
+                    log.info("DBMS_DATA_AIP_FILE_JOB_LOG: {} EA.", cnt);
                     break;
                 default:
                     log.error("DbmsJobProcess.process: Unknown Request {}.", type);

+ 32 - 2
src/main/java/com/aip/gateway/api/repository/AipFileRepository.java

@@ -1,17 +1,47 @@
 package com.aip.gateway.api.repository;
 
+import com.aip.gateway.api.aip.manager.AipFileManager;
+import com.aip.gateway.api.aip.model.AipLabel;
+import com.aip.gateway.api.aip.model.AipTemplate;
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
-import lombok.Setter;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
+import java.util.List;
+
 @Slf4j
 @Getter
-@Setter
 @Component
 @RequiredArgsConstructor
 public class AipFileRepository {
 
+    private final AppRepository repo;
+    private AipFileManager manager;
+
+    public boolean initialize() {
+        this.manager = new AipFileManager(this.repo.getSettings().getConfig());
+        if (!this.manager.initialize()) {
+            log.error("AipFileManager.initialize Failed, {}, {}", this.manager.getLastErrNo(), this.manager.getLastErrMsg());
+            return false;
+        }
+        if (!this.manager.createProfile()) {
+            log.error("AipFileManager.createProfile Failed, {}, {}", this.manager.getLastErrNo(), this.manager.getLastErrMsg());
+            return false;
+        }
+        if (!this.manager.createEngine()) {
+            log.error("AipFileManager.createEngine Failed, {}, {}", this.manager.getLastErrNo(), this.manager.getLastErrMsg());
+            return false;
+        }
+        log.info("AipFileManager Initialize And Create Success.");
+
+        List<AipLabel> labels = this.manager.sensitivityLabels();
+        log.info("{}", labels);
+        List<AipLabel> policies = this.manager.listSensitivityLabels();
+        log.info("{}", policies);
+        List<AipTemplate> templates = this.manager.getTemplates();
+        log.info("{}", templates);
 
+        return true;
+    }
 }

+ 5 - 0
src/main/java/com/aip/gateway/api/repository/AppRepository.java

@@ -3,6 +3,7 @@ package com.aip.gateway.api.repository;
 import com.aip.gateway.api.dto.LinkedApiKeyDto;
 import com.aip.gateway.api.dto.LinkedDecryptKeyDto;
 import com.aip.gateway.api.model.app.AipSettings;
+import com.aip.gateway.api.aip.utils.AipFileUtils;
 import lombok.Getter;
 import lombok.RequiredArgsConstructor;
 import lombok.Setter;
@@ -44,4 +45,8 @@ public class AppRepository {
         return 0;   // KEY OK
     }
 
+    public String getSupportedFileType(String fileName) {
+        String fileExt = AipFileUtils.getExtension(fileName);
+        return supportedFileExtMap.get(fileExt);
+    }
 }

+ 91 - 0
src/main/java/com/aip/gateway/api/repository/GlobalConstants.java

@@ -0,0 +1,91 @@
+package com.aip.gateway.api.repository;
+
+import com.aip.gateway.api.model.request.RequestBase;
+import jakarta.servlet.http.HttpServletRequest;
+
+import java.util.UUID;
+
+public class GlobalConstants {
+
+    public static final String API_ENDPOINT = "/aip-api";
+
+    public static final String API_IP_ADDRESS = "api-ip-address";
+    public static final String API_START_TM = "api-start-tm";
+    public static final String API_START_MILLISECONDS = "api-start-milliseconds";
+    public static final String API_GUID = "api-guid";
+    public static final String API_ID = "api-id";
+    public static final String API_KEY = "api-key";
+    public static final String API_RESULT_CODE = "api-result-code";
+    public static final String API_RESULT_MESSAGE = "api-result-message";
+    public static final String API_REQUEST = "api-request";
+    public static final String API_RESULT = "api-result";
+
+    public static final int API_DB_RELOAD = 1;
+    public static final int API_DB_LINKED_SYSTEMS = 3;
+    public static final int API_DB_LINKED_SERVERS = 4;
+    public static final int API_DB_LINKED_API_KEYS = 5;
+    public static final int API_DB_LINKED_DECRYPT_KEYS = 6;
+
+    public static final int API_AIP_DOWNLOAD = 10;
+    public static final int API_AIP_LABELS = 11;
+    public static final int API_AIP_POLICIES = 12;
+    public static final int API_AIP_PROTECTIONS = 13;
+
+    public static final int API_FILE_INFO = 21;
+    public static final int API_FILE_SET_LABEL = 22;
+    public static final int API_FILE_DELETE_LABEL = 23;
+    public static final int API_FILE_SET_PROTECTION = 24;
+    public static final int API_FILE_DELETE_PROTECTIN = 25;
+    public static final int API_FILE_SET_LABEL_PROTECTION = 26;
+    public static final int API_FILE_DELETE_LABEL_PROTECTION = 27;
+
+    public static final int API_STREAM_INFO = 31;
+    public static final int API_STREAM_SET_LABEL = 32;
+    public static final int API_STREAM_DELETE_LABEL = 33;
+    public static final int API_STREAM_SET_PROTECTION = 34;
+    public static final int API_STREAM_DELETE_PROTECTIN = 35;
+    public static final int API_STREAM_SET_LABEL_PROTECTION = 36;
+    public static final int API_STREAM_DELETE_LABEL_PROTECTION = 37;
+
+    public static final int API_DUMMY = 99;
+
+    public static final int API_FILE_DATA = 13;
+
+    public static final String API_RESULT_SUCCESS = "성공";
+    public static final String API_RESULT_FAIL = "실패";
+    public static final String API_RESULT_ERROR = "오류";
+
+
+    public static String getApiGuid(HttpServletRequest request)
+    {
+        String apiGuid = (String)request.getAttribute(API_GUID);
+        if (apiGuid == null) {
+            apiGuid = UUID.randomUUID().toString();
+            request.setAttribute(API_GUID, apiGuid);
+        }
+        return apiGuid;
+    }
+
+    public static void setAuthorization(HttpServletRequest request, int apiId, String apiKey, RequestBase req) {
+        request.setAttribute(GlobalConstants.API_ID, apiId);
+        request.setAttribute(GlobalConstants.API_KEY, apiKey);
+        if (req != null) {
+            req.setApiGuid(getApiGuid(request));
+        }
+    }
+
+    public static int getApiId(HttpServletRequest request) {
+        Integer apiId = (Integer)request.getAttribute(API_ID);
+        if (apiId == null) {
+            return -1;
+        }
+        return apiId;
+    }
+    public static String getApiKey(HttpServletRequest request) {
+        String apiKey = (String)request.getAttribute(API_KEY);
+        if (apiKey == null) {
+            apiKey = "x";
+        }
+        return apiKey;
+    }
+}

+ 90 - 0
src/main/java/com/aip/gateway/api/security/WebMvcConfig.java

@@ -0,0 +1,90 @@
+package com.aip.gateway.api.security;
+
+import com.aip.gateway.api.interceptor.AipApiControllerInterceptor;
+import com.aip.gateway.api.process.DbmsDataProcess;
+import lombok.AllArgsConstructor;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.*;
+
+@AllArgsConstructor
+@Configuration
+public class WebMvcConfig implements WebMvcConfigurer {
+
+    private final DbmsDataProcess dbmsDataProcess;
+
+    /**
+     * Controller Handler 인터셉서 등록
+     * @param registry
+     */
+    @Override
+    public void addInterceptors(InterceptorRegistry registry) {
+//        registry.addInterceptor(new SessionTimerInterceptor());
+//        registry.addInterceptor(new LoggerInterceptor());
+//        registry.addInterceptor(new UserInterceptor());
+
+        registry.addInterceptor(new AipApiControllerInterceptor(dbmsDataProcess))
+                .addPathPatterns("/v1/aip-api/**")                         // API Controller interceptors
+                .excludePathPatterns(
+                        "/application/facility/**",
+                        "/application/wall/**",
+                        "/application/dashboard/**",
+                        "/facility/**",
+                        "/wall/**",
+                        "/dashboard/**",
+                        "/api/resource/**",
+                        "/api/reload/**",
+                        "/api/test/**",
+                        "/manual/**")    // 해당 경로는 인터셉터가 가로채지 않는다.
+                ;
+    }
+
+    @Override
+    public void addCorsMappings(CorsRegistry registry) {
+        registry.addMapping("/**")                  // 프로그램에서 제공하는 URL
+                //.allowCredentials(true)                         // 쿠키 요청을 허용한다(다른 도메인 서버에 인증하는 경우에만 사용해야하며, true 설정시 보안상 이슈가 발생할 수 있다)
+                //.allowedOriginPatterns("*")
+                .allowedOrigins("*")                            // 허용할 Origin(요청 url) : "*" 의 경우 모두 허용
+//                .allowedHeaders("*")                            // 어떤 헤더들을 허용할 것인지
+                .allowedMethods("GET", "POST", "PUT", "DELETE") // 허용할 request http METHOD : POST, GET, DELETE, PUT
+                //.exposedHeaders("authorization")                // authorization 헤더를 넘기 위해 exposedHeaders 조건을 추가했다.
+                .maxAge(3600)                                   // 브라우저 캐시 시간(단위: 초) : "3600" 이면 최소 1시간 안에는 서버로 재요청 되지 않음
+        ;
+
+        // 스프링 부트에서 CORS 설정 시, .allowCredentials(true) 와 .allowedOrigins("*") 를 동시에 사용할 수 없도록 업데이트 되었음.
+        // .allowedOrigins("*") ==> .allowedOriginPatterns("*") 로 변경하여 해결...
+    }
+
+    @Override
+    public void addViewControllers(ViewControllerRegistry registry) {
+        //registry.addRedirectViewController("/api/auth/login.do", WebConstants.LOGIN_PAGE_URI);
+        //registry.addViewController("/api/auth/login.do").setViewName(WebConstants.LOGIN_PAGE_URI);
+    }
+
+    @Override
+    public void addResourceHandlers(ResourceHandlerRegistry registry) {
+//        registry.addResourceHandler("swagger-ui.html")
+//                .addResourceLocations("classpath:/META-INF/resources/");
+//        registry.addResourceHandler("/webjars/**")
+//                .addResourceLocations("classpath:/META-INF/resources/webjars/");
+
+        String separator = System.getProperty("file.separator");
+        String mapDataDir = System.getProperty("user.dir")+separator+"MAPDATA/";
+        String downloadDir = System.getProperty("user.dir")+separator+"download/";
+        registry.addResourceHandler("/MAPDATA/**")
+                .addResourceLocations("file:///" + mapDataDir)
+        //.setCachePeriod(60) // seconds
+        ;
+        registry.addResourceHandler("/download/**")
+                .addResourceLocations("file:///" + downloadDir)
+        //.setCachePeriod(60) // seconds
+        ;
+    }
+
+    public static String encUserId(String userId) {
+        return userId;
+    }
+    public static String decUserId(Object encUserId) {
+        String decUserId = (String)encUserId;
+        return decUserId;
+    }
+}

+ 81 - 0
src/main/java/com/aip/gateway/api/service/impl/AbstractAipService.java

@@ -0,0 +1,81 @@
+package com.aip.gateway.api.service.impl;
+
+import com.aip.gateway.api.aip.model.AipFileInfo;
+import com.aip.gateway.api.model.response.ResponseInfo;
+import com.aip.gateway.api.repository.AipFileRepository;
+import com.aip.gateway.api.repository.AppRepository;
+import com.aip.gateway.api.aip.utils.AipFileUtils;
+import com.aip.gateway.api.utils.TimeUtils;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.Date;
+
+@Slf4j
+@RequiredArgsConstructor
+abstract class AbstractAipService {
+
+    protected final AppRepository repo;
+    protected final AipFileRepository aipFile;
+
+    protected String getRequestFileName(String realFileName) {
+        return this.repo.getSettings().getSourceFileDir() + realFileName;
+    }
+    protected String getActualFileName(String fileName) {
+        return this.repo.getSettings().getTargetFileDir() + fileName;
+    }
+
+    protected String getSupportedFileType(String reqFileName) {
+        return this.repo.getSupportedFileType(reqFileName);
+    }
+
+    protected ResponseInfo responseGetFileInfo(AipFileInfo fileInfo, String displayFileName) {
+        boolean isLabled = false;
+        boolean isProtected = false;
+        Date creationTime = TimeUtils.getCurrentDate();
+        String contentId  = "";
+        String owner = "";
+        String labelId  = "";
+        String labelName  = "";
+        String templateId  = "";
+        String templateName  = "";
+        long fileSize = 0;
+        if (fileInfo != null) {
+            fileSize = fileInfo.getFileSize();
+            if (fileInfo.getContent() != null) {
+                creationTime = fileInfo.getContent().getCreationTime();
+            }
+            if (fileInfo.getLabel() != null) {
+                isLabled = true;
+                labelId = fileInfo.getLabel().getId();
+                labelName = fileInfo.getLabel().getName();
+            }
+            if (fileInfo.getProtection() != null) {
+                owner = fileInfo.getProtection().getOwner();
+                contentId = fileInfo.getProtection().getContentId();
+                if (fileInfo.getProtection().getProtectionDescriptor() != null) {
+                    isProtected = true;
+                    templateId = fileInfo.getProtection().getProtectionDescriptor().getTemplateId();
+                    templateName = fileInfo.getProtection().getProtectionDescriptor().getName();
+                }
+            }
+        }
+        ResponseInfo result = new ResponseInfo(0, "success");
+        result.setLabeled(isLabled);
+        result.setProtected(isProtected);
+        result.setCreationTime(creationTime);
+        result.setContentId(contentId);
+        result.setOwner(owner);
+        result.setLabelId(labelId);
+        result.setLabelName(labelName);
+        result.setTemplateId(templateId);
+        result.setTemplateName(templateName);
+        result.setDispFileName(displayFileName);
+        result.setFileLabelGuid(labelId);
+        result.setFileProtectionGuid(templateId);
+        result.setFileOwner(owner);
+        result.setFileExt(AipFileUtils.getExtension(displayFileName));
+        result.setFileSize(fileSize);
+        return result;
+    }
+}

+ 22 - 4
src/main/java/com/aip/gateway/api/service/impl/ApiFileService.java

@@ -6,19 +6,37 @@ import com.aip.gateway.api.model.request.RequestFileDel;
 import com.aip.gateway.api.model.request.RequestFileSet;
 import com.aip.gateway.api.model.response.ResponseFile;
 import com.aip.gateway.api.model.response.ResponseInfo;
+import com.aip.gateway.api.repository.AipFileRepository;
+import com.aip.gateway.api.repository.AppRepository;
 import com.aip.gateway.api.service.IApiFileService;
-import lombok.RequiredArgsConstructor;
+import com.aip.gateway.api.aip.utils.AipFileUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
 @Slf4j
-@RequiredArgsConstructor
 @Service
-public class ApiFileService implements IApiFileService {
+public class ApiFileService extends AbstractAipService implements IApiFileService {
+
+    public ApiFileService(AppRepository repo, AipFileRepository aipFile) {
+        super(repo, aipFile);
+    }
 
     @Override
     public ResponseInfo getInfo(RequestFile req) {
-        return null;
+        try {
+            String reqFileName = getRequestFileName(req.getRealFileName());
+            if (!AipFileUtils.isExists(reqFileName)) {
+                return new ResponseInfo(101, "파일이 존재하지 않습니다.");
+            }
+            String newFileExt = getSupportedFileType(reqFileName);
+            if (newFileExt == null) {
+                return new ResponseInfo(102, "지원하지 않는 파일형식 입니다.");
+            }
+            return responseGetFileInfo(this.aipFile.getManager().getFileInfo(reqFileName), req.getDispFileName());
+        }
+        catch (Exception e) {
+            return new ResponseInfo(109, "작업 중에 시스템 오류가 발생했습니다.");
+        }
     }
 
     @Override

+ 30 - 4
src/main/java/com/aip/gateway/api/service/impl/ApiStreamService.java

@@ -1,24 +1,50 @@
 package com.aip.gateway.api.service.impl;
 
+import com.aip.gateway.api.aip.utils.AipFileStream;
+import com.aip.gateway.api.aip.utils.AipFileUtils;
 import com.aip.gateway.api.model.request.RequestStream;
 import com.aip.gateway.api.model.request.RequestStreamAllSet;
 import com.aip.gateway.api.model.request.RequestStreamDel;
 import com.aip.gateway.api.model.request.RequestStreamSet;
 import com.aip.gateway.api.model.response.ResponseInfo;
 import com.aip.gateway.api.model.response.ResponseStream;
+import com.aip.gateway.api.repository.AipFileRepository;
+import com.aip.gateway.api.repository.AppRepository;
 import com.aip.gateway.api.service.IApiStreamService;
-import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
 
+import java.util.Base64;
+
 @Slf4j
-@RequiredArgsConstructor
 @Service
-public class ApiStreamService implements IApiStreamService {
+public class ApiStreamService extends AbstractAipService implements IApiStreamService {
+
+    public ApiStreamService(AppRepository repo, AipFileRepository aipFile) {
+        super(repo, aipFile);
+    }
 
     @Override
     public ResponseInfo getInfo(RequestStream req) {
-        return null;
+        try {
+            String tempOrgFileName = getRequestFileName(AipFileUtils.getFileNameWithoutExtension(req.getDispFileName()) + AipFileUtils.getExtension(req.getDispFileName()));
+            String actualFileName = getActualFileName(req.getApiGuid() + AipFileUtils.getExtension(req.getDispFileName()));
+            String newFileExt = getSupportedFileType(req.getDispFileName());
+            if (newFileExt == null) {
+                return new ResponseInfo(102, "지원하지 않는 파일형식 입니다.");
+            }
+            log.error("{}", tempOrgFileName);
+            log.error("{}", actualFileName);
+
+            byte[] fileDataArr = Base64.getDecoder().decode(req.getFileData());
+            AipFileUtils.streamToFile(fileDataArr, tempOrgFileName);
+
+            AipFileStream fileStream = new AipFileStream(req.getFileData());
+            return responseGetFileInfo(this.aipFile.getManager().getFileInfo(fileStream, actualFileName), req.getDispFileName());
+        }
+        catch (Exception e) {
+            return new ResponseInfo(109, "작업 중에 시스템 오류가 발생했습니다.");
+        }
     }
 
     @Override

+ 12 - 7
src/test/java/com/aip/gateway/api/AipGatewayApiApplicationTests.java

@@ -4,6 +4,7 @@ import com.aip.gateway.api.aip.manager.AipFileManager;
 import com.aip.gateway.api.aip.model.AipConfig;
 import com.aip.gateway.api.aip.model.AipLabel;
 import com.aip.gateway.api.aip.model.AipTemplate;
+import com.aip.gateway.api.aip.utils.AipFileUtils;
 import com.aip.gateway.api.aip.utils.MemoryTokenCacheWithEviction;
 import com.google.common.base.Stopwatch;
 import com.microsoft.aad.msal4j.ClientCredentialFactory;
@@ -39,6 +40,13 @@ class AipGatewayApiApplicationTests {
 
 	private ConfidentialClientApplication app;
 
+	@Test
+	void test2() {
+		String fileName = "c:\\data\\SSL\\mip\\mip_gateway.pfx";
+		String ext = AipFileUtils.getExtension(fileName);
+		String name = AipFileUtils.getFileName(fileName);
+		log.error("[{}] , [{}] [{}] [{}]", fileName, ext, name, AipFileUtils.getFileNameWithoutExtension(fileName));
+	}
 	@Test
 	void jasypt() {
 		String encKey = "asdkjfaslkjflkajslfjkajlkf";
@@ -75,18 +83,15 @@ class AipGatewayApiApplicationTests {
 
 	boolean AipFileInitialize(AipConfig aipConfig) {
 		AipFileManager aipFileManager = new AipFileManager(aipConfig);
-		if (!aipFileManager.initialize())
-		{
+		if (!aipFileManager.initialize()) {
 			log.error("AipFileManager.initialize Failed, {}, {}", aipFileManager.getLastErrNo(), aipFileManager.getLastErrMsg());
 			return false;
 		}
-		if (!aipFileManager.createProfile())
-		{
+		if (!aipFileManager.createProfile()) {
 			log.error("AipFileManager.createProfile Failed, {}, {}", aipFileManager.getLastErrNo(), aipFileManager.getLastErrMsg());
 			return false;
 		}
-		if (!aipFileManager.createEngine())
-		{
+		if (!aipFileManager.createEngine()) {
 			log.error("AipFileManager.createEngine Failed, {}, {}", aipFileManager.getLastErrNo(), aipFileManager.getLastErrMsg());
 			return false;
 		}
@@ -109,7 +114,7 @@ class AipGatewayApiApplicationTests {
 				.clientId("0e225915-3be3-419c-aa04-284d7de5e16b")
 				.tenantId("2e58414a-c6ae-43ff-aaf5-45ab8b78a404")
 				.mipData("App_Data\\\\mip_data")
-				.loginType(AipConfig.authLoginPassword)
+				.loginType(AipConfig.authLoginCert)
 				.domain("AIP.Gateway")
 				.eMail("seungho@ms365.hanteinfo.com")
 				.secretValue("CvW8Q~0iANtLN1Y2EXR_nVyYb_tQTDwjW-Z7Ndg3")

Some files were not shown because too many files changed in this diff