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 | |
| 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')
8 files changed, 136 insertions, 247 deletions
| diff --git a/pdf-as-web/build.gradle b/pdf-as-web/build.gradle index 64111a3a..d854a365 100644 --- a/pdf-as-web/build.gradle +++ b/pdf-as-web/build.gradle @@ -21,20 +21,13 @@ dependencies {  	compile project (':signature-standards:sigs-pkcs7detached')  	compile project (':signature-standards:sigs-pades')  	compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.1' -    compile 'org.apache.commons:commons-collections4:4.0' -	compile 'commons-io:commons-io:2.4'  	compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.7' +	compile 'org.slf4j:slf4j-log4j12:1.7.7'  	compile group: 'opensymphony', name: 'sitemesh', version: '2.4.2' -	compile 'javax.xml.ws:jaxws-api:2.2.11'  	compile "commons-codec:commons-codec:1.9" -	compile 'com.sun.xml.ws:jaxws-rt:2.2.8' -	compile 'com.sun.xml.bind:jaxb-impl:2.2.7'  	compile 'org.apache.commons:commons-lang3:3.3.2' -	compile 'org.apache.httpcomponents:httpclient:4.3.5' -	compile "org.hibernate:hibernate-core:4.3.6.Final" -	compile "org.hibernate:hibernate-entitymanager:4.3.6.Final" -	//compile "mysql:mysql-connector-java:5.1.33" -	compile group: 'org.apache.pdfbox', name: 'pdfbox', version: '1.8.5' +	compile 'org.apache.cxf:cxf-rt-transports-http:3.0.1' +	compile 'org.apache.cxf:cxf-rt-frontend-jaxws:3.0.1'  	providedCompile "javax.servlet:servlet-api:2.5"      testCompile group: 'junit', name: 'junit', version: '4.+'  } 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!");  		} - 	} -	 +	} +  } diff --git a/pdf-as-web/src/main/webapp/META-INF/cxf/org.apache.cxf.Logger b/pdf-as-web/src/main/webapp/META-INF/cxf/org.apache.cxf.Logger new file mode 100644 index 00000000..067508e1 --- /dev/null +++ b/pdf-as-web/src/main/webapp/META-INF/cxf/org.apache.cxf.Logger @@ -0,0 +1 @@ +org.apache.cxf.common.logging.Slf4jLogger 
\ No newline at end of file diff --git a/pdf-as-web/src/main/webapp/WEB-INF/sun-jaxws.xml b/pdf-as-web/src/main/webapp/WEB-INF/sun-jaxws.xml deleted file mode 100644 index f62b8484..00000000 --- a/pdf-as-web/src/main/webapp/WEB-INF/sun-jaxws.xml +++ /dev/null @@ -1,11 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" -    version="2.0"> -    <endpoint name="SOAP Sign" -        implementation="at.gv.egiz.pdfas.web.ws.PDFASSigningImpl" -        url-pattern="/wssign"/> -     -    <endpoint name="SOAP Verify" -        implementation="at.gv.egiz.pdfas.web.ws.PDFASVerificationImpl" -        url-pattern="/wsverify"/> -</endpoints>
\ No newline at end of file diff --git a/pdf-as-web/src/main/webapp/WEB-INF/web.xml b/pdf-as-web/src/main/webapp/WEB-INF/web.xml index 82d00fdf..f8b886ca 100644 --- a/pdf-as-web/src/main/webapp/WEB-INF/web.xml +++ b/pdf-as-web/src/main/webapp/WEB-INF/web.xml @@ -29,15 +29,15 @@  		<url-pattern>/*</url-pattern>  	</filter-mapping> -	<listener> +	<!-- listener>  	    <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class> -	</listener> +	</listener--> -	<servlet> +	<!-- servlet>  	    <servlet-name>SOAPSign</servlet-name>  	    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class> -	</servlet> +	</servlet-->  	<servlet>  		<servlet-name>SignServlet</servlet-name>  		<description> @@ -47,6 +47,12 @@  		<load-on-startup>0</load-on-startup>  	</servlet>  	<servlet> +		<servlet-name>CXFServlet</servlet-name> +		<display-name>CXFServlet</display-name> +		<description></description> +		<servlet-class>at.gv.egiz.pdfas.web.servlets.SoapServiceServlet</servlet-class> +	</servlet> +	<servlet>  		<servlet-name>ProvidePDF</servlet-name>  		<display-name>ProvidePDF</display-name>  		<description></description> @@ -116,9 +122,13 @@  		servlet mappings, including zero. It is also legal to define more than one   		mapping for the same servlet, if you wish to. --> -	<servlet-mapping> +	<!-- servlet-mapping>  		<servlet-name>SOAPSign</servlet-name>  		<url-pattern>/wssign</url-pattern> +	</servlet-mapping --> +	<servlet-mapping> +		<servlet-name>CXFServlet</servlet-name> +		<url-pattern>/services/*</url-pattern>  	</servlet-mapping>  	<servlet-mapping>  		<servlet-name>SignServlet</servlet-name> | 
