• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java AccessPermission类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.pdfbox.pdmodel.encryption.AccessPermission的典型用法代码示例。如果您正苦于以下问题:Java AccessPermission类的具体用法?Java AccessPermission怎么用?Java AccessPermission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



AccessPermission类属于org.apache.pdfbox.pdmodel.encryption包,在下文中一共展示了AccessPermission类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: protect

import org.apache.pdfbox.pdmodel.encryption.AccessPermission; //导入依赖的package包/类
@Override
public void protect(final String inputUri, final String outputUri, final String password)
		throws IOException, BadSecurityHandlerException, COSVisitorException {

	if (StringUtils.isNotBlank(inputUri) && StringUtils.isNotBlank(outputUri)
			&& StringUtils.isNotBlank(password)) {

		final PDDocument doc = PDDocument.load(inputUri);

		final StandardProtectionPolicy pp = new StandardProtectionPolicy(password, password,
				new AccessPermission());
		doc.protect(pp);

		doc.save(outputUri);

		doc.close();

	} else {
		throw new IllegalArgumentException(Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE);
	}
}
 
开发者ID:alexpernas,项目名称:PDFGal,代码行数:22,代码来源:PDFGalImpl.java


示例2: unProtect

import org.apache.pdfbox.pdmodel.encryption.AccessPermission; //导入依赖的package包/类
@Override
public void unProtect(final String inputUri, final String outputUri, final String password)
		throws IOException, COSVisitorException, BadSecurityHandlerException,
		CryptographyException {

	if (StringUtils.isNotBlank(inputUri) && StringUtils.isNotBlank(outputUri)
			&& StringUtils.isNotBlank(password)) {

		final PDDocument doc = PDDocument.load(inputUri);

		final DecryptionMaterial decryptionMaterial = new StandardDecryptionMaterial(password);
		doc.openProtection(decryptionMaterial);

		final StandardProtectionPolicy pp = new StandardProtectionPolicy(null, null,
				new AccessPermission());
		doc.protect(pp);

		doc.save(outputUri);

		doc.close();

	} else {
		throw new IllegalArgumentException(Constants.ILLEGAL_ARGUMENT_EXCEPTION_MESSAGE);
	}
}
 
开发者ID:alexpernas,项目名称:PDFGal,代码行数:26,代码来源:PDFGalImpl.java


示例3: init

import org.apache.pdfbox.pdmodel.encryption.AccessPermission; //导入依赖的package包/类
@Override
public void init(RunConfig config) throws InvalidTestFormatException {
	super.init(config);
	File file = new File(GR.getGoldenDir(), goldenFileName);
	try {
		in = new ByteArrayInputStream(MTTestResourceManager.goldenFileToByteArray(file.getPath()));
		out = new ByteArrayOutputStream();
		AccessPermission ap = new AccessPermission();
		policy = new StandardProtectionPolicy(ownerPass, userPass, ap);
	} catch (IOException e) {
		throw new InvalidTestFormatException ("file not found " + e.getMessage() + " " + file.getAbsolutePath(), this.getClass());
	}
}
 
开发者ID:android-workloads,项目名称:JACWfA,代码行数:14,代码来源:Encryption.java


示例4: testPdfCreationWithEncryption

