|
@@ -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;
|
|
|
}
|
|
|
|