Author: koen.aers(a)jboss.com
Date: 2009-12-01 18:32:31 -0500 (Tue, 01 Dec 2009)
New Revision: 18960
Added:
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/common/util/Base64Converter.java
Modified:
trunk/jbpm/plugins/org.jbpm.gd.jpdl/plugin.xml
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/jpdl/deployment/DeploymentForm.java
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/jpdl/prefs/ServerDeploymentPage.java
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/jpdl/util/ProcessDeployer.java
Log:
GPD-381
Modified: trunk/jbpm/plugins/org.jbpm.gd.jpdl/plugin.xml
===================================================================
--- trunk/jbpm/plugins/org.jbpm.gd.jpdl/plugin.xml 2009-12-01 23:06:15 UTC (rev 18959)
+++ trunk/jbpm/plugins/org.jbpm.gd.jpdl/plugin.xml 2009-12-01 23:32:31 UTC (rev 18960)
@@ -358,7 +358,11 @@
class="org.jbpm.gd.jpdl.prefs.AssignmentTypesPage"
id="org.jbpm.gd.jpdl.prefs.assignmentTypes"
name="Assignment Types"
- category="org.jbpm.gd.jpdl.prefs.jbpm3"/>
+ category="org.jbpm.gd.jpdl.prefs.jbpm3">
+ <enablement>
+ <systemProperty name="MyTestProperty"
value="puppy"/>
+ </enablement>
+ </page>
<page
class="org.jbpm.gd.jpdl.prefs.ServerDeploymentPage"
id="org.jbpm.gd.jpdl.prefs.deployment"
Added:
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/common/util/Base64Converter.java
===================================================================
--- trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/common/util/Base64Converter.java
(rev 0)
+++
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/common/util/Base64Converter.java 2009-12-01
23:32:31 UTC (rev 18960)
@@ -0,0 +1,75 @@
+package org.jbpm.gd.common.util;
+
+public class Base64Converter {
+
+ public static final char[] alphabet = {
+ 'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H',
+ 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X',
+ 'Y', 'Z', 'a', 'b', 'c', 'd',
'e', 'f',
+ 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n',
+ 'o', 'p', 'q', 'r', 's', 't',
'u', 'v',
+ 'w', 'x', 'y', 'z', '0', '1',
'2', '3',
+ '4', '5', '6', '7', '8', '9',
'+', '/' };
+
+ public static String encode(String s) {
+ return encode(s.getBytes());
+ }
+
+ public static String encode(byte[] octetString) {
+ int bits24;
+ int bits6;
+
+ char[] out = new char[((octetString.length - 1) / 3 + 1) * 4];
+
+ int outIndex = 0;
+ int i = 0;
+
+ while ((i + 3) <= octetString.length) {
+ // store the octets
+ bits24 = (octetString[i++] & 0xFF) << 16;
+ bits24 |= (octetString[i++] & 0xFF) << 8;
+ bits24 |= (octetString[i++] & 0xFF) << 0;
+
+ bits6 = (bits24 & 0x00FC0000) >> 18;
+ out[outIndex++] = alphabet[bits6];
+ bits6 = (bits24 & 0x0003F000) >> 12;
+ out[outIndex++] = alphabet[bits6];
+ bits6 = (bits24 & 0x00000FC0) >> 6;
+ out[outIndex++] = alphabet[bits6];
+ bits6 = (bits24 & 0x0000003F);
+ out[outIndex++] = alphabet[bits6];
+ }
+
+ if (octetString.length - i == 2) {
+ // store the octets
+ bits24 = (octetString[i] & 0xFF) << 16;
+ bits24 |= (octetString[i + 1] & 0xFF) << 8;
+
+ bits6 = (bits24 & 0x00FC0000) >> 18;
+ out[outIndex++] = alphabet[bits6];
+ bits6 = (bits24 & 0x0003F000) >> 12;
+ out[outIndex++] = alphabet[bits6];
+ bits6 = (bits24 & 0x00000FC0) >> 6;
+ out[outIndex++] = alphabet[bits6];
+
+ // padding
+ out[outIndex++] = '=';
+ } else if (octetString.length - i == 1) {
+ // store the octets
+ bits24 = (octetString[i] & 0xFF) << 16;
+
+ bits6 = (bits24 & 0x00FC0000) >> 18;
+ out[outIndex++] = alphabet[bits6];
+ bits6 = (bits24 & 0x0003F000) >> 12;
+ out[outIndex++] = alphabet[bits6];
+
+ // padding
+ out[outIndex++] = '=';
+ out[outIndex++] = '=';
+ }
+
+ return new String(out);
+ }
+
+}
\ No newline at end of file
Property changes on:
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/common/util/Base64Converter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/jpdl/deployment/DeploymentForm.java
===================================================================
---
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/jpdl/deployment/DeploymentForm.java 2009-12-01
23:06:15 UTC (rev 18959)
+++
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/jpdl/deployment/DeploymentForm.java 2009-12-01
23:32:31 UTC (rev 18960)
@@ -46,11 +46,13 @@
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Tree;
@@ -84,11 +86,14 @@
private Text portText;
private Text deployerText;
private Text locationText;
+ private Text usernameText;
+ private Text passwordText;
private Button deployButton;
private Button saveButton;
private Button locationButton;
private Button testConnectionButton;
private Button saveLocallyButton;
+ private Button useCredentialsButton;
private IncludeInDeploymentTreeViewer includeFilesTreeViewer;
private IncludeInDeploymentTreeViewer includeClassesTreeViewer;
@@ -143,6 +148,11 @@
result.setServerName(nameText.getText());
result.setServerPort(portText.getText());
result.setServerDeployer(deployerText.getText());
+ result.setUseCredentials(useCredentialsButton.getSelection());
+ if (useCredentialsButton.getSelection()) {
+ result.setUsername(usernameText.getText() == null ? "" :
usernameText.getText());
+ result.setPassword(passwordText.getText() == null ? "" :
passwordText.getText());
+ }
result.setShell(form.getShell());
result.setProcessFolder(processFolder);
result.setFilesAndFolders(getIncludedFiles());
@@ -223,6 +233,8 @@
createServerNameField(serverInfoFormClient);
createServerPortField(serverInfoFormClient);
createServerDeployerField(serverInfoFormClient);
+ createUseCredentialsButton(serverInfoFormClient);
+ createUseCredentialsGroup(serverInfoFormClient);
createTestConnectionButton(serverInfoFormClient);
}
@@ -281,6 +293,51 @@
});
}
+ private void createUserNameField(Composite composite) {
+ Label usernameLabel = toolkit.createLabel(composite, "Username:");
+ usernameLabel.setForeground(toolkit.getColors().getColor(FormColors.TITLE));
+ usernameText = toolkit.createText(composite, "");
+ String usernameString = Plugin.getDefault().getPreferenceStore().getString("user
name");
+ usernameText.setText(usernameString == null ? "" : usernameString);
+ usernameText.setEnabled(useCredentialsButton.getSelection());
+ usernameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ }
+
+ private void createPasswordField(Composite composite) {
+ Label passwordLabel = toolkit.createLabel(composite, "Password:");
+ passwordLabel.setForeground(toolkit.getColors().getColor(FormColors.TITLE));
+ passwordText = toolkit.createText(composite, "", SWT.PASSWORD);
+ String passwordString =
Plugin.getDefault().getPreferenceStore().getString("password");
+ passwordText.setText(passwordString == null ? "" : passwordString);
+ passwordText.setEnabled(useCredentialsButton.getSelection());
+ passwordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ }
+
+ private void createUseCredentialsButton(Composite infoFormClient) {
+ useCredentialsButton = toolkit.createButton(infoFormClient, "Use
credentials", SWT.CHECK);
+ useCredentialsButton.setForeground(toolkit.getColors().getColor(FormColors.TITLE));
+ useCredentialsButton.setSelection(Plugin.getDefault().getPreferenceStore().getBoolean("use
credentials"));
+ GridData gridData = new GridData();
+ gridData.horizontalSpan = 3;
+ useCredentialsButton.setLayoutData(gridData);
+ useCredentialsButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ usernameText.setEnabled(useCredentialsButton.getSelection());
+ passwordText.setEnabled(useCredentialsButton.getSelection());
+ }
+ });
+ }
+
+ private void createUseCredentialsGroup(Composite infoFormClient) {
+ Composite useCredentialsGroup = toolkit.createComposite(infoFormClient, SWT.BORDER);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.horizontalSpan = 3;
+ useCredentialsGroup.setLayoutData(gridData);
+ useCredentialsGroup.setLayout(new GridLayout(2, false));
+ createUserNameField(useCredentialsGroup);
+ createPasswordField(useCredentialsGroup);
+ }
+
private void createTestConnectionButton(Composite infoFormClient) {
testConnectionButton = toolkit.createButton(infoFormClient, "Test
Connection...", SWT.PUSH);
testConnectionButton.addSelectionListener(new SelectionAdapter() {
Modified:
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/jpdl/prefs/ServerDeploymentPage.java
===================================================================
---
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/jpdl/prefs/ServerDeploymentPage.java 2009-12-01
23:06:15 UTC (rev 18959)
+++
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/jpdl/prefs/ServerDeploymentPage.java 2009-12-01
23:32:31 UTC (rev 18960)
@@ -23,10 +23,15 @@
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench;
@@ -36,7 +41,8 @@
public class ServerDeploymentPage extends PreferencePage implements
IWorkbenchPreferencePage, Constants {
- private Text nameText, portText, deployerText;
+ private Text nameText, portText, deployerText, usernameText, passwordText;
+ private Button useCredentialsCheckbox;
public ServerDeploymentPage() {
super();
@@ -45,14 +51,59 @@
protected Control createContents(Composite parent) {
Composite clientArea = createClientArea(parent);
- createNameField(clientArea);
- createPortField(clientArea);
- createDeployerField(clientArea);
+ createServerNameField(clientArea);
+ createServerPortField(clientArea);
+ createServerDeployerField(clientArea);
+ createServerCredentialsCheckBox(clientArea);
+ createServerCredentialsGroup(clientArea);
return null;
}
- private void createNameField(Composite parent) {
+ private void createServerCredentialsGroup(Composite parent) {
+ Group serverCredentialsGroup = new Group(parent, SWT.BORDER);
+ serverCredentialsGroup.setLayout(new GridLayout(2, false));
+ createUserNameField(serverCredentialsGroup);
+ createUserPasswordField(serverCredentialsGroup);
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ data.horizontalSpan = 2;
+ serverCredentialsGroup.setLayoutData(data);
+ }
+
+ private void createUserNameField(Composite parent) {
Label nameLabel = new Label(parent, SWT.NORMAL);
+ nameLabel.setText("Username:");
+ String username = getPreferenceStore().getString("user name");
+ usernameText = new Text(parent, SWT.BORDER);
+ usernameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ usernameText.setText(useCredentialsCheckbox.getSelection() ? username : "");
+ }
+
+ private void createUserPasswordField(Composite parent) {
+ Label passwordLabel = new Label(parent, SWT.NORMAL);
+ passwordLabel.setText("Password:");
+ String password = getPreferenceStore().getString("password");
+ passwordText = new Text(parent, SWT.PASSWORD | SWT.BORDER);
+ passwordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ passwordText.setText(useCredentialsCheckbox.getSelection() ? password : "");
+ }
+
+ private void createServerCredentialsCheckBox(Composite parent) {
+ useCredentialsCheckbox = new Button(parent, SWT.CHECK);
+ useCredentialsCheckbox.setText("Use credentials");
+ useCredentialsCheckbox.setSelection(getPreferenceStore().getBoolean("use
credentials"));
+ GridData data = new GridData(GridData.FILL_HORIZONTAL);
+ data.horizontalSpan = 2;
+ useCredentialsCheckbox.setLayoutData(data);
+ useCredentialsCheckbox.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ usernameText.setEnabled(useCredentialsCheckbox.getSelection());
+ passwordText.setEnabled(useCredentialsCheckbox.getSelection());
+ }
+ });
+ }
+
+ private void createServerNameField(Composite parent) {
+ Label nameLabel = new Label(parent, SWT.NORMAL);
nameLabel.setText("Server name:");
nameText = new Text(parent, SWT.BORDER);
String serverName = getPreferenceStore().getString("server name");
@@ -60,7 +111,7 @@
nameText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
- private void createPortField(Composite parent) {
+ private void createServerPortField(Composite parent) {
Label portLabel = new Label(parent, SWT.NORMAL);
portLabel.setText("Server port:");
portText = new Text(parent, SWT.BORDER);
@@ -69,7 +120,7 @@
portText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
- private void createDeployerField(Composite parent) {
+ private void createServerDeployerField(Composite parent) {
Label deployerLabel = new Label(parent, SWT.NORMAL);
deployerLabel.setText("Server deployer:");
deployerText = new Text(parent, SWT.BORDER);
@@ -95,6 +146,9 @@
getPreferenceStore().setValue("server name", nameText.getText());
getPreferenceStore().setValue("server port", portText.getText());
getPreferenceStore().setValue("server deployer", deployerText.getText());
+ getPreferenceStore().setValue("use credentials",
useCredentialsCheckbox.getSelection());
+ getPreferenceStore().setValue("user name",
useCredentialsCheckbox.getSelection() ? usernameText.getText() : "");
+ getPreferenceStore().setValue("password",
useCredentialsCheckbox.getSelection() ? passwordText.getText() : "");
return true;
}
@@ -102,9 +156,15 @@
nameText.setText("localhost");
portText.setText("8080");
deployerText.setText("jbpm-console/upload");
+ useCredentialsCheckbox.setSelection(false);
+ usernameText.setText(null);
+ passwordText.setText(null);
getPreferenceStore().setValue("server name", "localhost");
getPreferenceStore().setValue("server port", "8080");
getPreferenceStore().setValue("server deployer",
"jbpm-console/upload");
+ getPreferenceStore().setValue("use credentials", false);
+ getPreferenceStore().setValue("user name", "");
+ getPreferenceStore().setValue("password", "");
}
}
Modified:
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/jpdl/util/ProcessDeployer.java
===================================================================
---
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/jpdl/util/ProcessDeployer.java 2009-12-01
23:06:15 UTC (rev 18959)
+++
trunk/jbpm/plugins/org.jbpm.gd.jpdl/src/org/jbpm/gd/jpdl/util/ProcessDeployer.java 2009-12-01
23:32:31 UTC (rev 18960)
@@ -3,6 +3,7 @@
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
@@ -33,6 +34,7 @@
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Shell;
+import org.jbpm.gd.common.util.Base64Converter;
import org.jbpm.gd.jpdl.Logger;
import org.jbpm.gd.jpdl.Plugin;
@@ -48,6 +50,9 @@
String targetLocation;
List classesAndResources;
List filesAndFolders;
+ boolean useCredentials = false;
+ String username;
+ String password;
public void setShell(Shell shell) {
this.shell = shell;
@@ -81,6 +86,18 @@
this.filesAndFolders = filesAndFolders;
}
+ public void setUseCredentials(boolean useCredentials) {
+ this.useCredentials = useCredentials;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
public boolean deploy() {
try {
showProgressMonitorDialog();
@@ -94,6 +111,18 @@
dialog.open();
return false;
}
+ catch (IOException e) {
+ if (e.getMessage().contains("Server returned HTTP response code: 403 for
URL")) {
+ MessageDialog dialog = new MessageDialog(shell, "Not Allowed", null,
+ "The server refused to perform the deployment. Check your credentials.",
+ SWT.ICON_INFORMATION, new String[] { "OK" }, 0);
+ dialog.open();
+ return false;
+ } else {
+ showErrorDialog(e);
+ return false;
+ }
+ }
catch (Exception e) {
// NOTE that Error's are not caught because that might halt the JVM and
mask the original Error.
showErrorDialog(e);
@@ -103,7 +132,8 @@
public void pingServer() {
try {
- URL url = new URL("http://" + serverName + ":" + serverPort +
serverDeployer);
+ String urlStr = "http://" + serverName + ":" + serverPort +
serverDeployer;
+ URL url = new URL(urlStr);
URLConnection urlConnection = url.openConnection();
urlConnection.setDoOutput(true);
InputStream inputStream = urlConnection.getInputStream();
@@ -123,6 +153,12 @@
SWT.ICON_INFORMATION, new String[] { "OK" }, 0);
dialog.open();
}
+ catch (FileNotFoundException e) {
+ MessageDialog dialog = new MessageDialog(shell, "Connection Test", null,
+ "The server can be reached, but the deployer seems unavailable.",
+ SWT.ICON_INFORMATION, new String[] { "OK" }, 0);
+ dialog.open();
+ }
catch (Exception e) {
Logger.logError(e);
ErrorDialog dialog = new ErrorDialog(shell,
@@ -170,6 +206,12 @@
}
deployProcessWithServlet(baos);
return;
+ } catch (IOException e) {
+ if (e.getMessage().contains("Server returned HTTP response code: 403 for
URL")) {
+ Logger.logError(
+ "The server refused to execute the deployment. Check your
credentials.",
+ e);
+ }
} catch (Exception e) {
Logger
.logError(
@@ -193,8 +235,14 @@
}
private void deployProcessWithServlet(byte[] parBytes) throws Exception {
- URL url = new URL("http://" + serverName + ":" + serverPort +
serverDeployer);
+ String urlStr = "http://" + serverName + ":" + serverPort +
serverDeployer;
+ URL url = new URL(urlStr);
URLConnection urlConnection = url.openConnection();
+ if (useCredentials) {
+ String userPassword = username + ":" + password;
+ String encoding = Base64Converter.encode(userPassword);
+ urlConnection.setRequestProperty ("Authorization", "Basic" +
encoding);
+ }
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);