import org.apache.pdfbox.pdmodel.encryption.AccessPermission; //导入依赖的package包/类
@Test
public void testPdfCreationWithEncryption() throws Exception {
    final String ownerPass = "ownerPass";
    final String userPass = "userPass";
    final String expectedText = "expectedText";
    AccessPermission accessPermission = new AccessPermission();
    accessPermission.setCanPrint(false);
    StandardProtectionPolicy protectionPolicy = new StandardProtectionPolicy(ownerPass, userPass, accessPermission);
    protectionPolicy.setEncryptionKeyLength(128);
    template.sendBodyAndHeader("direct:start",
            expectedText,
            PdfHeaderConstants.PROTECTION_POLICY_HEADER_NAME,
            protectionPolicy);

    resultEndpoint.setExpectedMessageCount(1);
    resultEndpoint.expectedMessagesMatches(new Predicate() {
        @Override
        public boolean matches(Exchange exchange) {
            Object body = exchange.getIn().getBody();
            assertThat(body, instanceOf(ByteArrayOutputStream.class));
            try {
                PDDocument doc = PDDocument.load(new ByteArrayInputStream(((ByteArrayOutputStream) body).toByteArray()));
                assertTrue("Expected encrypted document", doc.isEncrypted());
                doc.decrypt(userPass);
                assertFalse("Printing should not be permitted", doc.getCurrentAccessPermission().canPrint());
                PDFTextStripper pdfTextStripper = new PDFTextStripper();
                String text = pdfTextStripper.getText(doc);
                assertEquals(1, doc.getNumberOfPages());
                assertThat(text, containsString(expectedText));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            return true;
        }
    });
    resultEndpoint.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:38,代码来源:PdfCreationTest.java


示例5: generate

import org.apache.pdfbox.pdmodel.encryption.AccessPermission; //导入依赖的package包/类
@Override
public ByteArrayOutputStream generate( Invoice invoice ) throws IOException
{
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    Resource resource = resourceLoader.getResource( templateLocation );

    try ( PDDocument pdfDocument = PDDocument.load( resource.getInputStream() ) )
    {
        PDDocumentCatalog docCatalog = pdfDocument.getDocumentCatalog();
        PDAcroForm acroForm = docCatalog.getAcroForm();
        acroForm.setCacheFields( true );

        setFields( invoice, acroForm );
        acroForm.getFieldIterator().forEachRemaining( pdField -> pdField.setReadOnly( true ) );

        AccessPermission ap = new AccessPermission();
        ap.setCanModify( false );
        ap.setReadOnly();
        StandardProtectionPolicy spp = new StandardProtectionPolicy( UUID.randomUUID().toString(), "", ap );
        spp.setEncryptionKeyLength( 128 );
        pdfDocument.protect( spp );

        pdfDocument.save( out );
    }

    return out;
}
 
开发者ID:ClouDesire,项目名称:janine,代码行数:29,代码来源:PdfServiceImpl.java


示例6: testExtractTextFromEncrypted

import org.apache.pdfbox.pdmodel.encryption.AccessPermission; //导入依赖的package包/类
@Test
public void testExtractTextFromEncrypted() throws Exception {
    final String ownerPass = "ownerPass";
    final String userPass = "userPass";
    AccessPermission accessPermission = new AccessPermission();
    accessPermission.setCanExtractContent(false);
    StandardProtectionPolicy protectionPolicy = new StandardProtectionPolicy(ownerPass, userPass, accessPermission);
    protectionPolicy.setEncryptionKeyLength(128);
    PDDocument document = new PDDocument();

    final String expectedText = "Test string";
    PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
    document.addPage(page);
    PDPageContentStream contentStream = new PDPageContentStream(document, page);
    contentStream.setFont(PDType1Font.HELVETICA, 12);
    contentStream.beginText();
    contentStream.moveTextPositionByAmount(20, 400);
    contentStream.drawString(expectedText);
    contentStream.endText();
    contentStream.close();

    document.protect(protectionPolicy);

    ByteArrayOutputStream output = new ByteArrayOutputStream();
    document.save(output);

    // Encryption happens after saving.
    PDDocument encryptedDocument = PDDocument.load(new ByteArrayInputStream(output.toByteArray()));

    template.sendBodyAndHeader("direct:start",
            encryptedDocument,
            PdfHeaderConstants.DECRYPTION_MATERIAL_HEADER_NAME,
            new StandardDecryptionMaterial(userPass));

    resultEndpoint.setExpectedMessageCount(1);
    resultEndpoint.expectedMessagesMatches(new Predicate() {
        @Override
        public boolean matches(Exchange exchange) {
            Object body = exchange.getIn().getBody();
            assertThat(body, instanceOf(String.class));
            assertThat((String) body, containsString(expectedText));
            return true;
        }
    });
    resultEndpoint.assertIsSatisfied();
    document.isEncrypted();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:48,代码来源:PdfTextExtractionTest.java


示例7: testAppendEncrypted

import org.apache.pdfbox.pdmodel.encryption.AccessPermission; //导入依赖的package包/类
@Test
public void testAppendEncrypted() throws Exception {
    final String originalText = "Test";
    final String textToAppend = "Append";
    PDDocument document = new PDDocument();
    PDPage page = new PDPage(PDPage.PAGE_SIZE_A4);
    document.addPage(page);
    PDPageContentStream contentStream = new PDPageContentStream(document, page);
    contentStream.setFont(PDType1Font.HELVETICA, 12);
    contentStream.beginText();
    contentStream.moveTextPositionByAmount(20, 400);
    contentStream.drawString(originalText);
    contentStream.endText();
    contentStream.close();

    final String ownerPass = "ownerPass";
    final String userPass = "userPass";
    AccessPermission accessPermission = new AccessPermission();
    accessPermission.setCanExtractContent(false);
    StandardProtectionPolicy protectionPolicy = new StandardProtectionPolicy(ownerPass, userPass, accessPermission);
    protectionPolicy.setEncryptionKeyLength(128);

    document.protect(protectionPolicy);

    ByteArrayOutputStream output = new ByteArrayOutputStream();
    document.save(output);

    // Encryption happens after saving.
    PDDocument encryptedDocument = PDDocument.load(new ByteArrayInputStream(output.toByteArray()));

    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put(PdfHeaderConstants.PDF_DOCUMENT_HEADER_NAME, encryptedDocument);
    headers.put(PdfHeaderConstants.DECRYPTION_MATERIAL_HEADER_NAME, new StandardDecryptionMaterial(userPass));

    template.sendBodyAndHeaders("direct:start", textToAppend, headers);

    resultEndpoint.setExpectedMessageCount(1);
    resultEndpoint.expectedMessagesMatches(new Predicate() {
        @Override
        public boolean matches(Exchange exchange) {
            Object body = exchange.getIn().getBody();
            assertThat(body, instanceOf(ByteArrayOutputStream.class));
            try {
                PDDocument doc = PDDocument.load(new ByteArrayInputStream(((ByteArrayOutputStream) body).toByteArray()));
                PDFTextStripper pdfTextStripper = new PDFTextStripper();
                String text = pdfTextStripper.getText(doc);
                assertEquals(2, doc.getNumberOfPages());
                assertThat(text, containsString(originalText));
                assertThat(text, containsString(textToAppend));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            return true;
        }
    });
    resultEndpoint.assertIsSatisfied();

}
 
开发者ID:HydAu,项目名称:Camel,代码行数:59,代码来源:PdfAppendTest.java


示例8: hasDRMGranular

import org.apache.pdfbox.pdmodel.encryption.AccessPermission; //导入依赖的package包/类
/**
	 * Check for encryption with Apache PDFBox
	 * -> query the encryption dictionary (might allow more granular checks of protection)
	 * @param pPDF pdf file to check
	 * @return whether or not the file has DRM
	 */
	public static boolean hasDRMGranular(File pPDF) {

		boolean ret = false;

		try {
			System.setProperty("org.apache.pdfbox.baseParser.pushBackSize", "1024768");
			// NOTE: we use loadNonSeq here as it is the latest parser
			// load() and parser.parse() have hung on test files
			File tmp = File.createTempFile("flint-", ".tmp");
			tmp.deleteOnExit();
			RandomAccess scratchFile = new RandomAccessFile(tmp, "rw");
			PDDocument doc = PDDocument.loadNonSeq(new FileInputStream(pPDF), scratchFile);

			PDEncryptionDictionary dict = doc.getEncryptionDictionary();
			if(dict!=null) {

				//print encryption dictionary
//				for(COSName key:dict.keySet()) {
//					System.out.print(key.getName());
//					String value = dict.getString(key);
//					if(value!=null){
//						System.out.println(": "+value);
//					} else {
//						System.out.println(": "+dict.getLong(key));
//					}
//				}

				//this feaure in pdfbox is currently broken, see: https://issues.apache.org/jira/browse/PDFBOX-1651
				//AccessPermission perms = parser.getPDDocument().getCurrentAccessPermission();
				//this is a work around; creating a new object from the data
				AccessPermission perms = new AccessPermission(dict.getPermissions());//.getInt("P"));

				boolean debug = true;

				if(debug) {

					System.out.println("canAssembleDocument()        : "+perms.canAssembleDocument());
					System.out.println("canExtractContent()          : "+perms.canExtractContent());
					System.out.println("canExtractForAccessibility() : "+perms.canExtractForAccessibility());
					System.out.println("canFillInForm()              : "+perms.canFillInForm());
					System.out.println("canModify()                  : "+perms.canModify());
					System.out.println("canModifyAnnotations()       : "+perms.canModifyAnnotations());
					System.out.println("canPrint()                   : "+perms.canPrint());
					System.out.println("canPrintDegraded()           : "+perms.canPrintDegraded());
					System.out.println("isOwnerPermission()          : "+perms.isOwnerPermission());
					System.out.println("isReadOnly()                 : "+perms.isReadOnly());

				}
			}

			doc.close();

		} catch (Exception e) {
           LOGGER.warn("Exception while doing granular DRM checks leads to invalidity: {}", e);
		}

		return ret;
	}
 
开发者ID:openpreserve,项目名称:flint,代码行数:65,代码来源:PDFBoxWrapper.java


示例9: getCurrentAccessPermission

import org.apache.pdfbox.pdmodel.encryption.AccessPermission; //导入依赖的package包/类
/**
 * {@inheritDoc}
 * @return 
 */
public final AccessPermission getCurrentAccessPermission() {
	return document.getCurrentAccessPermission();
}
 
开发者ID:juliusHuelsmann,项目名称:paint,代码行数:8,代码来源:XDocument.java



注:本文中的org.apache.pdfbox.pdmodel.encryption.AccessPermission类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AttributeValue类代码示例发布时间:2022-05-22
下一篇:
Java MockMvcRestDocumentation类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap