diff options
author | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-10-09 13:40:38 +0200 |
---|---|---|
committer | Andreas Fitzek <andreas.fitzek@iaik.tugraz.at> | 2014-10-09 13:40:38 +0200 |
commit | 1c8feb0dd0ee0cf74e60d93853e6f5d57b034bee (patch) | |
tree | 90cbd22aee1b053fcde6ada9725be26a75cde31a /pdf-as-web/src/main/java/at | |
parent | 11dd7f9d647b1ac8af91dc8aab82743a74a1cbaf (diff) | |
download | pdf-as-4-1c8feb0dd0ee0cf74e60d93853e6f5d57b034bee.tar.gz pdf-as-4-1c8feb0dd0ee0cf74e60d93853e6f5d57b034bee.tar.bz2 pdf-as-4-1c8feb0dd0ee0cf74e60d93853e6f5d57b034bee.zip |
WebServices with CXF, removed DB dependencies to pdf-as-web-db
Diffstat (limited to 'pdf-as-web/src/main/java/at')
4 files changed, 117 insertions, 221 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SoapServiceServlet.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SoapServiceServlet.java new file mode 100644 index 00000000..71395304 --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/SoapServiceServlet.java @@ -0,0 +1,48 @@ +package at.gv.egiz.pdfas.web.servlets; + +import javax.servlet.ServletConfig; +import javax.xml.ws.Endpoint; + +import org.apache.cxf.Bus; +import org.apache.cxf.BusFactory; +import org.apache.cxf.feature.LoggingFeature; +import org.apache.cxf.interceptor.LoggingInInterceptor; +import org.apache.cxf.interceptor.LoggingOutInterceptor; +import org.apache.cxf.transport.servlet.CXFNonSpringServlet; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import at.gv.egiz.pdfas.web.ws.PDFASSigningImpl; +import at.gv.egiz.pdfas.web.ws.PDFASVerificationImpl; + +public class SoapServiceServlet extends CXFNonSpringServlet { + + private static final Logger logger = LoggerFactory + .getLogger(SoapServiceServlet.class); + + /** + * + */ + private static final long serialVersionUID = -8903883276191902043L; + + @Override + protected void loadBus(ServletConfig sc) { + super.loadBus(sc); + + // You could add the endpoint publish codes here + Bus bus = this.getBus(); + BusFactory.setDefaultBus(bus); + Endpoint signEp = Endpoint.publish("/wssign", new PDFASSigningImpl()); + /* + * SOAPBinding signBinding = (SOAPBinding)signEp.getBinding(); + signBinding.setMTOMEnabled(true); + */ + + Endpoint verifyEp = Endpoint.publish("/wsverify", new PDFASVerificationImpl()); + /* + SOAPBinding verifyBinding = (SOAPBinding)verifyEp.getBinding(); + verifyBinding.setMTOMEnabled(true); + */ + + } +} diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/DBRequestStore.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/DBRequestStore.java deleted file mode 100644 index 6ca6d9a4..00000000 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/DBRequestStore.java +++ /dev/null @@ -1,121 +0,0 @@ -package at.gv.egiz.pdfas.web.store; - -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; - -import org.hibernate.Query; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.Transaction; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.cfg.Configuration; -import org.hibernate.service.ServiceRegistry; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import at.gv.egiz.pdfas.api.ws.PDFASSignRequest; -import at.gv.egiz.pdfas.web.config.WebConfiguration; -import at.gv.egiz.pdfas.web.store.db.Request; - -public class DBRequestStore implements IRequestStore { - - private static final Logger logger = LoggerFactory - .getLogger(DBRequestStore.class); - - private SessionFactory sessions; - private ServiceRegistry serviceRegistry; - - public DBRequestStore() { - Configuration cfg = new Configuration(); - cfg.addAnnotatedClass(Request.class); - cfg.setProperties(WebConfiguration.getHibernateProps()); - - serviceRegistry = new StandardServiceRegistryBuilder().applySettings( - cfg.getProperties()).build(); - - sessions = cfg.buildSessionFactory(serviceRegistry); - } - - private void cleanOldRequests() { - int seconds = WebConfiguration.getDBTimeout(); - Calendar calendar = Calendar.getInstance(); - calendar.add(Calendar.SECOND, (-1)* seconds); - Date date = calendar.getTime(); - SimpleDateFormat dt = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss"); - logger.info("Clearing Entries before: " + dt.format(date)); - Session session = null; - Transaction tx = null; - try { - session = sessions.openSession(); - tx = session.beginTransaction(); - Query query = session.createQuery("delete from Request as req" + - " where req.created < :date"); - query.setCalendar("date", calendar); - query.executeUpdate(); - } catch(Throwable e) { - logger.error("Failed to save Request", e); - tx.rollback(); - } finally { - if(session != null) { - session.close(); - } - } - } - - public String createNewStoreEntry(PDFASSignRequest request) { - // Clean Old Requests - this.cleanOldRequests(); - Session session = null; - Transaction tx = null; - try { - session = sessions.openSession(); - tx = session.beginTransaction(); - Request dbRequest = new Request(); - dbRequest.setSignRequest(request); - dbRequest.setCreated(Calendar.getInstance().getTime()); - session.save(dbRequest); - - tx.commit(); - return dbRequest.getId(); - } catch(Throwable e) { - logger.error("Failed to save Request", e); - tx.rollback(); - return null; - } finally { - if(session != null) { - session.close(); - } - } - } - - public PDFASSignRequest fetchStoreEntry(String id) { - // Clean Old Requests - this.cleanOldRequests(); - - Session session = null; - Transaction tx = null; - try { - session = sessions.openSession(); - tx = session.beginTransaction(); - Request dbRequest = (Request) session.get(Request.class, id); - - PDFASSignRequest request = dbRequest.getSignRequest(); - - session.delete(dbRequest); - - tx.commit(); - return request; - } catch(Throwable e) { - logger.error("Failed to fetch Request", e); - tx.rollback(); - return null; - } finally { - if(session != null) { - session.close(); - } - } - - } - -} diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/db/Request.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/db/Request.java deleted file mode 100644 index d7377166..00000000 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/store/db/Request.java +++ /dev/null @@ -1,52 +0,0 @@ -package at.gv.egiz.pdfas.web.store.db; - -import java.util.Date; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; - -import org.hibernate.annotations.GenericGenerator; - -import at.gv.egiz.pdfas.api.ws.PDFASSignRequest; - -@Entity -@Table(name = "requests") -public class Request { - - private String uuid; - private Date created; - private PDFASSignRequest signRequest; - - @Id - @GeneratedValue(generator = "uuid") - @GenericGenerator(name = "uuid", strategy = "uuid2") - @Column(name = "id", unique = true) - public String getId() { - return this.uuid; - } - - public void setId(String uuid) { - this.uuid = uuid; - } - - @Column(name = "created", nullable = false) - public Date getCreated() { - return this.created; - } - - public void setCreated(Date created) { - this.created = created; - } - - @Column(name = "signRequest", nullable = false, length = 52428800) - public PDFASSignRequest getSignRequest() { - return this.signRequest; - } - - public void setSignRequest(PDFASSignRequest signRequest) { - this.signRequest = signRequest; - } -} diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java index 02c1af5e..6df63a3b 100644 --- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/ws/PDFASSigningImpl.java @@ -53,91 +53,110 @@ public class PDFASSigningImpl implements PDFASSigning { private static final Logger logger = LoggerFactory .getLogger(PDFASSigningImpl.class); - - /*public byte[] signPDFDokument(byte[] inputDocument, - PDFASSignParameters parameters) { - checkSoapSignEnabled(); - try { - return PdfAsHelper.synchornousServerSignature(inputDocument, - parameters); - } catch (Throwable e) { - logger.error("Server Signature failed.", e); - if (WebConfiguration.isShowErrorDetails()) { - throw new WebServiceException("Server Signature failed.", e); - } else { - throw new WebServiceException("Server Signature failed."); - } - } - }*/ + + /* + * public byte[] signPDFDokument(byte[] inputDocument, PDFASSignParameters + * parameters) { checkSoapSignEnabled(); try { return + * PdfAsHelper.synchornousServerSignature(inputDocument, parameters); } + * catch (Throwable e) { logger.error("Server Signature failed.", e); if + * (WebConfiguration.isShowErrorDetails()) { throw new + * WebServiceException("Server Signature failed.", e); } else { throw new + * WebServiceException("Server Signature failed."); } } } + */ public PDFASSignResponse signPDFDokument(PDFASSignRequest request) { + logger.debug("Starting SOAP Sign Request"); checkSoapSignEnabled(); if (request == null) { logger.warn("SOAP Sign Request is null!"); return null; } + PDFASSignResponse response = new PDFASSignResponse(); try { - if(request.getParameters().getConnector().equals(Connector.MOA) || - request.getParameters().getConnector().equals(Connector.JKS)) { + if(request.getParameters().getConnector() == null) { + throw new WebServiceException( + "Invalid connector value!"); + } + + if (request.getParameters().getConnector().equals(Connector.MOA) + || request.getParameters().getConnector() + .equals(Connector.JKS)) { // Plain server based signatures!! - response = PdfAsHelper.synchornousServerSignature(request.getInputData(), - request.getParameters()); - - + response = PdfAsHelper.synchornousServerSignature( + request.getInputData(), request.getParameters()); + VerifyResult verifyResult = null; - if(request.getVerificationLevel().equals(VerificationLevel.FULL_CERT_PATH)) { - List<VerifyResult> verResults = PdfAsHelper.synchornousVerify(response.getSignedPDF(), -1, - SignatureVerificationLevel.FULL_VERIFICATION); - - if(verResults.size() != 1) { - throw new WebServiceException("Document verification failed!"); + if (request.getVerificationLevel() != null && + request.getVerificationLevel().equals( + VerificationLevel.FULL_CERT_PATH)) { + List<VerifyResult> verResults = PdfAsHelper + .synchornousVerify( + response.getSignedPDF(), + -1, + SignatureVerificationLevel.FULL_VERIFICATION); + + if (verResults.size() != 1) { + throw new WebServiceException( + "Document verification failed!"); } verifyResult = verResults.get(0); } else { - List<VerifyResult> verResults = PdfAsHelper.synchornousVerify(response.getSignedPDF(), -1, - SignatureVerificationLevel.INTEGRITY_ONLY_VERIFICATION); - - if(verResults.size() != 1) { - throw new WebServiceException("Document verification failed!"); + List<VerifyResult> verResults = PdfAsHelper + .synchornousVerify( + response.getSignedPDF(), + -1, + SignatureVerificationLevel.INTEGRITY_ONLY_VERIFICATION); + + if (verResults.size() != 1) { + throw new WebServiceException( + "Document verification failed!"); } verifyResult = verResults.get(0); } - - response.getVerificationResponse().setCertificateCode(verifyResult.getCertificateCheck().getCode()); - response.getVerificationResponse().setValueCode(verifyResult.getValueCheckCode().getCode()); + + response.getVerificationResponse().setCertificateCode( + verifyResult.getCertificateCheck().getCode()); + response.getVerificationResponse().setValueCode( + verifyResult.getValueCheckCode().getCode()); } else { // Signatures with user interaction!! - String id = RequestStore.getInstance().createNewStoreEntry(request); - - if(id == null) { + String id = RequestStore.getInstance().createNewStoreEntry( + request); + + if (id == null) { throw new WebServiceException("Failed to store request"); } - + String userEntryURL = PdfAsHelper.generateUserEntryURL(id); - + logger.debug("Generated request store: " + id); logger.debug("Generated UI URL: " + userEntryURL); - - if(userEntryURL == null) { - throw new WebServiceException("Failed to generate User Entry URL"); + + if (userEntryURL == null) { + throw new WebServiceException( + "Failed to generate User Entry URL"); } - + response.setRedirectUrl(userEntryURL); } } catch (Throwable e) { + logger.error("Error in Soap Service", e); if (e.getCause() != null) { response.setError(e.getCause().getMessage()); } else { response.setError(e.getMessage()); } + } finally { + logger.debug("Done SOAP Sign Request"); } response.setRequestID(request.getRequestID()); return response; } public PDFASBulkSignResponse signPDFDokument(PDFASBulkSignRequest request) { + logger.debug("Starting SOAP BulkSign Request"); checkSoapSignEnabled(); List<PDFASSignResponse> responses = new ArrayList<PDFASSignResponse>(); if (request.getSignRequests() != null) { @@ -150,9 +169,11 @@ public class PDFASSigningImpl implements PDFASSigning { } PDFASBulkSignResponse response = new PDFASBulkSignResponse(); response.setSignResponses(responses); + logger.debug("Done SOAP Sign Request"); return response; } logger.error("Server Signature failed. [PDFASBulkSignRequest is NULL]"); + if (WebConfiguration.isShowErrorDetails()) { throw new WebServiceException("PDFASBulkSignRequest is NULL"); } else { @@ -161,9 +182,9 @@ public class PDFASSigningImpl implements PDFASSigning { } private void checkSoapSignEnabled() { - if(!WebConfiguration.getSoapSignEnabled()) { + if (!WebConfiguration.getSoapSignEnabled()) { throw new WebServiceException("Service disabled!"); } - } - + } + } |