aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java
diff options
context:
space:
mode:
authorknowcenter <knowcenter@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-05-17 15:28:32 +0000
committerknowcenter <knowcenter@7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c>2007-05-17 15:28:32 +0000
commit527484bcc0a65c61d50209849f7b3db34f0128f7 (patch)
tree2fa9ddcbf42f0fae9137444f5950de25a1e53b0a /src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java
parent0184c140614b99a5037cbd8f969b7512888cd37d (diff)
downloadpdf-as-3-527484bcc0a65c61d50209849f7b3db34f0128f7.tar.gz
pdf-as-3-527484bcc0a65c61d50209849f7b3db34f0128f7.tar.bz2
pdf-as-3-527484bcc0a65c61d50209849f7b3db34f0128f7.zip
web
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-as/trunk@87 7b5415b0-85f9-ee4d-85bd-d5d0c3b42d1c
Diffstat (limited to 'src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java')
-rw-r--r--src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java178
1 files changed, 126 insertions, 52 deletions
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java
index e5278b9..220a3d0 100644
--- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java
+++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/DetachedLocRefMOAConnector.java
@@ -4,21 +4,23 @@
package at.knowcenter.wag.egov.egiz.sig.connectors.moa;
import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
+import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
import at.knowcenter.wag.egov.egiz.exceptions.SettingsException;
import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
-import at.knowcenter.wag.egov.egiz.exceptions.WebException;
import at.knowcenter.wag.egov.egiz.sig.SignatureData;
+import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
+import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
import at.knowcenter.wag.egov.egiz.sig.connectors.TemplateReplaces;
import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUHelper;
import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUPostConnection;
import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
+import at.knowcenter.wag.egov.egiz.sig.sigid.DetachedLocRefMOAIdFormatter;
+import at.knowcenter.wag.egov.egiz.tools.DebugHelper;
import at.knowcenter.wag.egov.egiz.tools.FileHelper;
/**
@@ -26,7 +28,7 @@ import at.knowcenter.wag.egov.egiz.tools.FileHelper;
*
* @author wprinz
*/
-public class DetachedLocRefMOAConnector
+public class DetachedLocRefMOAConnector implements Connector
{
/**
* The SIG_ID prefix.
@@ -60,31 +62,19 @@ public class DetachedLocRefMOAConnector
* @throws SignatureException
* f.e.
*/
- public DetachedLocRefMOAConnector(String profile) throws SignatureException, SettingsException
+ public DetachedLocRefMOAConnector(String profile, String signature_data_url) throws SignatureException, SettingsException
{
- this.environment = new Environment(profile);
+ this.environment = new Environment(profile, signature_data_url);
}
- /**
- * Prepares the sign request xml to be sent using the sign request template.
- *
- * @param data
- * The SignatureData.
- * @return Returns the sign request xml to be sent.
- * @throws SignatureException
- * f.e.
- */
- protected String prepareSignRequest(SignatureData data) throws SignatureException
+ protected String prepareSignRequest(SignatureData data) throws ConnectorException
{
log.debug("prepareSignRequestDetached:"); //$NON-NLS-1$
String sign_request_template = this.environment.getSignRequestTemplate();
String sign_key_identifier = this.environment.getSignKeyIdentifier();
- String loc_ref_content = // "http://wwwx.google.at";
- // this doesn't work - MOA always complains that file system access is
- // forbidden
- "file:///C:/wprinz/Filer/egiz2/test.utf8.txt";
+ String loc_ref_content = this.environment.getSignatureDataUrl();
String mime_type = data.getMimeType();
if (log.isDebugEnabled())
{
@@ -102,16 +92,9 @@ public class DetachedLocRefMOAConnector
}
/**
- * Analyzes the sign response xml and extracts the signature data.
- *
- * @param response_properties
- * The response properties containing the response String and
- * transport related information.
- * @return Returns the extracted data encapsulated in a SignatureObject.
- * @throws SignatureException
- * f.e.
+ * @see at.knowcenter.wag.egov.egiz.sig.connectors.LocalConnector#analyzeSignResponse(java.util.Properties)
*/
- public SignSignatureObject analyzeSignResponse(Properties response_properties) throws SignatureException
+ public SignSignatureObject analyzeSignResponse(Properties response_properties) throws ConnectorException
{
log.debug("analyzeSignResponse:"); //$NON-NLS-1$
@@ -119,33 +102,26 @@ public class DetachedLocRefMOAConnector
BKUHelper.checkResponseForError(response_string);
- // SignSignatureObject so = parseCreateXMLResponse(response_string);
+ SignSignatureObject so = MOAHelper.parseCreateXMLResponse(response_string, new DetachedLocRefMOAIdFormatter());
log.debug("analyzeSignResponse finished."); //$NON-NLS-1$
- return null;// so;
+ return so;
}
/**
- * Performs a sign.
- *
- * @param data
- * The data to be signed.
- * @return Returns the signature object containing the signature data.
- * @throws SignatureException
- * f.e.
- * @throws WebException
+ * @see at.knowcenter.wag.egov.egiz.sig.connectors.Connector#doSign(at.knowcenter.wag.egov.egiz.sig.SignatureData)
*/
- public SignSignatureObject doSign(SignatureData data) throws SignatureException, WebException
+ public SignSignatureObject doSign(SignatureData data) throws ConnectorException
{
log.debug("doSign:"); //$NON-NLS-1$
String sign_request_xml = prepareSignRequest(data);
- log.debug("sign_request_xml = " + sign_request_xml); //$NON-NLS-1$
+ DebugHelper.debugStringToFile(sign_request_xml, "MOA_DetLocRef_sign_request.xml"); //$NON-NLS-1$
String url = this.environment.getSignURL();
- Properties response_properties = sendRequest(url, MOASoapConnection.SERVICE_SIGN, sign_request_xml, data);
+ Properties response_properties = sendRequest(url, MOASoapConnection.SERVICE_SIGN, sign_request_xml);
- log.debug("response_string = " + response_properties.getProperty(BKUPostConnection.RESPONSE_STRING_KEY));; //$NON-NLS-1$
+ DebugHelper.debugStringToFile(response_properties.getProperty(BKUPostConnection.RESPONSE_STRING_KEY), "MOA_DetLocRef_sign_response.xml"); //$NON-NLS-1$
SignSignatureObject sso = analyzeSignResponse(response_properties);
// TODO this could be made more generic
@@ -155,8 +131,66 @@ public class DetachedLocRefMOAConnector
return sso;
}
+ /**
+ * @see at.knowcenter.wag.egov.egiz.sig.connectors.Connector#doVerify(at.knowcenter.wag.egov.egiz.sig.SignatureData,
+ * at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject)
+ */
+ public SignatureResponse doVerify(SignatureData data, SignSignatureObject so) throws ConnectorException
+ {
+ log.debug("doVerify:"); //$NON-NLS-1$
+
+ String verify_request_xml = prepareVerifyRequest(data, so);
+ log.debug("verify_request_xml = " + verify_request_xml); //$NON-NLS-1$
+
+ String url = this.environment.getVerifyURL();
+ Properties response_properties = sendRequest(url, MOASoapConnection.SERVICE_VERIFY, verify_request_xml);
+
+ // SignatureResponse signature_response =
+ // analyzeVerifyResponse(response_properties);
+
+ log.debug("doVerify finished."); //$NON-NLS-1$
+ return null; // signature_response;
+ }
+
+ /**
+ * Prepares the verify request xml to be sent using the verify request
+ * template.
+ *
+ * @param data
+ * The SignatureData.
+ * @param so
+ * The signature information object.
+ * @return Returns the verify request xml to be sent.
+ * @throws ConnectorException
+ * f.e.
+ */
+ public String prepareVerifyRequest(SignatureData data, SignSignatureObject so) throws ConnectorException
+ {
+ String verify_request_template = this.environment.getVerifyRequestTemplate();
+
+ String xml_content = null;
+ // TODO implement BKU
+ // if (sigObject.isMOASigned())
+ // {
+ // MOAConnector moa_conn = new MOAConnector();
+ // // get the MOA-template
+ // verify_template_str = moa_conn.getVerifyTemplate(normalizedText,
+ // sigObject);
+ // }
+ // else
+ // {
+ // get the BKU-template
+// xml_content = prepareXMLContent(data, so);
+ // }
+
+ String verify_request_xml = verify_request_template.replaceFirst(TemplateReplaces.XML_CONTENT_REPLACE, xml_content);
+ verify_request_xml = verify_request_xml.replaceFirst(TemplateReplaces.TRUST_PROFILE_ID_REPLACE, this.environment.getVerifyTrustProfileId());
+
+ return verify_request_xml;
+ }
+
protected Properties sendRequest(String url, String mode,
- String request_string, SignatureData data) throws SignatureException
+ String request_string) throws ConnectorException
{
try
{
@@ -165,8 +199,7 @@ public class DetachedLocRefMOAConnector
}
catch (Exception e)
{
- SignatureException se = new SignatureException(320, e);
- throw se;
+ throw new ConnectorException(320, e);
}
}
@@ -208,6 +241,11 @@ public class DetachedLocRefMOAConnector
protected static final String VERIFY_URL_KEY = "moa.verify.url"; //$NON-NLS-1$
/**
+ * The configuration key of the trust profile id.
+ */
+ protected static final String VERIFY_TRUST_PROFILE_ID = "moa.verify.TrustProfileID"; //$NON-NLS-1$
+
+ /**
* The configuration key for the ECDSA cert alg property.
*/
protected static final String ECDSA_CERT_ALG_KEY = "cert.alg.ecdsa"; //$NON-NLS-1$
@@ -217,6 +255,8 @@ public class DetachedLocRefMOAConnector
*/
protected static final String RSA_CERT_ALG_KEY = "cert.alg.rsa"; //$NON-NLS-1$
+ protected String signature_data_url = null;
+
protected String sign_key_identifier = null;
protected String sign_request_template = null;
@@ -229,6 +269,8 @@ public class DetachedLocRefMOAConnector
protected String verify_url = null;
+ protected String verify_trust_profile_id = null;
+
protected String cert_alg_ecdsa = null;
protected String cert_alg_rsa = null;
@@ -240,12 +282,22 @@ public class DetachedLocRefMOAConnector
* The configuration profile.
* @throws SettingsException
* f.e.
- * @throws SignatureException
+ * @throws ConnectorException
* f.e.
*/
- public Environment(String profile) throws SettingsException, SignatureException
+ public Environment(String profile, String signature_data_url) throws ConnectorException
{
- SettingsReader settings = SettingsReader.getInstance();
+ this.signature_data_url = signature_data_url;
+
+ SettingsReader settings = null;
+ try
+ {
+ settings = SettingsReader.getInstance();
+ }
+ catch (SettingsException e)
+ {
+ throw new ConnectorException(300, e);
+ }
this.sign_key_identifier = getConnectorValueFromProfile(settings, profile, SIGN_KEY_IDENTIFIER_KEY);
@@ -254,7 +306,7 @@ public class DetachedLocRefMOAConnector
if (this.sign_request_template == null)
{
// TODO make this a settings exception
- throw new SignatureException(300, "Can not read the create xml request template"); //$NON-NLS-1$
+ throw new ConnectorException(300, "Can not read the create xml request template"); //$NON-NLS-1$
}
this.sign_url = getConnectorValueFromProfile(settings, profile, SIGN_URL_KEY);
@@ -264,7 +316,7 @@ public class DetachedLocRefMOAConnector
if (this.verify_request_template == null)
{
// TODO make this a settings exception
- throw new SignatureException(300, "Can not read the verify xml request template"); //$NON-NLS-1$
+ throw new ConnectorException(300, "Can not read the verify xml request template"); //$NON-NLS-1$
}
String verify_filename = getConnectorValueFromProfile(settings, profile, VERIFY_TEMPLATE_KEY);
@@ -272,11 +324,13 @@ public class DetachedLocRefMOAConnector
if (this.verify_template == null)
{
// TODO make this a settings exception
- throw new SignatureException(300, "Can not read the verify template"); //$NON-NLS-1$
+ throw new ConnectorException(300, "Can not read the verify template"); //$NON-NLS-1$
}
this.verify_url = getConnectorValueFromProfile(settings, profile, VERIFY_URL_KEY);
+ this.verify_trust_profile_id = settings.getValueFromKey(VERIFY_TRUST_PROFILE_ID);
+
this.cert_alg_ecdsa = settings.getValueFromKey(ECDSA_CERT_ALG_KEY);
this.cert_alg_rsa = settings.getValueFromKey(RSA_CERT_ALG_KEY);
@@ -284,6 +338,16 @@ public class DetachedLocRefMOAConnector
}
/**
+ * Returns the URL where to load the detached data from.
+ *
+ * @return Returns the URL where to load the detached data from.
+ */
+ public String getSignatureDataUrl()
+ {
+ return this.signature_data_url;
+ }
+
+ /**
* Returns the sign key identifier.
*
* @return Returns the sign key identifier.
@@ -344,6 +408,16 @@ public class DetachedLocRefMOAConnector
}
/**
+ * Returns the verify trust profile id.
+ *
+ * @return Returns the verify trust profile id.
+ */
+ public String getVerifyTrustProfileId()
+ {
+ return this.verify_trust_profile_id;
+ }
+
+ /**
* Returns the ecdsa cert alg property.
*
* @return Returns the ecdsa cert alg property.