用于安全时间戳的露天自定义操作 - 使用BouncyCastle

时间:2015-07-09 00:37:33

标签: java maven alfresco bouncycastle

我是开发露天的新手,所以这是我的问题。我正在开发露天的自定义动作,其目标是创建一个独立的文档安全时间戳。 这是我的代码:

    String tsaUrl = "http://ts.cartaodecidadao.pt/tsa/server";
    OutputStream out = null;
    HttpURLConnection con = null;
    MessageDigest hash;
    InputStream is = null;
    try{
        hash = MessageDigest.getInstance("SHA1");
        try{
           is = new BufferedInputStream(new FileInputStream(file));
           final byte[] buffer = new byte[1024];
           for (int i = 0; is.read(buffer) != -1;){
                hash.update(buffer, 0, i);
           }
         } catch (FileNotFoundException e){
                e.printStackTrace();
            }                
            TimeStampRequestGenerator timeStampRequestGenerator = new TimeStampRequestGenerator();

            /*FIXME */
            ASN1ObjectIdentifier algorithm = TSPAlgorithms.SHA1;
            TimeStampRequest timeStampRequest = timeStampRequestGenerator.generate(algorithm, hash.digest());
            byte request[] = timeStampRequest.getEncoded();

            URL url = new URL(tsaUrl);
            con = (HttpURLConnection) url.openConnection();
            con.setDoOutput(true);
            con.setDoInput(true);
            con.setRequestMethod("POST");
            con.setRequestProperty("Content-type",
                    "application/timestamp-query");
            con.setRequestProperty("Content-length",
                    String.valueOf(request.length));
            out = con.getOutputStream();
            out.write(request);
            out.flush();
            out.close();

            if (con.getResponseCode() != HttpURLConnection.HTTP_OK)
            {
                System.out.println("---------- != HttpURLConnection.HTTP_OK");
                throw new IOException("Received HTTP error: "
                        + con.getResponseCode() + " - "
                        + con.getResponseMessage());
            }

            InputStream in = con.getInputStream();
            TimeStampResp resp = TimeStampResp
                    .getInstance(new ASN1InputStream(in).readObject());
            TimeStampResponse response = new TimeStampResponse(resp);

它构建成功但是在尝试操作时,它会在注释“FIXME”之后的行引发错误。错误的堆栈跟踪是

2015-07-09 00:58:32,598  ERROR [extensions.webscripts.AbstractRuntime] [http-bio-8080-exec-8] Exception from executeScript - redirecting to status template error: 06090002 Wrapped Exception (with status template): 06090015 The action failed to execute due to an error.
org.springframework.extensions.webscripts.WebScriptException: 06090002 Wrapped Exception (with status template): 06090015 The action failed to execute due to an error.
    at org.springframework.extensions.webscripts.AbstractWebScript.createStatusException(AbstractWebScript.java:1126)
    at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:171)
    at org.alfresco.repo.web.scripts.RepositoryContainer$3.execute(RepositoryContainer.java:470)
    at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:454)
    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecute(RepositoryContainer.java:532)
    at org.alfresco.repo.web.scripts.RepositoryContainer.transactionedExecuteAs(RepositoryContainer.java:600)
    at org.alfresco.repo.web.scripts.RepositoryContainer.executeScriptInternal(RepositoryContainer.java:380)
    at org.alfresco.repo.web.scripts.RepositoryContainer.executeScript(RepositoryContainer.java:261)
    at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:378)
    at org.springframework.extensions.webscripts.AbstractRuntime.executeScript(AbstractRuntime.java:209)
    at org.springframework.extensions.webscripts.servlet.WebScriptServlet.service(WebScriptServlet.java:132)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.alfresco.service.cmr.action.ActionServiceException: 06090015 The action failed to execute due to an error.
    at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:816)
    at org.alfresco.repo.action.ActionServiceImpl.executeAction(ActionServiceImpl.java:573)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:34)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.alfresco.repo.security.permissions.impl.ExceptionTranslatorMethodInterceptor.invoke(ExceptionTranslatorMethodInterceptor.java:46)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.alfresco.repo.audit.AuditMethodInterceptor.invoke(AuditMethodInterceptor.java:159)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
    at com.sun.proxy.$Proxy53.executeAction(Unknown Source)
    at org.alfresco.repo.web.scripts.rule.ActionQueuePost.executeImpl(ActionQueuePost.java:85)
    at org.springframework.extensions.webscripts.DeclarativeWebScript.execute(DeclarativeWebScript.java:64)
    ... 32 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.bouncycastle.tsp.TSPAlgorithms
    at pt.ubi.release.SecureTimeStamp_repo.action.StampAction.executeImpl(StampAction.java:233)
    at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:265)
    at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:839)
    at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:739)

有没有人知道为什么它说无法初始化类org.bouncycastle.tsp.TSPAlgorithms?顺便说一下,我正在使用1.52版的bouncycastle库。 抱歉我的英语,但这不是我的母语。

1 个答案:

答案 0 :(得分:1)

NoClassDefFoundError 表示负责动态加载类的类加载器无法找到您尝试使用的类的.class文件。因此,可能jar不会添加到类 org.bouncycastle.tsp.TSPAlgorithms的类路径

如果您尝试在Alfresco中运行此操作,则可能需要在alfresco / Web-INF / lib中添加该bouncycastle jar。