summaryrefslogtreecommitdiff
path: root/BKULocal/src/main/java/at/gv/egiz/bku/local/stal
diff options
context:
space:
mode:
Diffstat (limited to 'BKULocal/src/main/java/at/gv/egiz/bku/local/stal')
-rw-r--r--BKULocal/src/main/java/at/gv/egiz/bku/local/stal/ExclusiveAccessSTAL.java76
-rw-r--r--BKULocal/src/main/java/at/gv/egiz/bku/local/stal/ExclusiveAccessSTALFactory.java65
-rw-r--r--BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalBKUWorker.java2
-rw-r--r--BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSTALFactory.java69
-rw-r--r--BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSecureViewer.java24
-rw-r--r--BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java9
6 files changed, 195 insertions, 50 deletions
diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/ExclusiveAccessSTAL.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/ExclusiveAccessSTAL.java
new file mode 100644
index 00000000..0b8511e3
--- /dev/null
+++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/ExclusiveAccessSTAL.java
@@ -0,0 +1,76 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.local.stal;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import at.gv.egiz.stal.ErrorResponse;
+import at.gv.egiz.stal.STAL;
+import at.gv.egiz.stal.STALRequest;
+import at.gv.egiz.stal.STALResponse;
+
+public class ExclusiveAccessSTAL implements STAL {
+
+ private final Logger log = LoggerFactory.getLogger(ExclusiveAccessSTAL.class);
+
+ private Lock lock = new ReentrantLock(true);
+
+ private long timeout = 30;
+
+ private STAL stal;
+
+ public ExclusiveAccessSTAL(STAL stal) {
+ if (stal == null) {
+ throw new NullPointerException("Argument 'stal' must not be null.");
+ }
+ this.stal = stal;
+ }
+
+ @Override
+ public List<STALResponse> handleRequest(
+ List<? extends STALRequest> aRequestList) {
+
+ try {
+ if (lock.tryLock(timeout, TimeUnit.SECONDS)) {
+ try {
+ return stal.handleRequest(aRequestList);
+ } finally {
+ lock.unlock();
+ }
+ } else {
+ // time out
+ log.info("Timeout while waiting for exclusive access to STAL.");
+ ErrorResponse response = new ErrorResponse(6000);
+ return Collections.singletonList((STALResponse) response);
+ }
+ } catch (InterruptedException e) {
+ // interrupted
+ ErrorResponse response = new ErrorResponse(6000);
+ return Collections.singletonList((STALResponse) response);
+ }
+
+ }
+
+}
diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/ExclusiveAccessSTALFactory.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/ExclusiveAccessSTALFactory.java
new file mode 100644
index 00000000..1dee8e2b
--- /dev/null
+++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/ExclusiveAccessSTALFactory.java
@@ -0,0 +1,65 @@
+/*
+* Copyright 2009 Federal Chancellery Austria and
+* Graz University of Technology
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package at.gv.egiz.bku.local.stal;
+
+import java.util.Locale;
+
+import at.gv.egiz.stal.STAL;
+import at.gv.egiz.stal.STALFactory;
+
+public class ExclusiveAccessSTALFactory implements STALFactory {
+
+ private STALFactory stalFactory;
+
+ private ExclusiveAccessSTAL stal;
+
+ private Locale locale;
+
+ /**
+ * @return the stalFactory
+ */
+ public STALFactory getStalFactory() {
+ return stalFactory;
+ }
+
+ /**
+ * @param stalFactory the stalFactory to set
+ */
+ public synchronized void setStalFactory(STALFactory stalFactory) {
+ this.stalFactory = stalFactory;
+ stalFactory.setLocale(locale);
+ }
+
+ @Override
+ public synchronized STAL createSTAL() {
+ if (stal == null && stalFactory != null) {
+ STAL delegate = stalFactory.createSTAL();
+ stal = new ExclusiveAccessSTAL(delegate);
+ }
+ return stal;
+ }
+
+ @Override
+ public synchronized void setLocale(Locale locale) {
+ this.locale = locale;
+ if (stalFactory != null) {
+ stalFactory.setLocale(locale);
+ }
+ }
+
+}
diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalBKUWorker.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalBKUWorker.java
index 1e3f9a1d..d2e49039 100644
--- a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalBKUWorker.java
+++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalBKUWorker.java
@@ -49,7 +49,7 @@ public class LocalBKUWorker extends AbstractBKUWorker {
public List<STALResponse> handleRequest(List<? extends STALRequest> requestList) {
signatureCard = null;
List<STALResponse> responses = super.handleRequest(requestList);
- container.setVisible(false);
+ container.setVisible(false);
return responses;
}
diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSTALFactory.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSTALFactory.java
index 44322a07..a703ad5c 100644
--- a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSTALFactory.java
+++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSTALFactory.java
@@ -19,7 +19,6 @@ package at.gv.egiz.bku.local.stal;
import at.gv.egiz.bku.viewer.ResourceFontLoader;
import java.awt.Dimension;
import java.awt.Toolkit;
-import java.net.MalformedURLException;
import java.util.Locale;
@@ -31,10 +30,11 @@ import at.gv.egiz.bku.local.gui.GUIProxy;
import at.gv.egiz.bku.local.gui.LocalHelpListener;
import at.gv.egiz.stal.STAL;
import at.gv.egiz.stal.STALFactory;
-import java.net.URL;
import javax.swing.JFrame;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+
+import org.apache.commons.configuration.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Creates a PINManagementGUI and a LocalBKUWorker, which in turn registers
@@ -44,55 +44,45 @@ import org.apache.commons.logging.LogFactory;
*/
public class LocalSTALFactory implements STALFactory {
- protected static final Log log = LogFactory.getLog(LocalSTALFactory.class);
+ private final Logger log = LoggerFactory.getLogger(LocalSTALFactory.class);
protected static final Dimension PREFERRED_SIZE = new Dimension(318, 200);
protected String helpURL;
protected Locale locale;
+
+ protected Configuration configuration;
+
+
@Override
public STAL createSTAL() {
- LocalBKUWorker stal;
+ final LocalBKUWorker stal;
//http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html
// use undecorated JFrame instead of JWindow,
// which creates an invisible owning frame and therefore cannot getFocusInWindow()
JFrame dialog = new JFrame("Bürgerkarte");
- if (log.isTraceEnabled()) {
- log.debug("alwaysOnTop supported: " + dialog.isAlwaysOnTopSupported());
- }
+ log.debug("AlwaysOnTop supported: {}.", dialog.isAlwaysOnTopSupported());
// [#439] make mocca dialog alwaysOnTop
dialog.setAlwaysOnTop(true);
dialog.setIconImages(BKUIcons.icons);
- dialog.setUndecorated(true);
+// dialog.setUndecorated(true);
// dialog.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
-// dialog.addWindowListener(new WindowAdapter() {
-//
-// @Override
-// public void windowClosing(WindowEvent e) {
-// super.windowClosing(e);
-// log.debug("closing window ********************");
-// }
-//
-// });
+
if (locale != null) {
dialog.setLocale(locale);
}
LocalHelpListener helpListener = null;
- try {
- if (helpURL != null) {
- helpListener = new LocalHelpListener(new URL(helpURL), locale);
- } else {
- log.warn("no HELP URL configured, help system disabled");
- }
- } catch (MalformedURLException ex) {
- log.error("failed to configure help listener: " + ex.getMessage(), ex);
+ if (helpURL != null) {
+ helpListener = new LocalHelpListener(helpURL, locale);
+ } else {
+ log.warn("No HELP URL configured, help system disabled.");
}
PINManagementGUIFacade gui = new PINManagementGUI(dialog.getContentPane(),
dialog.getLocale(),
BKUGUIFacade.Style.advanced,
null,
new ResourceFontLoader(),
- helpListener,
+ helpListener,
null);
BKUGUIFacade proxy = (BKUGUIFacade) GUIProxy.newInstance(gui, dialog, new Class[] { PINManagementGUIFacade.class} );
stal = new LocalBKUWorker(proxy, dialog);
@@ -116,11 +106,26 @@ public class LocalSTALFactory implements STALFactory {
this.locale = locale;
}
- public String getHelpURL() {
- return helpURL;
- }
-
+ /**
+ * spring injects helpURL
+ * @param helpURL
+ */
public void setHelpURL(String helpURL) {
this.helpURL = helpURL;
}
+
+ /**
+ * @return the configuration
+ */
+ public Configuration getConfiguration() {
+ return configuration;
+ }
+
+ /**
+ * @param configuration the configuration to set
+ */
+ public void setConfiguration(Configuration configuration) {
+ this.configuration = configuration;
+ }
+
}
diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSecureViewer.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSecureViewer.java
index ae58526c..749a455a 100644
--- a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSecureViewer.java
+++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSecureViewer.java
@@ -31,8 +31,8 @@ import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
*
@@ -40,8 +40,8 @@ import org.apache.commons.logging.LogFactory;
*/
public class LocalSecureViewer implements SecureViewer {
- private static final Log log = LogFactory.getLog(LocalSignRequestHandler.class);
- private List<HashDataInput> hashDataInputs = Collections.EMPTY_LIST;
+ private final Logger log = LoggerFactory.getLogger(LocalSignRequestHandler.class);
+ private List<HashDataInput> hashDataInputs = Collections.emptyList();
protected BKUGUIFacade gui;
@@ -63,8 +63,8 @@ public class LocalSecureViewer implements SecureViewer {
ActionListener okListener, String okCommand)
throws Exception {
if (signedInfo.getReference().size() == 0) {
- log.error("No hashdata input selected to be displayed: null");
- throw new Exception("No HashData Input selected to be displayed");
+ log.error("No hashdata input selected to be displayed: null.");
+ throw new Exception("No HashData Input selected to be displayed.");
}
ArrayList<HashDataInput> selectedHashDataInputs = new ArrayList<HashDataInput>();
@@ -76,8 +76,8 @@ public class LocalSecureViewer implements SecureViewer {
boolean hdiAvailable = false;
for (HashDataInput hashDataInput : hashDataInputs) {
if (dsigRefId.equals(hashDataInput.getReferenceId())) {
- log.debug("display hashdata input for dsig:SignedReference " +
- dsigRefId);
+ log.debug("Display hashdata input for dsig:SignedReference {}.",
+ dsigRefId);
selectedHashDataInputs.add(
ensureCachedHashDataInput(hashDataInput));
hdiAvailable = true;
@@ -85,7 +85,7 @@ public class LocalSecureViewer implements SecureViewer {
}
}
if (!hdiAvailable) {
- log.error("no hashdata input for dsig:SignedReference " + dsigRefId);
+ log.error("No hashdata input for dsig:SignedReference {}.", dsigRefId);
throw new Exception(
"No HashDataInput available for dsig:SignedReference " + dsigRefId);
}
@@ -97,8 +97,8 @@ public class LocalSecureViewer implements SecureViewer {
}
if (selectedHashDataInputs.size() < 1) {
- log.error("dsig:SignedInfo does not contain a data reference");
- throw new Exception("dsig:SignedInfo does not contain a data reference");
+ log.error("dsig:SignedInfo does not contain a data reference.");
+ throw new Exception("dsig:SignedInfo does not contain a data reference.");
}
gui.showSecureViewer(selectedHashDataInputs, okListener, okCommand);
}
@@ -108,7 +108,7 @@ public class LocalSecureViewer implements SecureViewer {
throws IOException {
if (!(hashDataInput instanceof DataObjectHashDataInput)) {
- log.warn("expected DataObjectHashDataInput for LocalSignRequestHandler, got " +
+ log.warn("Expected DataObjectHashDataInput for LocalSignRequestHandler, got {}.",
hashDataInput.getClass().getName());
InputStream hdIs = hashDataInput.getHashDataInput();
diff --git a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java
index 9ae1d9b9..a1f77a85 100644
--- a/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java
+++ b/BKULocal/src/main/java/at/gv/egiz/bku/local/stal/LocalSignRequestHandler.java
@@ -16,8 +16,8 @@
*/
package at.gv.egiz.bku.local.stal;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import at.gv.egiz.bku.smccstal.SignRequestHandler;
import at.gv.egiz.stal.ErrorResponse;
@@ -31,7 +31,7 @@ import at.gv.egiz.stal.SignRequest;
*/
public class LocalSignRequestHandler extends SignRequestHandler {
- private static final Log log = LogFactory.getLog(LocalSignRequestHandler.class);
+ private final Logger log = LoggerFactory.getLogger(LocalSignRequestHandler.class);
public LocalSignRequestHandler(LocalSecureViewer secureViewer) {
super(secureViewer);
@@ -44,7 +44,6 @@ public class LocalSignRequestHandler extends SignRequestHandler {
* @param request
* @return
*/
- @SuppressWarnings("unchecked")
@Override
public STALResponse handleRequest(STALRequest request)
throws InterruptedException {
@@ -54,7 +53,7 @@ public class LocalSignRequestHandler extends SignRequestHandler {
((LocalSecureViewer) secureViewer).setDataToBeSigned(signReq.getHashDataInput());
return super.handleRequest(request);
} else {
- log.fatal("Got unexpected STAL request: " + request);
+ log.error("Got unexpected STAL request: {}.", request);
return new ErrorResponse(1000);
}