diff options
Diffstat (limited to 'src/main/java')
21 files changed, 584 insertions, 272 deletions
diff --git a/src/main/java/at/gv/egiz/pdfas/commandline/CommandlineConnectorChooser.java b/src/main/java/at/gv/egiz/pdfas/commandline/CommandlineConnectorChooser.java index 7a8283e..904bd9d 100644 --- a/src/main/java/at/gv/egiz/pdfas/commandline/CommandlineConnectorChooser.java +++ b/src/main/java/at/gv/egiz/pdfas/commandline/CommandlineConnectorChooser.java @@ -71,7 +71,7 @@ public class CommandlineConnectorChooser if (sig_kz == null)
{
- log.debug("sig_kz is null -> chose an old enveloped base64 connector"); //$NON-NLS-1$
+ log.debug("sig_kz is null -> choosing an old enveloped base64 connector"); //$NON-NLS-1$
return chooseEnvelopingBase64ConnectorOld(connectorType);
}
diff --git a/src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java b/src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java index ab8914c..f6b5602 100644 --- a/src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java +++ b/src/main/java/at/gv/egiz/pdfas/exceptions/ErrorCode.java @@ -19,6 +19,7 @@ public final class ErrorCode public static final int SETTING_NOT_FOUND = 100;
public static final int SETTINGS_EXCEPTION = 101;
public static final int KZ_SETTING_NOT_FOUND = 102;
+ public static final int NO_EMBEDABLE_TTF_CONFIGURED_FOR_PDFA = 103;
public static final int DOCUMENT_CANNOT_BE_READ = 201;
public static final int TEXT_EXTRACTION_EXCEPTION = 202;
diff --git a/src/main/java/at/gv/egiz/pdfas/web/filter/EncodingFilter.java b/src/main/java/at/gv/egiz/pdfas/web/filter/EncodingFilter.java new file mode 100644 index 0000000..5267918 --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/web/filter/EncodingFilter.java @@ -0,0 +1,123 @@ +package at.gv.egiz.pdfas.web.filter;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.builder.ToStringBuilder;
+import org.apache.log4j.Logger;
+
+/**
+ * @author <a href="mailto:thomas.knall@iaik.tugraz.at">Thomas Knall</a>
+ */
+public class EncodingFilter implements javax.servlet.Filter {
+
+ private static final String SERVLET_INIT_PARAM_ENCODING = "encoding";
+
+ private static final String SERVLET_INIT_PARAM_SET_REQUEST_ENCODING = "setRequestEncoding";
+ private static final String SERVLET_INIT_PARAM_FORCE_REQUEST_ENCODING = "forceRequestEncoding";
+
+ private static final String SERVLET_INIT_PARAM_SET_RESPONSE_ENCODING = "setResponseEncoding";
+ private static final String SERVLET_INIT_PARAM_FORCE_RESPONSE_ENCODING = "forceResponseEncoding";
+
+ private static final boolean DEFAULT_SET_REQUEST_ENCODING_VALUE = true;
+ private static final boolean DEFAULT_FORCE_REQUEST_ENCODING_VALUE = true;
+ private static final boolean DEFAULT_SET_RESPONSE_ENCODING_VALUE = false;
+ private static final boolean DEFAULT_FORCE_RESPONSE_ENCODING_VALUE = false;
+
+ private Logger log = Logger.getLogger(getClass().getName());
+
+ private String encoding = null;
+
+ private boolean setRequestEncoding;
+ private boolean forceRequestEncoding;
+
+ private boolean setResponseEncoding;
+ private boolean forceResponseEncoding;
+
+ private boolean enabled = false;
+
+ private boolean parseBooleanInitParameter(final FilterConfig filterConfig, String parameterName, boolean defaultValue) {
+ String paramValue = filterConfig.getInitParameter(parameterName);
+ if (paramValue == null) {
+ return defaultValue;
+ }
+ paramValue = paramValue.trim();
+ if (paramValue.equalsIgnoreCase("true")) {
+ return true;
+ } else if (paramValue.equalsIgnoreCase("false")){
+ return false;
+ } else {
+ log.warn("Unknown value \"" + paramValue + "\" for init parameter \"" + parameterName + "\" detected. Should be \"true\" or \"false\". Using default value \"" + defaultValue + "\".");
+ return defaultValue;
+ }
+ }
+
+ public void init(final FilterConfig filterConfig) throws ServletException {
+ log.debug("Initializing encoding filter (" + getClass().getName() + ").");
+
+ // mandatory parameter encoding
+ String desiredEncoding = filterConfig.getInitParameter(SERVLET_INIT_PARAM_ENCODING);
+ if (StringUtils.isEmpty(desiredEncoding)) {
+ log.warn("Unable to initialize encoding filter (" + getClass().getName() + "). Init parameter \"" + SERVLET_INIT_PARAM_ENCODING + "\" empty or not supplied.");
+ } else if (!Charset.isSupported(desiredEncoding)) {
+ log.warn("Unable to initialize encoding filter (" + getClass().getName() + "). Encoding \"" + desiredEncoding + "\" is not supported.");
+ } else {
+ this.encoding = desiredEncoding;
+ this.enabled = true;
+ this.setRequestEncoding = this.parseBooleanInitParameter(filterConfig, SERVLET_INIT_PARAM_SET_REQUEST_ENCODING, DEFAULT_SET_REQUEST_ENCODING_VALUE);
+ this.forceRequestEncoding = this.parseBooleanInitParameter(filterConfig, SERVLET_INIT_PARAM_FORCE_REQUEST_ENCODING, DEFAULT_FORCE_REQUEST_ENCODING_VALUE);
+ this.setResponseEncoding = this.parseBooleanInitParameter(filterConfig, SERVLET_INIT_PARAM_SET_RESPONSE_ENCODING, DEFAULT_SET_RESPONSE_ENCODING_VALUE);
+ this.forceResponseEncoding = this.parseBooleanInitParameter(filterConfig, SERVLET_INIT_PARAM_FORCE_RESPONSE_ENCODING, DEFAULT_FORCE_RESPONSE_ENCODING_VALUE);
+ log.debug("Encoding filter \"" + getClass().getName() + "\" configured: " + this.toString(true));
+
+ }
+ }
+
+ public String toString(boolean verbose) {
+ if (verbose) {
+ return new ToStringBuilder(this)
+ .append(SERVLET_INIT_PARAM_ENCODING, this.encoding)
+ .append(SERVLET_INIT_PARAM_SET_REQUEST_ENCODING, this.setRequestEncoding)
+ .append(SERVLET_INIT_PARAM_FORCE_REQUEST_ENCODING, this.forceRequestEncoding)
+ .append(SERVLET_INIT_PARAM_SET_RESPONSE_ENCODING, this.setResponseEncoding)
+ .append(SERVLET_INIT_PARAM_FORCE_RESPONSE_ENCODING, this.forceResponseEncoding)
+ .toString();
+ } else {
+ return super.toString();
+ }
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, final FilterChain filterChain) throws IOException, ServletException {
+ if (this.enabled) {
+ if (this.setRequestEncoding) {
+ if (this.forceRequestEncoding) {
+ log.trace("Forcing request encoding \"" + this.encoding + "\".");
+ request.setCharacterEncoding(this.encoding);
+ } else if (request.getCharacterEncoding() == null) {
+ log.trace("Request character encoding not set. Setting to \"" + this.encoding + "\".");
+ request.setCharacterEncoding("UTF8");
+ }
+ }
+ if (this.setResponseEncoding) {
+ if (this.forceResponseEncoding) {
+ log.trace("Forcing response encoding \"" + this.encoding + "\".");
+ response.setCharacterEncoding(this.encoding);
+ } else if (response.getCharacterEncoding() == null) {
+ log.trace("Response character encoding not set. Setting to \"" + this.encoding + "\".");
+ response.setCharacterEncoding("UTF8");
+ }
+ }
+ }
+ filterChain.doFilter(request, response);
+ }
+
+ public void destroy() {
+ }
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/web/i18n/LanguageDecoratorMapper.java b/src/main/java/at/gv/egiz/pdfas/web/i18n/LanguageDecoratorMapper.java index 1db7e3b..c610e42 100644 --- a/src/main/java/at/gv/egiz/pdfas/web/i18n/LanguageDecoratorMapper.java +++ b/src/main/java/at/gv/egiz/pdfas/web/i18n/LanguageDecoratorMapper.java @@ -18,9 +18,10 @@ import com.opensymphony.module.sitemesh.mapper.DefaultDecorator; public class LanguageDecoratorMapper extends AbstractDecoratorMapper {
- public static final String LOCALE_SESSION_KEY = "at.gv.egiz.pdfas.web.i18n:currentLocale";
- private Logger log = Logger.getLogger(LanguageDecoratorMapper.class);
+ private String decoratorParameter = null;
+
+ private static final Logger LOG = Logger.getLogger(LanguageDecoratorMapper.class);
public void init(Config config, Properties properties, DecoratorMapper parent) throws InstantiationException {
super.init(config, properties, parent);
@@ -37,29 +38,42 @@ public class LanguageDecoratorMapper extends AbstractDecoratorMapper { }
return null;
}
+
+ public static Locale getLocale(HttpServletRequest request, String decoratorParameter) {
+ Locale locale = null;
+ HttpSession session = request.getSession();
+
+ LOG.trace("Looking for locale in session (ID=" + session.getId() + ").");
+ locale = (Locale) session.getAttribute(LocaleParamFilter.LOCALE_SESSION_KEY);
+ if (locale == null) {
+ LOG.debug("Unable to find locale in session. Trying to create new locale based on Accept-Language header entry.");
+ String acceptLanguage = request.getHeader("Accept-Language");
+ if (acceptLanguage != null) {
+ LOG.trace("Accept-Language header entry: " + acceptLanguage);
+ } else {
+ LOG.trace("No header entry found.");
+ }
+ if (acceptLanguage != null && acceptLanguage.length() >= 2) {
+ locale = new Locale(acceptLanguage.substring(0, 2));
+ LOG.debug("New Locale created: " + locale);
+ LOG.trace("Setting language to " + locale.getDisplayLanguage() + ".");
+ session.setAttribute(LocaleParamFilter.LOCALE_SESSION_KEY, locale);
+ }
+ } else {
+ LOG.debug("Locale found: " + locale);
+ }
+
+ return locale;
+ }
public Decorator getDecorator(HttpServletRequest request, Page page) {
+ LOG.trace("SiteMesh language resource decorator mapper invoked.");
+
try {
Decorator result = null;
final Decorator d = super.getDecorator(request, page);
- HttpSession session = request.getSession();
- log.trace("Looking for Locale in session.");
- Locale locale = (Locale) session.getAttribute(LOCALE_SESSION_KEY);
- if (locale == null) {
- log.debug("Unable to find Locale in session. Creating new Locale based on Accept-Language header entry.");
- String acceptLanguage = request.getHeader("Accept-Language");
- if (acceptLanguage != null) {
- log.trace("Accept-Language header entry: " + acceptLanguage);
- } else {
- log.trace("No header entry found.");
- }
- if (acceptLanguage != null && acceptLanguage.length() >= 2) {
- locale = new Locale(acceptLanguage.substring(0, 2));
- log.debug("New Locale created: " + locale);
- }
- } else {
- log.debug("Locale found: " + locale);
- }
+ Locale locale = getLocale(request, this.decoratorParameter);
+
String path;
if (locale != null) {
path = modifyPath(d.getPage(), locale.getLanguage());
@@ -69,7 +83,7 @@ public class LanguageDecoratorMapper extends AbstractDecoratorMapper { File decFile = new File(config.getServletContext().getRealPath(path));
- log.debug("Looking for decorator \"" + path + "\".");
+ LOG.debug("Looking for decorator \"" + path + "\".");
if (decFile.isFile()) {
result = new DefaultDecorator(d.getName(), path, null) {
public String getInitParameter(String paramName) {
@@ -79,15 +93,15 @@ public class LanguageDecoratorMapper extends AbstractDecoratorMapper { }
if (result != null) {
- log.debug("Decorator found (\"" + result.getName() + "\", \"" + getFirstNotNull(new Object[] { result.getURIPath(), result.getPage(), "<n/a>"}) + "\").");
+ LOG.debug("Decorator found (\"" + result.getName() + "\", \"" + getFirstNotNull(new Object[] { result.getURIPath(), result.getPage(), "<n/a>"}) + "\").");
return result;
} else {
- log.trace("No decorator found. Delegating to super class.");
+ LOG.trace("No decorator found. Delegating to super class.");
result = super.getDecorator(request, page);
if (result != null) {
- log.debug("Super class returned decorator (\"" + result.getName() + "\", \"" + getFirstNotNull(new Object[] { result.getURIPath(), result.getPage(), "<n/a>"}) + "\").");
+ LOG.debug("Super class returned decorator (\"" + result.getName() + "\", \"" + getFirstNotNull(new Object[] { result.getURIPath(), result.getPage(), "<n/a>"}) + "\").");
} else {
- log.trace("Super class did not return a decorator.");
+ LOG.trace("Super class did not return a decorator.");
}
return result;
}
diff --git a/src/main/java/at/gv/egiz/pdfas/web/i18n/LocaleParamFilter.java b/src/main/java/at/gv/egiz/pdfas/web/i18n/LocaleParamFilter.java new file mode 100644 index 0000000..598b23b --- /dev/null +++ b/src/main/java/at/gv/egiz/pdfas/web/i18n/LocaleParamFilter.java @@ -0,0 +1,96 @@ +package at.gv.egiz.pdfas.web.i18n;
+
+import java.io.IOException;
+import java.util.Locale;
+import java.util.StringTokenizer;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.lang.LocaleUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Logger;
+
+public class LocaleParamFilter implements Filter {
+
+ private static final Logger LOG = Logger.getLogger(LocaleParamFilter.class);
+ public static final String LOCALE_SESSION_KEY = "at.gv.egiz.pdfas.web.i18n:currentLocale";
+ public static final String LOCALE_PARAM_KEY = "locale";
+
+ public void destroy() {
+ }
+
+ public static String normalizeLocaleString(String localeString) {
+ if (localeString == null) {
+ return null;
+ }
+ int jsessionIdIndex = localeString.toLowerCase().indexOf(";jsessionid");
+ if (jsessionIdIndex != -1) {
+ localeString = localeString.substring(0, jsessionIdIndex);
+ }
+ StringTokenizer tokenizer = new StringTokenizer(localeString, "_", false);
+ StringBuffer buffer = new StringBuffer();
+ int index = 0;
+ while (tokenizer.hasMoreTokens()) {
+ String token = tokenizer.nextToken();
+ switch (++index) {
+ case 1:
+ buffer.append(token.toLowerCase());
+ break;
+ case 2:
+ buffer.append(token.toUpperCase());
+ break;
+ default:
+ buffer.append(token);
+ break;
+ }
+ if (tokenizer.hasMoreTokens()) {
+ buffer.append("_");
+ }
+ }
+ return buffer.toString();
+ }
+
+ public static Locale getLocale(HttpServletRequest request) {
+ Locale locale = null;
+ HttpSession session = request.getSession();
+
+ LOG.trace("Looking for locale parameter \"" + LOCALE_PARAM_KEY + "\".");
+ String language = request.getParameter(LOCALE_PARAM_KEY);
+ if (!StringUtils.isEmpty(language)) {
+ LOG.debug("Locale parameter \"" + language + "\" found.");
+ String code = normalizeLocaleString(language.trim());
+ LOG.debug("Normalizing locale -> " + code);
+ try {
+ locale = LocaleUtils.toLocale(code);
+ LOG.info("Setting locale flag in session (ID=" + session.getId() + ") to \"" + locale.toString() + "\".");
+ session.setAttribute(LOCALE_SESSION_KEY, locale);
+ } catch (IllegalArgumentException e) {
+ LOG.error("Locale \"" + code + "\" is not valid. Flag will not be set.");
+ }
+ } else {
+ LOG.trace("No locale parameter found.");
+ }
+
+ return locale;
+ }
+
+ public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
+ HttpServletRequest request = (HttpServletRequest) servletRequest;
+
+ LOG.trace("LocaleParamFilter invoked.");
+ getLocale(request);
+
+ filterChain.doFilter(servletRequest, servletResponse);
+ }
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ }
+
+}
diff --git a/src/main/java/at/gv/egiz/pdfas/web/i18n/SetLanguageServlet.java b/src/main/java/at/gv/egiz/pdfas/web/i18n/SetLanguageServlet.java deleted file mode 100644 index 582f765..0000000 --- a/src/main/java/at/gv/egiz/pdfas/web/i18n/SetLanguageServlet.java +++ /dev/null @@ -1,59 +0,0 @@ -package at.gv.egiz.pdfas.web.i18n;
-
-import java.io.IOException;
-import java.util.Locale;
-
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.http.HttpSession;
-
-import org.apache.commons.lang.ArrayUtils;
-import org.apache.commons.lang.StringUtils;
-import org.apache.log4j.Logger;
-
-public class SetLanguageServlet extends HttpServlet {
-
- private static final long serialVersionUID = 1L;
-
- public static final String LANGUAGE_PARAMETER = "code";
- private Logger log = Logger.getLogger(LanguageDecoratorMapper.class);
-
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- this.doPost(request, response);
- }
-
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
-
- HttpSession session = request.getSession();
-
- // check manual language override (should be two-letter ISO-639 code)
- Locale currentManualSetLanguage = (Locale) session.getAttribute(LanguageDecoratorMapper.LOCALE_SESSION_KEY);
- String language = request.getParameter(LANGUAGE_PARAMETER);
- if (!StringUtils.isEmpty(language)) {
- String code = language.trim().toLowerCase();
- if (!ArrayUtils.contains(Locale.getISOLanguages(), code)) {
- log.error("Manually set language code \"" + code + "\" is not a valid ISO 639 language. Do not switch language.");
- } else {
- currentManualSetLanguage = new Locale(code);
- log.info("Switching language to " + currentManualSetLanguage.getDisplayLanguage() + ".");
- session.setAttribute(LanguageDecoratorMapper.LOCALE_SESSION_KEY, currentManualSetLanguage);
- }
- }
-
-// if (currentManualSetLanguage != null) {
-// log.info("Forcing language " + currentManualSetLanguage.getDisplayLanguage() + ".");
-// super.getServletContext().setAttribute(LanguageDecoratorMapper.LOCALE_SESSION_KEY, currentManualSetLanguage);
-// }
-
-// response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/"));
- RequestDispatcher rd = request.getRequestDispatcher("/");
- rd.forward(request, response);
-
- }
-
-
-
-}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java index 2ffc7b2..3824a98 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/PdfAS.java @@ -96,7 +96,7 @@ public abstract class PdfAS * The current version of the pdf-as library. This version string is logged on every invocation
* of the api or the web application.
*/
- public static final String PDFAS_VERSION = "3.0.8-20081119";
+ public static final String PDFAS_VERSION = "3.0.8-20090113";
/**
* The key of the strict mode setting.
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/SettingsException.java b/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/SettingsException.java index d781577..1a41982 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/SettingsException.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/exceptions/SettingsException.java @@ -29,28 +29,38 @@ import at.gv.egiz.pdfas.exceptions.ErrorCode; *
* @author wprinz
*/
-public class SettingsException extends PresentableException
-{
-
- /**
- * SVUID.
- */
- private static final long serialVersionUID = -99979541706943372L;
-
- /**
- * @param message
- */
- public SettingsException(String message)
- {
- super(ErrorCode.SETTINGS_EXCEPTION, message);
- }
-
- /**
- * @param message
- * @param cause
- */
- public SettingsException(String message, Throwable cause)
- {
- super(ErrorCode.SETTINGS_EXCEPTION, message, cause);
- }
+public class SettingsException extends PresentableException {
+
+ /**
+ * SVUID.
+ */
+ private static final long serialVersionUID = -99979541706943372L;
+
+ /**
+ * @param message
+ */
+ public SettingsException(String message) {
+ super(ErrorCode.SETTINGS_EXCEPTION, message);
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public SettingsException(String message, Throwable cause) {
+ super(ErrorCode.SETTINGS_EXCEPTION, message, cause);
+ }
+
+ public SettingsException(int errorCode, String message, Throwable cause) {
+ super(errorCode, message, cause);
+ }
+
+ public SettingsException(int errorCode, String message) {
+ super(errorCode, message);
+ }
+
+ public SettingsException(int errorCode, Throwable cause) {
+ super(errorCode, cause);
+ }
+
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java index b1b1a5a..0467bad 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/pdf/PDFSignatureObjectIText.java @@ -359,8 +359,9 @@ public class PDFSignatureObjectIText implements PDFSignatureObject }
else
{
- if(pdfaValid)
- throw new PDFDocumentException(0,"PDF/A modus requires an embedable true type font");
+ if (pdfaValid) {
+ throw new PDFDocumentException(ErrorCode.NO_EMBEDABLE_TTF_CONFIGURED_FOR_PDFA, "PDF/A modus requires an embedable true type font");
+ }
cell_font = getCellFont(font_string);
}
Phrase text_phrase = new Phrase(text, cell_font);
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java index 9253955..cec8d6f 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUHelper.java @@ -156,6 +156,9 @@ public final class BKUHelper public static SignSignatureObject parseCreateXMLResponse(String xmlResponse,
IdFormatter id_formatter) throws ConnectorException
{
+ if (log.isDebugEnabled()) {
+ log.debug("xmlResponse = " + xmlResponse);
+ }
Pattern sig_val_p_s = Pattern.compile("<[\\w]*:?SignatureValue>"); //$NON-NLS-1$
Pattern sig_val_p_e = Pattern.compile("</[\\w]*:?SignatureValue>"); //$NON-NLS-1$
Pattern iss_nam_p_s = Pattern.compile("<[\\w]*:?X509IssuerName>"); //$NON-NLS-1$
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUPostConnection.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUPostConnection.java index 1a720d8..b582715 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUPostConnection.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/BKUPostConnection.java @@ -41,6 +41,11 @@ public final class BKUPostConnection public static final String BKU_SERVER_HEADER_KEY = "BKU-Server-Header"; //$NON-NLS-1$
/**
+ * The response Properties key that identifies the BKU User-Agent header.
+ */
+ public static final String BKU_USER_AGENT_HEADER_KEY = "BKU-User-Agent-Header"; //$NON-NLS-1$
+
+ /**
* The log.
*/
private static Log log = LogFactory.getLog(BKUPostConnection.class);
@@ -119,7 +124,11 @@ public final class BKUPostConnection }
}
Header server_header = post_method.getResponseHeader("Server"); //$NON-NLS-1$
- response_properties.setProperty(BKU_SERVER_HEADER_KEY, server_header.getValue());
+ if (server_header != null) {
+ response_properties.setProperty(BKU_SERVER_HEADER_KEY, server_header.getValue());
+ } else {
+ log.warn("BKU response header \"Server\" is empty.");
+ }
log.debug(post_method.getResponseCharSet());
if (!post_method.getResponseCharSet().equals("UTF-8")) //$NON-NLS-1$
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java index 5dbc0a6..d10afc6 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/bku/DetachedBKUConnector.java @@ -21,7 +21,9 @@ import at.knowcenter.wag.egov.egiz.sig.connectors.Connector; import at.knowcenter.wag.egov.egiz.sig.connectors.LocalConnector;
import at.knowcenter.wag.egov.egiz.sig.connectors.TemplateReplaces;
import at.knowcenter.wag.egov.egiz.sig.connectors.moa.DetachedLocRefMOAConnector;
+import at.knowcenter.wag.egov.egiz.sig.connectors.mocca.MOCCAHelper;
import at.knowcenter.wag.egov.egiz.sig.sigid.DetachedIdFormatter;
+import at.knowcenter.wag.egov.egiz.sig.sigid.DetachedMOCIdFormatter;
import at.knowcenter.wag.egov.egiz.sig.sigkz.SigKZIDHelper;
import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
import at.knowcenter.wag.egov.egiz.tools.FileHelper;
@@ -123,10 +125,19 @@ public class DetachedBKUConnector implements Connector, LocalConnector log.debug("analyzeSignResponse:"); //$NON-NLS-1$
String response_string = response_properties.getProperty(BKUPostConnection.RESPONSE_STRING_KEY);
+ String bkuServerHeader = response_properties.getProperty(BKUPostConnection.BKU_SERVER_HEADER_KEY);
+ String bkuUserAgentHeader = response_properties.getProperty(BKUPostConnection.BKU_USER_AGENT_HEADER_KEY);
BKUHelper.checkResponseForError(response_string);
- SignSignatureObject so = BKUHelper.parseCreateXMLResponse(response_string, new DetachedIdFormatter());
+ SignSignatureObject so;
+ if (MOCCAHelper.isMOCCACCEId(bkuServerHeader == null ? bkuUserAgentHeader : bkuServerHeader)) {
+ log.debug("Evaluating response as MOCCA response.");
+ so = MOCCAHelper.parseCreateXMLResponse(response_string, new DetachedMOCIdFormatter());
+ } else {
+ so = BKUHelper.parseCreateXMLResponse(response_string, new DetachedIdFormatter());
+ }
+
so.response_properties = response_properties;
log.debug("analyzeSignResponse finished."); //$NON-NLS-1$
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/MOASoapWithAttachmentConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/MOASoapWithAttachmentConnector.java index 44a7c38..b45303d 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/MOASoapWithAttachmentConnector.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/moa/MOASoapWithAttachmentConnector.java @@ -4,15 +4,7 @@ package at.knowcenter.wag.egov.egiz.sig.connectors.moa;
import java.security.cert.X509Certificate;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
import java.util.Properties;
-import java.util.SimpleTimeZone;
-import java.util.TimeZone;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -22,7 +14,6 @@ import at.gv.egiz.pdfas.framework.ConnectorParameters; 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.sig.SignatureData;
import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/LocRefDetachedMOCCAConnector.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/LocRefDetachedMOCCAConnector.java index 8ae6d5f..fcfe006 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/LocRefDetachedMOCCAConnector.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/LocRefDetachedMOCCAConnector.java @@ -1,10 +1,5 @@ package at.knowcenter.wag.egov.egiz.sig.connectors.mocca;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.security.cert.CertificateException;
-import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Properties;
import java.util.regex.Matcher;
@@ -15,16 +10,11 @@ import org.apache.commons.logging.LogFactory; import at.gv.egiz.pdfas.exceptions.ErrorCode;
import at.gv.egiz.pdfas.framework.ConnectorParameters;
-import at.gv.egiz.pdfas.web.helper.SigningTimeHelper;
import at.knowcenter.wag.egov.egiz.cfg.SettingsReader;
import at.knowcenter.wag.egov.egiz.exceptions.ConnectorException;
-import at.knowcenter.wag.egov.egiz.exceptions.PresentableException;
import at.knowcenter.wag.egov.egiz.exceptions.SettingsException;
-import at.knowcenter.wag.egov.egiz.exceptions.SignatureException;
import at.knowcenter.wag.egov.egiz.sig.SignatureData;
-import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
import at.knowcenter.wag.egov.egiz.sig.SignatureResponse;
-import at.knowcenter.wag.egov.egiz.sig.X509Cert;
import at.knowcenter.wag.egov.egiz.sig.connectors.Connector;
import at.knowcenter.wag.egov.egiz.sig.connectors.LocalConnector;
import at.knowcenter.wag.egov.egiz.sig.connectors.TemplateReplaces;
@@ -32,7 +22,6 @@ 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.DetachedMOCIdFormatter;
-import at.knowcenter.wag.egov.egiz.sig.sigid.IdFormatter;
import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
import at.knowcenter.wag.egov.egiz.tools.FileHelper;
@@ -126,139 +115,13 @@ public class LocRefDetachedMOCCAConnector implements Connector, LocalConnector { log.debug("analyzeSignResponse:");
String response_string = response_properties.getProperty(BKUPostConnection.RESPONSE_STRING_KEY);
BKUHelper.checkResponseForError(response_string);
- SignSignatureObject so = this.parseCreateXMLResponse(response_string, new DetachedMOCIdFormatter());
+ SignSignatureObject so = MOCCAHelper.parseCreateXMLResponse(response_string, new DetachedMOCIdFormatter());
so.response_properties = response_properties;
log.debug("analyzeSignResponse finished.");
return so;
}
/**
- * This method parses the signature creation response of the signature device.
- * @param xmlResponse The response string.
- * @return Returns the parsed signature object holding the data.
- * @see SignatureObject
- * @see CodingHelper
- * @see X509Cert
- */
- public SignSignatureObject parseCreateXMLResponse(String xmlResponse, IdFormatter id_formatter) throws ConnectorException {
-
- Pattern iss_nam_p_s = Pattern.compile("<[\\w]*:?X509IssuerName>");
- Pattern iss_nam_p_e = Pattern.compile("</[\\w]*:?X509IssuerName>");
- Pattern sig_tim_p_s = Pattern.compile("<[\\w]*:?SigningTime>");
- Pattern sig_tim_p_e = Pattern.compile("</[\\w]*:?SigningTime>");
- Pattern ser_num_p_s = Pattern.compile("<[\\w]*:?X509SerialNumber>");
- Pattern ser_num_p_e = Pattern.compile("</[\\w]*:?X509SerialNumber>");
- Pattern sig_cer_p_s = Pattern.compile("<[\\w]*:?X509Certificate>");
- Pattern sig_cer_p_e = Pattern.compile("</[\\w]*:?X509Certificate>");
-
- Matcher iss_nam_m_s = iss_nam_p_s.matcher(xmlResponse);
- Matcher iss_nam_m_e = iss_nam_p_e.matcher(xmlResponse);
- Matcher sig_tim_m_s = sig_tim_p_s.matcher(xmlResponse);
- Matcher sig_tim_m_e = sig_tim_p_e.matcher(xmlResponse);
- Matcher ser_num_m_s = ser_num_p_s.matcher(xmlResponse);
- Matcher ser_num_m_e = ser_num_p_e.matcher(xmlResponse);
- Matcher sig_cer_m_s = sig_cer_p_s.matcher(xmlResponse);
- Matcher sig_cer_m_e = sig_cer_p_e.matcher(xmlResponse);
-
- // SignatureValue
- String sig_val = null;
- Matcher signatureValueMatcher = Pattern.compile("<(\\w+:)?SignatureValue( Id=\"[\\w-]+\")?>\\s*(.*)\\s*</(\\w+:)?SignatureValue>").matcher(xmlResponse);
- if (signatureValueMatcher.find()) {
- sig_val = signatureValueMatcher.group(3);
- }
- log.debug("sig_val = " + sig_val);
-
- // X509IssuerName
- String iss_nam = null;
- if (iss_nam_m_s.find() && iss_nam_m_e.find()) {
- iss_nam = xmlResponse.substring(iss_nam_m_s.end(), iss_nam_m_e.start());
- }
- log.debug("iss_nam = " + iss_nam);
-
- // X509SerialNumber
- String ser_num = null;
- if (ser_num_m_s.find() && ser_num_m_e.find()) {
- ser_num = BKUHelper.removeAllWhitespace(xmlResponse.substring(ser_num_m_s.end(), ser_num_m_e.start()));
- }
- log.debug("ser_num = " + ser_num);
-
- // SigningTime
- String sig_tim = null;
- if (sig_tim_m_s.find() && sig_tim_m_e.find()) {
- sig_tim = xmlResponse.substring(sig_tim_m_s.end(), sig_tim_m_e.start());
- }
- log.debug("sig_tim = " + sig_tim);
-
- // X509Certificate
- X509Certificate cert = null;
- if (sig_cer_m_s.find() && sig_cer_m_e.find()) {
- String sig_cer = BKUHelper.removeAllWhitespace(xmlResponse.substring(sig_cer_m_s.end(), sig_cer_m_e.start()));
-
- try {
- byte[] der = CodingHelper.decodeBase64(sig_cer);
- ByteArrayInputStream bais = new ByteArrayInputStream(der);
- CertificateFactory cf = CertificateFactory.getInstance("X.509");
- cert = (X509Certificate) cf.generateCertificate(bais);
- bais.close();
- } catch (UnsupportedEncodingException e) {
- throw new ConnectorException(300, e);
- } catch (CertificateException e) {
- throw new ConnectorException(300, e);
- } catch (IOException e) {
- throw new ConnectorException(300, e);
- }
- }
- log.debug("X509Certificate = " + cert);
-
- if (log.isDebugEnabled()) {
-
- String cert_iss = cert.getIssuerDN().getName();
- log.debug("certificate's issuer = " + cert_iss);
- log.debug("response's issuer = " + iss_nam);
- log.debug("issuer matches = " + cert_iss.equals(iss_nam));
- log.debug("ser number matches = " + cert.getSerialNumber().toString().equals(ser_num));
- }
-
- // extract Signature Id's
- String[] ids = extractIds(xmlResponse);
- String final_ids = id_formatter.formatIds(ids);
-
- SignSignatureObject so = new SignSignatureObject();
- so.date = sig_tim;
- so.issuer = iss_nam;
- so.signatureValue = sig_val;
- so.x509Certificate = cert;
-
- so.id = final_ids;
-
- return so;
- }
-
- /**
- * Extraction of the id attributes from the xml response.
- * @param xmlResponse The xml response.
- * @return The parsed id attributes.
- */
- public final static String[] extractIds(String xmlResponse) {
- return new String[] { extractId(xmlResponse) };
- }
-
- /**
- * There is only one special common part of all id attributes of this connector that has to be
- * stored. This method returns that single part.
- * @param xmlResponse The xml response.
- * @return The parsed common part of all id attributes.
- */
- private final static String extractId(String xmlResponse) {
- final Pattern ID_PATTERN = Pattern.compile("Id\\s*=\\s*\"\\s*Signature-([\\p{XDigit}]+)-\\d+\\s*\"");
- Matcher matcher = ID_PATTERN.matcher(xmlResponse);
- if (matcher.find() && matcher.groupCount() > 0) {
- return matcher.group(1);
- }
- return null;
- }
-
- /**
* Verification is not supported by MOCCA. Therefore this method always throws a
* {@link ConnectorException} with error code {@link ErrorCode#SIGNATURE_VERIFICATION_NOT_SUPPORTED}.
*/
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/MOCCAHelper.java b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/MOCCAHelper.java new file mode 100644 index 0000000..1bb89be --- /dev/null +++ b/src/main/java/at/knowcenter/wag/egov/egiz/sig/connectors/mocca/MOCCAHelper.java @@ -0,0 +1,194 @@ +package at.knowcenter.wag.egov.egiz.sig.connectors.mocca;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+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.exceptions.ConnectorException;
+import at.knowcenter.wag.egov.egiz.sig.SignatureObject;
+import at.knowcenter.wag.egov.egiz.sig.X509Cert;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.BKUHelper;
+import at.knowcenter.wag.egov.egiz.sig.connectors.bku.SignSignatureObject;
+import at.knowcenter.wag.egov.egiz.sig.sigid.IdFormatter;
+import at.knowcenter.wag.egov.egiz.tools.CodingHelper;
+
+/**
+ * Provides useful methods for the usage of the open source cce mocca.
+ *
+ * @author tknall
+ */
+public final class MOCCAHelper {
+
+ /**
+ * Prevents this plain util class from being instantiated.
+ */
+ private MOCCAHelper() {
+ }
+
+ /**
+ * The logging implementation.
+ */
+ private final static Log log = LogFactory.getLog(MOCCAHelper.class);
+
+ /**
+ * The pattern that identifies a mocca response (that matches the header value "Server" or "User-Agent").
+ */
+ private final static Pattern MOCCA_PATTERN = Pattern.compile("(citizen-card-environment/\\d+(\\.\\d+) MOCCA[ /].*)|(Jetty(.*))");
+
+ /**
+ * Checks if the given header value for "Server" or "User-Agent" respectively indicates that
+ * the response was from a mocca cce.
+ * @param cceId The value of the http header "Server" or "User-Agent".
+ * @see http://www.buergerkarte.at/konzept/securitylayer/spezifikation/aktuell/bindings/bindings.html#http.kodierung
+ * @return <code>true</code> if the id points to a mocca response, <code>false</code> if not.
+ */
+ public final static boolean isMOCCACCEId(String cceId) {
+ if (cceId == null) {
+ return false;
+ }
+ return MOCCA_PATTERN.matcher(cceId).matches();
+ }
+
+ /**
+ * This method parses the signature creation response of the signature
+ * device mocca.
+ *
+ * @param xmlResponse The response string.
+ * @return Returns the parsed signature object holding the data.
+ * @see SignatureObject
+ * @see CodingHelper
+ * @see X509Cert
+ */
+ public final static SignSignatureObject parseCreateXMLResponse(String xmlResponse, IdFormatter id_formatter) throws ConnectorException {
+
+ if (log.isDebugEnabled()) {
+ log.debug("xmlResponse = " + xmlResponse);
+ }
+
+ Pattern iss_nam_p_s = Pattern.compile("<[\\w]*:?X509IssuerName>");
+ Pattern iss_nam_p_e = Pattern.compile("</[\\w]*:?X509IssuerName>");
+ Pattern sig_tim_p_s = Pattern.compile("<[\\w]*:?SigningTime>");
+ Pattern sig_tim_p_e = Pattern.compile("</[\\w]*:?SigningTime>");
+ Pattern ser_num_p_s = Pattern.compile("<[\\w]*:?X509SerialNumber>");
+ Pattern ser_num_p_e = Pattern.compile("</[\\w]*:?X509SerialNumber>");
+ Pattern sig_cer_p_s = Pattern.compile("<[\\w]*:?X509Certificate>");
+ Pattern sig_cer_p_e = Pattern.compile("</[\\w]*:?X509Certificate>");
+
+ Matcher iss_nam_m_s = iss_nam_p_s.matcher(xmlResponse);
+ Matcher iss_nam_m_e = iss_nam_p_e.matcher(xmlResponse);
+ Matcher sig_tim_m_s = sig_tim_p_s.matcher(xmlResponse);
+ Matcher sig_tim_m_e = sig_tim_p_e.matcher(xmlResponse);
+ Matcher ser_num_m_s = ser_num_p_s.matcher(xmlResponse);
+ Matcher ser_num_m_e = ser_num_p_e.matcher(xmlResponse);
+ Matcher sig_cer_m_s = sig_cer_p_s.matcher(xmlResponse);
+ Matcher sig_cer_m_e = sig_cer_p_e.matcher(xmlResponse);
+
+ // SignatureValue
+ String sig_val = null;
+ Matcher signatureValueMatcher = Pattern.compile("<(\\w+:)?SignatureValue( Id=\"[\\w-]+\")?>\\s*(.*)\\s*</(\\w+:)?SignatureValue>").matcher(xmlResponse);
+ if (signatureValueMatcher.find()) {
+ sig_val = signatureValueMatcher.group(3);
+ }
+ log.debug("sig_val = " + sig_val);
+
+ // X509IssuerName
+ String iss_nam = null;
+ if (iss_nam_m_s.find() && iss_nam_m_e.find()) {
+ iss_nam = xmlResponse.substring(iss_nam_m_s.end(), iss_nam_m_e.start());
+ }
+ log.debug("iss_nam = " + iss_nam);
+
+ // X509SerialNumber
+ String ser_num = null;
+ if (ser_num_m_s.find() && ser_num_m_e.find()) {
+ ser_num = BKUHelper.removeAllWhitespace(xmlResponse.substring(ser_num_m_s.end(), ser_num_m_e.start()));
+ }
+ log.debug("ser_num = " + ser_num);
+
+ // SigningTime
+ String sig_tim = null;
+ if (sig_tim_m_s.find() && sig_tim_m_e.find()) {
+ sig_tim = xmlResponse.substring(sig_tim_m_s.end(), sig_tim_m_e.start());
+ }
+ log.debug("sig_tim = " + sig_tim);
+
+ // X509Certificate
+ X509Certificate cert = null;
+ if (sig_cer_m_s.find() && sig_cer_m_e.find()) {
+ String sig_cer = BKUHelper.removeAllWhitespace(xmlResponse.substring(sig_cer_m_s.end(), sig_cer_m_e.start()));
+
+ try {
+ byte[] der = CodingHelper.decodeBase64(sig_cer);
+ ByteArrayInputStream bais = new ByteArrayInputStream(der);
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ cert = (X509Certificate) cf.generateCertificate(bais);
+ bais.close();
+ } catch (UnsupportedEncodingException e) {
+ throw new ConnectorException(300, e);
+ } catch (CertificateException e) {
+ throw new ConnectorException(300, e);
+ } catch (IOException e) {
+ throw new ConnectorException(300, e);
+ }
+ }
+ log.debug("X509Certificate = " + cert);
+
+ if (log.isDebugEnabled()) {
+
+ String cert_iss = cert.getIssuerDN().getName();
+ log.debug("certificate's issuer = " + cert_iss);
+ log.debug("response's issuer = " + iss_nam);
+ log.debug("issuer matches = " + cert_iss.equals(iss_nam));
+ log.debug("ser number matches = " + cert.getSerialNumber().toString().equals(ser_num));
+ }
+
+ // extract Signature Id's
+ String[] ids = extractIds(xmlResponse);
+ String final_ids = id_formatter.formatIds(ids);
+
+ SignSignatureObject so = new SignSignatureObject();
+ so.date = sig_tim;
+ so.issuer = iss_nam;
+ so.signatureValue = sig_val;
+ so.x509Certificate = cert;
+
+ so.id = final_ids;
+
+ return so;
+ }
+
+ /**
+ * Extraction of the id attributes from the xml response.
+ *
+ * @param xmlResponse The xml response.
+ * @return The parsed id attributes.
+ */
+ public final static String[] extractIds(String xmlResponse) {
+ return new String[] { extractId(xmlResponse) };
+ }
+
+ /**
+ * There is only one special common part of all id attributes of this
+ * connector that has to be stored. This method returns that single part.
+ *
+ * @param xmlResponse The xml response.
+ * @return The parsed common part of all id attributes.
+ */
+ private final static String extractId(String xmlResponse) {
+ final Pattern ID_PATTERN = Pattern.compile("Id\\s*=\\s*\"\\s*Signature-([\\p{XDigit}]+)-\\d+\\s*\"");
+ Matcher matcher = ID_PATTERN.matcher(xmlResponse);
+ if (matcher.find() && matcher.groupCount() > 0) {
+ return matcher.group(1);
+ }
+ return null;
+ }
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java index 2adc4b1..16352de 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/DataURLServlet.java @@ -126,6 +126,7 @@ public class DataURLServlet extends HttpServlet {
Object sessionObject = SessionHelper.getSession(request);
+ // obsolete since EncodingFilter is set in web.xml
checkRequestCharacterEncoding(request);
if (sessionObject instanceof SignSessionInformation)
@@ -152,8 +153,6 @@ public class DataURLServlet extends HttpServlet protected void checkRequestCharacterEncoding(HttpServletRequest request) throws UnsupportedEncodingException
{
- log.debug("Request character encoding = " + request.getCharacterEncoding()); //$NON-NLS-1$
-// if (request.getCharacterEncoding() == null || request.getCharacterEncoding().equals("UTF-8")) //$NON-NLS-1$
if (request.getCharacterEncoding() == null || request.getCharacterEncoding().length() <= 0) //$NON-NLS-1$
{
log.info("The BKU didn't set a character encoding for the request."); //$NON-NLS-1$
@@ -220,12 +219,20 @@ public class DataURLServlet extends HttpServlet response.setCharacterEncoding("UTF-8");
response.getWriter().println(request_string);
}
- else
+ else if (xml_response != null)
{
log.debug("Received a normal response -> storing the response."); //$NON-NLS-1$
Properties response_properties = new Properties();
response_properties.setProperty(BKUPostConnection.RESPONSE_STRING_KEY, xml_response);
+
+ String userAgent = request.getHeader("User-Agent");
+ if (userAgent != null) {
+ response_properties.setProperty(BKUPostConnection.BKU_USER_AGENT_HEADER_KEY, userAgent);
+ } else {
+ log.warn("BKU request/response header \"User-Agent\" is empty.");
+ }
+
si.response_properties = response_properties;
log.debug("All requests have been processed -> processing the responses."); //$NON-NLS-1$
@@ -294,7 +301,9 @@ public class DataURLServlet extends HttpServlet // do not insert any code within this else block !
}
- }
+ } else {
+ log.debug("No XMLResponse found. Do nothing.");
+ }
}
protected void processVerify(HttpServletRequest request, HttpServletResponse response, VerifySessionInformation si) throws ServletException, IOException, ConnectorException, InvalidIDException
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java index a8ff426..1efc64f 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/ProvidePDFServlet.java @@ -59,8 +59,8 @@ public class ProvidePDFServlet extends HttpServlet { log.debug("Signed pdf found.");
session.removeAttribute(SessionAttributes.SIGNED_PDF_DOCUMENT);
log.debug("Returning signed pdf to browser.");
- log.debug("Invalidating session.");
- session.invalidate();
+// log.debug("Invalidating session.");
+// session.invalidate();
SignServletHelper.returnSignResponse(si, response);
return;
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java index 124b2a3..589de7c 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/SignServlet.java @@ -244,8 +244,11 @@ public class SignServlet extends HttpServlet catch (Exception e)
{
// Error retrieving data
- request.setAttribute("error", "Fehler beim Upload der Daten");
- request.setAttribute("cause", "Beim Upload der Daten ist ein Fehler aufgetreten.");
+// request.setAttribute("error", "Fehler beim Upload der Daten");
+// request.setAttribute("cause", "Beim Upload der Daten ist ein Fehler aufgetreten.");
+ request.setAttribute("error", "signservlet.error");
+ request.setAttribute("cause", "signservlet.cause");
+ request.setAttribute("resourcebundle", Boolean.TRUE);
dispatch(request, response, "/jsp/error.jsp");
return;
}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java new file mode 100644 index 0000000..ba5d43e --- /dev/null +++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/UpdateFormServlet.java @@ -0,0 +1,41 @@ +package at.knowcenter.wag.egov.egiz.web.servlets;
+
+import java.io.IOException;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import at.knowcenter.wag.egov.egiz.web.FormFields;
+
+public class UpdateFormServlet extends HttpServlet {
+
+ private static final long serialVersionUID = 1L;
+
+ public static final String UPLOADFORM_SIGNATURE_TYPE_KEY = "signupload.jsp:signatureType";
+ public static final String UPLOADFORM_SIGNATURE_MODE_KEY = "signupload.jsp:signatureMode";
+ public static final String UPLOADFORM_SIGNATURE_DEVICE_KEY = "signupload.jsp:signatureKey";
+
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ this.doPost(request, response);
+ }
+
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ String mode = request.getParameter(FormFields.FIELD_MODE);
+ String device = request.getParameter(FormFields.FIELD_CONNECTOR);
+ String type = request.getParameter(FormFields.FIELD_SIGNATURE_TYPE);
+
+ HttpSession session = request.getSession();
+ session.setAttribute(UPLOADFORM_SIGNATURE_DEVICE_KEY, device);
+ session.setAttribute(UPLOADFORM_SIGNATURE_MODE_KEY, mode);
+ session.setAttribute(UPLOADFORM_SIGNATURE_TYPE_KEY, type);
+
+ RequestDispatcher dispatcher = request.getRequestDispatcher("/jsp/signupload.jsp");
+ dispatcher.forward(request, response);
+// response.sendRedirect(response.encodeRedirectURL(request.getContextPath() + "/jsp/signupload.jsp"));
+ }
+
+}
diff --git a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java index 5e1819e..0eb417b 100644 --- a/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java +++ b/src/main/java/at/knowcenter/wag/egov/egiz/web/servlets/VerifyPreviewServlet.java @@ -699,8 +699,9 @@ public class VerifyPreviewServlet extends HttpServlet }
catch (FileUploadException e)
{
- request.setAttribute("error", "Fehler beim Upload der Daten");
- request.setAttribute("cause", "Beim Upload der Daten ist ein Fehler aufgetreten.");
+ request.setAttribute("error", "verifypreviewservlet.error");
+ request.setAttribute("cause", "verifypreviewservlet.cause");
+ request.setAttribute("resourcebundle", Boolean.TRUE);
dispatch(request, response, "/jsp/error.jsp");
}
catch (PresentableException e)
diff --git a/src/main/java/at/knowcenter/wag/exactparser/parsing/PDFUtils.java b/src/main/java/at/knowcenter/wag/exactparser/parsing/PDFUtils.java index 1387fb2..88476be 100644 --- a/src/main/java/at/knowcenter/wag/exactparser/parsing/PDFUtils.java +++ b/src/main/java/at/knowcenter/wag/exactparser/parsing/PDFUtils.java @@ -387,7 +387,8 @@ public abstract class PDFUtils while (isNumeric(pdf[index]) || pdf[index] == '.')
{
- number += (char) pdf[index];
+ char digit = (char) pdf[index];
+ number += digit;
index++;
}
|