-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: sign protected pdfs #498
base: main
Are you sure you want to change the base?
Changes from 24 commits
ff84ad3
6d00beb
84a311f
6eed34d
aad94b7
bb7c5a1
acb36d4
11ef8b9
553dd41
9d07e15
83bd4df
e74a283
065f674
56cc58a
2778cb2
f8a4f77
a8770c1
a8a2b5d
cf8473c
ff4eca7
3c03aef
2940dff
762b7b9
72d3337
39279d1
d6660e1
0a38cb2
1a51bca
d936977
6f99e22
a5d5899
7d94479
1cc94b5
6c15d52
e587086
5a1a71e
0df85f7
b846984
eebceae
5266922
c064992
a0a9e42
b69a83b
577cd03
d230231
10bd450
91dd90d
5b6c2a8
9e84caf
5803279
6b0d033
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import digital.slovensko.autogram.core.visualization.DocumentVisualizationBuilder; | ||
import digital.slovensko.autogram.core.visualization.UnsupportedVisualization; | ||
import digital.slovensko.autogram.drivers.TokenDriver; | ||
import digital.slovensko.autogram.model.AutogramDocument; | ||
import digital.slovensko.autogram.ui.BatchUiResult; | ||
import digital.slovensko.autogram.ui.UI; | ||
import digital.slovensko.autogram.util.Logging; | ||
|
@@ -56,22 +57,37 @@ public void checkPDFACompliance(SigningJob job) { | |
return; | ||
|
||
ui.onWorkThreadDo(() -> { | ||
var result = new PDFAStructureValidator().validate(job.getDocument()); | ||
// PDF/A doesn't support encryption | ||
if (job.getDocument().hasOpenDocumentPassword()) { | ||
ui.onUIThreadDo(() -> ui.onPDFAComplianceCheckFailed(job)); | ||
return; | ||
} | ||
|
||
var result = new PDFAStructureValidator().validate(job.getDocument().getDSSDocument()); | ||
if (!result.isCompliant()) { | ||
ui.onUIThreadDo(() -> ui.onPDFAComplianceCheckFailed(job)); | ||
} | ||
}); | ||
} | ||
|
||
public void handleProtectedPdfDocument(AutogramDocument document) { | ||
var protection = PDFUtils.determinePDFProtection(document.getDSSDocument()); | ||
if (protection == PDFUtils.PDFProtection.NONE) | ||
return; | ||
|
||
var password = ui.getDocumentPassword(document.getDSSDocument()); | ||
switch (protection) { | ||
case OPEN_DOCUMENT_PASSWORD -> document.setOpenDocumentPassword(password); | ||
case MASTER_PASSWORD -> document.setMasterPassword(password); | ||
} | ||
} | ||
|
||
public void wrapInWorkThread(Runnable callback) { | ||
ui.onWorkThreadDo(callback); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Toto sa pouziva presne na 1 mieste, cize dajme inline, nijako to nezvysuje prehladnost, skor naopak. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
public void startVisualization(SigningJob job) { | ||
ui.onWorkThreadDo(() -> { | ||
if (PDFUtils.isPdfAndPasswordProtected(job.getDocument())) { | ||
ui.onUIThreadDo(() -> { | ||
ui.showError(new AutogramException("Nastala chyba", "Dokument je chránený heslom", "Snažíte sa podpísať dokument chránený heslom, čo je funkcionalita, ktorá nie je podporovaná.\n\nOdstráňte ochranu heslom a potom budete môcť dokument podpísať.")); | ||
}); | ||
return; | ||
} | ||
|
||
try { | ||
var visualization = DocumentVisualizationBuilder.fromJob(job, settings); | ||
ui.onUIThreadDo(() -> ui.showVisualization(visualization, this)); | ||
|
@@ -159,7 +175,7 @@ public void batchSign(SigningJob job, String batchId) { | |
ui.onWorkThreadDo(() -> { | ||
try { | ||
signCommonAndThen(job, batch.getSigningKey(), (jobNew) -> { | ||
Logging.log("GUI: Signing batch job: " + job.hashCode() + " file " + job.getDocument().getName()); | ||
Logging.log("GUI: Signing batch job: " + job.hashCode() + " file " + job.getDocument().getDSSDocument().getName()); | ||
}); | ||
} catch (AutogramException e) { | ||
job.onDocumentSignFailed(e); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package digital.slovensko.autogram.core.errors; | ||
|
||
public class InvalidPasswordException extends AutogramException { | ||
public InvalidPasswordException(String message) { | ||
super("Nesprávne heslo", "Heslo je nesprávne", message); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ešte uvažujem, či sa neplatí vyrobiť pre tento prípad inú hlášku. Prípadne vedieť do toho
onPDFAComplianceCheckFailed
poslať ešte AutogramException, na základe ktorej sa zobrazí taký alebo onaký text. Totiž, pri tomto hesle má zmysel povedať userovi konkrétne, že nie len že dokument nie je v súlade s PDF/A, ale je to práva preto, že je zaheslovaný.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Urcite ano. Poslime tam
ui.onPDFPasswordProtectedCheck(job)