diff options
author | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-07-24 14:57:49 +0000 |
---|---|---|
committer | tkellner <tkellner@174cde9d-5d70-4d2a-aa98-46368bc2aaf7> | 2013-07-24 14:57:49 +0000 |
commit | a52b66cf1d0a579b95cddba44fb4df0e97bf8e22 (patch) | |
tree | 684815b87698872b68d5bfd357a4320dbf38e752 /pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow | |
parent | 7b4a747d8a922cb03c8019249217dbf3ff68302a (diff) | |
download | mocca-a52b66cf1d0a579b95cddba44fb4df0e97bf8e22.tar.gz mocca-a52b66cf1d0a579b95cddba44fb4df0e97bf8e22.tar.bz2 mocca-a52b66cf1d0a579b95cddba44fb4df0e97bf8e22.zip |
Add proxy authentication
git-svn-id: https://joinup.ec.europa.eu/svn/pdf-over/trunk@465 174cde9d-5d70-4d2a-aa98-46368bc2aaf7
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow')
8 files changed, 367 insertions, 89 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigManipulator.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigManipulator.java index 58b9e453..68b48242 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigManipulator.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigManipulator.java @@ -76,6 +76,18 @@ public interface ConfigManipulator { public void setProxyPort(int port); /** + * Sets the proxy username + * @param user the proxy username + */ + public void setProxyUser(String user); + + /** + * Sets the proxy password + * @param pass the proxy password + */ + public void setProxyPass(String pass); + + /** * Sets the default output folder * @param outputFolder the default output folder */ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigOverlayManipulator.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigOverlayManipulator.java index 952116ec..e3fec9f5 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigOverlayManipulator.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigOverlayManipulator.java @@ -61,6 +61,18 @@ public interface ConfigOverlayManipulator { public void setProxyPortOverlay(int port); /** + * Sets the proxy username + * @param user the proxy username + */ + public void setProxyUserOverlay(String user); + + /** + * Sets the proxy password + * @param pass the proxy password + */ + public void setProxyPassOverlay(String pass); + + /** * Sets the default output folder * @param outputFolder the default output folder */ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProvider.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProvider.java index 1adf39e4..91bd5ecf 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProvider.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProvider.java @@ -85,6 +85,18 @@ public interface ConfigProvider { public int getProxyPort(); /** + * Gets the proxy username + * @return the proxy username + */ + public String getProxyUser(); + + /** + * Gets the proxy password + * @return the proxy password + */ + public String getProxyPass(); + + /** * Get the default configured BKU * @return the default configured BKU */ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java index 3225c92d..3010868b 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigProviderImpl.java @@ -101,6 +101,14 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, this.setProxyHost(config .getProperty(Constants.CFG_PROXY_HOST)); + // Set Proxy User + this.setProxyUser(config + .getProperty(Constants.CFG_PROXY_USER)); + + // Set Proxy Password + this.setProxyPass(config + .getProperty(Constants.CFG_PROXY_PASS)); + // Set Output Folder this.setDefaultOutputFolder(config .getProperty(Constants.CFG_OUTPUT_FOLDER)); @@ -279,6 +287,8 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, props.setProperty(Constants.CFG_PROXY_HOST, this.getProxyHostPersistent()); props.setProperty(Constants.CFG_PROXY_PORT, Integer.toString(getProxyPortPersistent())); + props.setProperty(Constants.CFG_PROXY_USER, this.getProxyUserPersistent()); + props.setProperty(Constants.CFG_PROXY_PASS, this.getProxyPassPersistent()); props.setProperty(Constants.CFG_EMBLEM, this.getDefaultEmblemPersistent()); props.setProperty(Constants.CFG_SIGNATURE_NOTE, this.getSignatureNote()); props.setProperty(Constants.CFG_MOBILE_NUMBER, this.getDefaultMobileNumberPersistent()); @@ -758,6 +768,104 @@ public class ConfigProviderImpl implements ConfigProvider, ConfigManipulator, return this.configuration.getProxyPort(); } + /** + * Sets the proxy username + * + * @param user + * the proxy username + */ + @Override + public void setProxyUser(String user) { + if (user == null || user.trim().isEmpty()) { + this.configuration.setProxyUser(STRING_EMPTY); + } else { + this.configuration.setProxyUser(user); + } + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.config.ConfigOverlayManipulator#setProxyUserOverlay(java.lang.String) + */ + @Override + public void setProxyUserOverlay(String user) { + if (user == null || user.trim().isEmpty()) { + this.configurationOverlay.setProxyUser(STRING_EMPTY); + } else { + this.configurationOverlay.setProxyUser(user); + } + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.config.ConfigProvider#getProxyUser() + */ + @Override + public String getProxyUser() { + String user = this.configurationOverlay.getProxyUser(); + if (user == null) + user = getProxyUserPersistent(); + return user; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.config.PersistentConfigProvider#getProxyUserPersistent() + */ + @Override + public String getProxyUserPersistent() { + String user = this.configuration.getProxyUser(); + if (user == null) + user = STRING_EMPTY; + return user; + } + + /** + * Sets the proxy password + * + * @param pass + * the proxy password + */ + @Override + public void setProxyPass(String pass) { + if (pass == null || pass.trim().isEmpty()) { + this.configuration.setProxyPass(STRING_EMPTY); + } else { + this.configuration.setProxyPass(pass); + } + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.config.ConfigOverlayManipulator#setProxyPassOverlay(java.lang.String) + */ + @Override + public void setProxyPassOverlay(String pass) { + if (pass == null || pass.trim().isEmpty()) { + this.configurationOverlay.setProxyPass(STRING_EMPTY); + } else { + this.configurationOverlay.setProxyPass(pass); + } + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.config.ConfigProvider#getProxyPass() + */ + @Override + public String getProxyPass() { + String pass = this.configurationOverlay.getProxyPass(); + if (pass == null) + pass = getProxyPassPersistent(); + return pass; + } + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.config.PersistentConfigProvider#getProxyPassPersistent() + */ + @Override + public String getProxyPassPersistent() { + String pass = this.configuration.getProxyPass(); + if (pass == null) + pass = STRING_EMPTY; + return pass; + } + /* * (non-Javadoc) * diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java index 383f5e9b..486647cc 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainer.java @@ -81,18 +81,6 @@ public interface ConfigurationContainer { public void setProxyHost(String host); /** - * Gets the signature note - * @return the signature note - */ - public String getSignatureNote(); - - /** - * Sets the signature note - * @param note the signature note - */ - public void setSignatureNote(String note); - - /** * Gets the proxy port * * if port is -1 no port is selected @@ -112,6 +100,42 @@ public interface ConfigurationContainer { public void setProxyPort(int port) throws InvalidPortException; /** + * Gets the proxy username + * @return the proxy username + */ + public String getProxyUser(); + + /** + * Sets the proxy username + * @param user the proxy username + */ + public void setProxyUser(String user); + + /** + * Gets the proxy password + * @return the proxy password + */ + public String getProxyPass(); + + /** + * Sets the proxy password + * @param pass the proxy password + */ + public void setProxyPass(String pass); + + /** + * Gets the signature note + * @return the signature note + */ + public String getSignatureNote(); + + /** + * Sets the signature note + * @param note the signature note + */ + public void setSignatureNote(String note); + + /** * Gets the transparency of the placeholder * @return transparency of the placeholder (0-255) */ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainerImpl.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainerImpl.java index d878f59e..ec79b403 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainerImpl.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationContainerImpl.java @@ -54,31 +54,37 @@ public class ConfigurationContainerImpl implements ConfigurationContainer { /** The mobile phone number */ protected String mobileNumber = null; - + /** The mobile phone password */ protected String mobilePassword = null; - - /** Holds the proxy Host */ + + /** Holds the proxy host */ protected String proxyHost = null; - - /** Holds the signatureNote */ - protected String signatureNote = null; - + /** Holds the proxy port number */ protected int proxyPort = -1; - + + /** Holds the proxy username */ + protected String proxyUser = null; + + /** Holds the proxy password */ + protected String proxyPass = null; + + /** Holds the signatureNote */ + protected String signatureNote = null; + /** Holds the locale */ protected Locale locale = null; - + /** Holds the signature locale */ protected Locale signLocale = null; - + /** Holds the output folder */ protected String folder = null; - + /** Holds the default BKU to use */ protected BKUs defaultBKU = BKUs.NONE; - + /** Holds the automatic positioning value */ protected boolean automaticPositioning = false; @@ -225,6 +231,42 @@ public class ConfigurationContainerImpl implements ConfigurationContainer { /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.config.ConfigurationContainer#getProxyUser() + */ + @Override + public String getProxyUser() { + return this.proxyUser; + } + + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.config.ConfigurationContainer#setProxyUser(java.lang.String) + */ + @Override + public void setProxyUser(String user) { + this.proxyUser = user; + } + + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.config.ConfigurationContainer#getProxyPass() + */ + @Override + public String getProxyPass() { + return this.proxyPass; + } + + + /* (non-Javadoc) + * @see at.asit.pdfover.gui.workflow.config.ConfigurationContainer#setProxyPass(java.lang.String) + */ + @Override + public void setProxyPass(String pass) { + this.proxyPass = pass; + } + + + /* (non-Javadoc) * @see at.asit.pdfover.gui.workflow.ConfigurationContainer#getPlaceholderTransparency() */ @Override diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/PersistentConfigProvider.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/PersistentConfigProvider.java index ea2c97b1..fe4fceb3 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/PersistentConfigProvider.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/PersistentConfigProvider.java @@ -52,7 +52,7 @@ public interface PersistentConfigProvider { * @return the emblem */ public String getDefaultEmblemPersistent(); - + /** * Gets the proxy host * @return the proxy hostname or ip address @@ -66,6 +66,18 @@ public interface PersistentConfigProvider { public int getProxyPortPersistent(); /** + * Gets the proxy username + * @return the proxy username + */ + public String getProxyUserPersistent(); + + /** + * Gets the proxy password + * @return the proxy password + */ + public String getProxyPassPersistent(); + + /** * Gets the default output folder for signed documents * @return the default output folder */ diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java index d0e9bdfe..ad0658c5 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareSigningState.java @@ -16,6 +16,9 @@ package at.asit.pdfover.gui.workflow.states; //Imports +import java.net.Authenticator; +import java.net.PasswordAuthentication; + import org.eclipse.swt.SWT; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,7 +39,8 @@ import at.asit.pdfover.signator.SignatureParameter; import at.asit.pdfover.signator.Signer; /** - * User waiting state, wait for PDF Signator library to prepare document for signing. + * User waiting state, wait for PDF Signator library to prepare document for + * signing. */ public class PrepareSigningState extends State { @@ -48,97 +52,145 @@ public class PrepareSigningState extends State { } private final class PrepareDocumentThread implements Runnable { - + private PrepareSigningState state; - + /** * Default constructor + * * @param state */ public PrepareDocumentThread(PrepareSigningState state) { this.state = state; } - + @Override public void run() { try { - + Status status = this.state.stateMachine.getStatus(); - - ConfigProvider configuration = this.state.stateMachine.getConfigProvider(); - + + ConfigProvider configuration = this.state.stateMachine + .getConfigProvider(); + // SET PROXY HOST and PORT settings - String proxyHost = configuration.getProxyHost(); - int proxyPort = configuration.getProxyPort(); - - if(proxyPort > 0 && proxyPort <= 0xFFFF) { - System.setProperty("http.proxyPort", Integer.toString(proxyPort)); //$NON-NLS-1$ - System.setProperty("https.proxyPort", Integer.toString(proxyPort)); //$NON-NLS-1$ - } - - if(proxyHost != null && !proxyHost.isEmpty()) { + final String proxyHost = configuration.getProxyHost(); + final int proxyPort = configuration.getProxyPort(); + final String proxyUser = configuration.getProxyUser(); + final String proxyPass = configuration.getProxyPass(); + + if (proxyPort > 0 && proxyPort <= 0xFFFF) { + System.setProperty( + "http.proxyPort", Integer.toString(proxyPort)); //$NON-NLS-1$ + System.setProperty( + "https.proxyPort", Integer.toString(proxyPort)); //$NON-NLS-1$ + } + + if (proxyHost != null && !proxyHost.isEmpty()) { System.setProperty("http.proxyHost", proxyHost); //$NON-NLS-1$ System.setProperty("https.proxyHost", proxyHost); //$NON-NLS-1$ - } - - if(this.state.signer == null) { - this.state.signer = this.state.stateMachine.getPDFSigner().getPDFSigner(); } - - if(this.state.signatureParameter == null) { - this.state.signatureParameter = this.state.signer.newParameter(); + + if (proxyUser != null && !proxyUser.isEmpty()) { + System.setProperty("http.proxyUser", proxyUser); //$NON-NLS-1$ + System.setProperty("https.proxyUser", proxyUser); //$NON-NLS-1$ + } + + if (proxyPass != null && !proxyPass.isEmpty()) { + System.setProperty("http.proxyPassword", proxyPass); //$NON-NLS-1$ + System.setProperty("https.proxyPassword", proxyPass); //$NON-NLS-1$ + } + + if (proxyUser != null && !proxyUser.isEmpty() && + proxyPass != null && !proxyPass.isEmpty()) { + Authenticator.setDefault(new Authenticator() { + /* (non-Javadoc) + * @see java.net.Authenticator#getPasswordAuthentication() + */ + @Override + protected PasswordAuthentication getPasswordAuthentication() { + if (getRequestorType() == RequestorType.PROXY) { + if (getRequestingHost().equalsIgnoreCase(proxyHost) && + (getRequestingPort() == proxyPort)) { + return new PasswordAuthentication(proxyUser, + proxyPass.toCharArray()); + } + } + return super.getPasswordAuthentication(); + } + }); + } + if (this.state.signer == null) { + this.state.signer = this.state.stateMachine.getPDFSigner() + .getPDFSigner(); } - - this.state.signatureParameter.setInputDocument(new PDFFileDocumentSource(status.getDocument())); - this.state.signatureParameter.setSignatureDevice(status.getBKU()); - this.state.signatureParameter.setSignaturePosition(status.getSignaturePosition()); - - if(configuration.getDefaultEmblem() != null && !configuration.getDefaultEmblem().isEmpty()) { - this.state.signatureParameter.setEmblem(new FileNameEmblem(configuration.getDefaultEmblem())); + + if (this.state.signatureParameter == null) { + this.state.signatureParameter = this.state.signer + .newParameter(); + } + + this.state.signatureParameter + .setInputDocument(new PDFFileDocumentSource(status + .getDocument())); + this.state.signatureParameter.setSignatureDevice(status + .getBKU()); + this.state.signatureParameter.setSignaturePosition(status + .getSignaturePosition()); + + if (configuration.getDefaultEmblem() != null + && !configuration.getDefaultEmblem().isEmpty()) { + this.state.signatureParameter.setEmblem(new FileNameEmblem( + configuration.getDefaultEmblem())); } - - if(configuration.getSignatureNote() != null && !configuration.getSignatureNote().isEmpty()) { - this.state.signatureParameter.setProperty("SIG_NOTE", configuration.getSignatureNote()); //$NON-NLS-1$ + + if (configuration.getSignatureNote() != null + && !configuration.getSignatureNote().isEmpty()) { + this.state.signatureParameter.setProperty( + "SIG_NOTE", configuration.getSignatureNote()); //$NON-NLS-1$ } - - this.state.signatureParameter.setSignatureLanguage(configuration.getSignLocale().getLanguage()); - - this.state.signingState = this.state.signer.prepare(this.state.signatureParameter); - + + this.state.signatureParameter + .setSignatureLanguage(configuration.getSignLocale() + .getLanguage()); + + this.state.signingState = this.state.signer + .prepare(this.state.signatureParameter); + } catch (Exception e) { log.error("PrepareDocumentThread: ", e); //$NON-NLS-1$ this.state.threadException = e; - } - finally { + } finally { this.state.stateMachine.invokeUpdate(); } } } - + /** * SFL4J Logger instance **/ - static final Logger log = LoggerFactory.getLogger(PrepareSigningState.class); - + static final Logger log = LoggerFactory + .getLogger(PrepareSigningState.class); + SignatureParameter signatureParameter; - + private WaitingComposite waitingComposite = null; private WaitingComposite getSelectionComposite() { if (this.waitingComposite == null) { - this.waitingComposite = - this.stateMachine.getGUIProvider().createComposite(WaitingComposite.class, SWT.RESIZE, this); + this.waitingComposite = this.stateMachine.getGUIProvider() + .createComposite(WaitingComposite.class, SWT.RESIZE, this); } return this.waitingComposite; } - - at.asit.pdfover.signator.SigningState signingState = null; + + at.asit.pdfover.signator.SigningState signingState = null; Signer signer; - + Exception threadException = null; - + @Override public void run() { WaitingComposite waiting = this.getSelectionComposite(); @@ -149,22 +201,23 @@ public class PrepareSigningState extends State { Status status = this.stateMachine.getStatus(); - if(this.signatureParameter == null) { - this.signatureParameter = this.signer.newParameter(); + if (this.signatureParameter == null) { + this.signatureParameter = this.signer.newParameter(); } - if(this.signingState == null && this.threadException == null) { + if (this.signingState == null && this.threadException == null) { Thread t = new Thread(new PrepareDocumentThread(this)); t.start(); return; } - if(this.threadException != null) { - ErrorDialog error = new ErrorDialog(this.stateMachine.getGUIProvider().getMainShell(), - Messages.getString("error.PrepareDocument"), //$NON-NLS-1$ + if (this.threadException != null) { + ErrorDialog error = new ErrorDialog(this.stateMachine + .getGUIProvider().getMainShell(), + Messages.getString("error.PrepareDocument"), //$NON-NLS-1$ BUTTONS.RETRY_CANCEL); this.threadException = null; - if(error.open() == SWT.RETRY) { + if (error.open() == SWT.RETRY) { run(); } else { this.setNextState(new BKUSelectionState(this.stateMachine)); @@ -174,10 +227,10 @@ public class PrepareSigningState extends State { // We got the Request set it into status and move on to next state ... status.setSigningState(this.signingState); - - if(this.stateMachine.getStatus().getBKU() == BKUs.LOCAL) { + + if (this.stateMachine.getStatus().getBKU() == BKUs.LOCAL) { this.setNextState(new LocalBKUState(this.stateMachine)); - } else if(this.stateMachine.getStatus().getBKU() == BKUs.MOBILE) { + } else if (this.stateMachine.getStatus().getBKU() == BKUs.MOBILE) { this.setNextState(new MobileBKUState(this.stateMachine)); } else { log.error("Invalid selected BKU Value \"NONE\" in PrepareSigningState!"); //$NON-NLS-1$ @@ -185,7 +238,8 @@ public class PrepareSigningState extends State { } } - /* (non-Javadoc) + /* + * (non-Javadoc) * @see at.asit.pdfover.gui.workflow.states.State#cleanUp() */ @Override @@ -194,12 +248,14 @@ public class PrepareSigningState extends State { this.waitingComposite.dispose(); } - /* (non-Javadoc) + /* + * (non-Javadoc) * @see at.asit.pdfover.gui.workflow.states.State#setMainWindowBehavior() */ @Override public void updateMainWindowBehavior() { - MainWindowBehavior behavior = this.stateMachine.getStatus().getBehavior(); + MainWindowBehavior behavior = this.stateMachine.getStatus() + .getBehavior(); behavior.reset(); behavior.setActive(Buttons.OPEN, true); behavior.setActive(Buttons.POSITION, true); |