Skip to main content
summaryrefslogtreecommitdiffstats
blob: 14d5a23a885c63d8fec6ae07f2d7353226f2d0e3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*******************************************************************************
 * Copyright (c) 2003, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.jst.ws.internal.consumption.ui.wsil;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jst.ws.internal.consumption.ui.ConsumptionUIMessages;
import org.eclipse.jst.ws.internal.consumption.ui.plugin.WebServiceConsumptionUIPlugin;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.PlatformUI;
import org.eclipse.wst.ws.internal.parser.wsil.WWWAuthenticationException;
import org.eclipse.wst.ws.internal.parser.wsil.WWWAuthenticationHandler;


public class DialogWWWAuthentication extends Dialog implements WWWAuthenticationHandler
{

  /*CONTEXT_ID DBAS0001 for the HTTP basic authentication user name*/
  private final String INFOPOP_DBAS_USERNAME = WebServiceConsumptionUIPlugin.ID + ".DBAS0001";

  /*CONTEXT_ID DBAS0002 for the HTTP basic authentication password*/
  private final String INFOPOP_DBAS_PASSWORD = WebServiceConsumptionUIPlugin.ID + ".DBAS0002";

  private String usernameString_;
  private String passwordString_;

  private Text username_;
  private Text password_;

  private WWWAuthenticationException wwwae_;

  public DialogWWWAuthentication(Shell shell)
  {
    super(shell);
    usernameString_ = null;
    passwordString_ = null;
    wwwae_ = null;
  }

  /**
  * Called when the Cancel button is pressed.
  */
  protected void cancelPressed()
  {
    usernameString_ = null;
    passwordString_ = null;
    super.cancelPressed();
  }

  /**
  * Called when the OK button is pressed.
  */
  protected void okPressed()
  {
    String usernameString = username_.getText();
    usernameString_ = (usernameString.length() > 0) ? usernameString : null;
    String passwordString = password_.getText();
    passwordString_ = (passwordString.length() > 0) ? passwordString : null;
    setReturnCode(Dialog.OK);
    super.okPressed();
  }

  /**
  * See {@link org.eclipse.jface.window.Window#configureShell}.
  * @param shell The shell.
  */
  protected void configureShell(Shell shell)
  {
    super.configureShell(shell);
    shell.setText(ConsumptionUIMessages.DIALOG_TITLE_HTTP_BASIC_AUTH);
  }

  /** 
  * Creates the dialog area.
  * @param parent The parent composite.
  * @return The control area.
  */
  protected Control createDialogArea(Composite parent)
  {
    Composite composite = (Composite)super.createDialogArea(parent);
    GridData gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL | GridData.GRAB_VERTICAL);
    gd.widthHint = 400;
    gd.grabExcessVerticalSpace = true;
    gd.grabExcessHorizontalSpace = true;
    composite.setLayoutData(gd);
    GridLayout gl = new GridLayout();
    gl.numColumns = 2;
    gl.verticalSpacing = 15;
    composite.setLayout(gl);

    Label label = new Label(composite, SWT.WRAP);
    label.setText(ConsumptionUIMessages.LABEL_URL);
    label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    label = new Label(composite, SWT.WRAP);
    label.setText(wwwae_.getURL());
    label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    label = new Label(composite, SWT.WRAP);
    label.setText(ConsumptionUIMessages.LABEL_HTTP_BASIC_AUTH_USERNAME);
    label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    username_ = new Text(composite, SWT.BORDER);
    username_.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    username_.setToolTipText(ConsumptionUIMessages.TOOLTIP_HTTP_BASIC_AUTH_USERNAME);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(username_, INFOPOP_DBAS_USERNAME);

    label = new Label(composite, SWT.WRAP);
    label.setText(ConsumptionUIMessages.LABEL_HTTP_BASIC_AUTH_PASSWORD);
    label.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    password_ = new Text(composite, SWT.BORDER);
    password_.setEchoChar('*');
    password_.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    password_.setToolTipText(ConsumptionUIMessages.TOOLTIP_HTTP_BASIC_AUTH_PASSWORD);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(username_, INFOPOP_DBAS_PASSWORD);

    return composite;
  }

  public void handleWWWAuthentication(WWWAuthenticationException wwwae)
  {
    usernameString_ = null;
    passwordString_ = null;
    wwwae_ = wwwae;
    open();
  }

  public String getUsername()
  {
    return usernameString_;
  }

  public String getPassword()
  {
    return passwordString_;
  }
}

Back to the top