protected void initialise()

in taverna-wsdl-activity-ui/src/main/java/org/apache/taverna/activities/wsdl/views/WSDLActivityConfigurationView.java [98:299]


	protected void initialise() {
		super.initialise();

		int gridy = 0;

		// title panel
		JPanel titlePanel = new JPanel(new BorderLayout());
		titlePanel.setBackground(Color.WHITE);
		JLabel titleLabel = new JLabel("Security configuration");
		titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 13.5f));
		titleLabel.setBorder(new EmptyBorder(10, 10, 0, 10));
		DialogTextArea titleMessage = new DialogTextArea(
				"Select a security profile for the service");
		titleMessage.setMargin(new Insets(5, 20, 10, 10));
		titleMessage.setFont(titleMessage.getFont().deriveFont(11f));
		titleMessage.setEditable(false);
		titleMessage.setFocusable(false);
		titlePanel.setBorder(new EmptyBorder(10, 10, 0, 10));
		titlePanel.add(titleLabel, BorderLayout.NORTH);
		titlePanel.add(titleMessage, BorderLayout.CENTER);
		addDivider(titlePanel, SwingConstants.BOTTOM, true);

		// Main panel
		JPanel mainPanel = new JPanel();
		mainPanel.setLayout(new GridBagLayout());
		mainPanel.setBorder(new EmptyBorder(10, 10, 10, 10));

		// Create the radio buttons
		noSecurityRadioButton = new JRadioButton("None");
		noSecurityRadioButton.addItemListener(this);

		wsSecurityAuthNRadioButton = new JRadioButton(
				"WS-Security username and password authentication");
		wsSecurityAuthNRadioButton.addItemListener(this);

		httpSecurityAuthNRadioButton = new JRadioButton("HTTP username and password authentication");
		httpSecurityAuthNRadioButton.addItemListener(this);

		// Group the radio buttons
		buttonGroup = new ButtonGroup();
		buttonGroup.add(noSecurityRadioButton);
		buttonGroup.add(wsSecurityAuthNRadioButton);
		buttonGroup.add(httpSecurityAuthNRadioButton);

		GridBagConstraints gbc = new GridBagConstraints();
		gbc.weightx = 1.0;
		gbc.weighty = 0.0;

		gbc.gridx = 0;
		gbc.gridy = gridy++;
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gbc.insets = new Insets(5, 10, 0, 0);
		mainPanel.add(noSecurityRadioButton, gbc);

		noSecurityLabel = new JLabel("Service requires no security");
		noSecurityLabel.setFont(noSecurityLabel.getFont().deriveFont(11f));
		// addDivider(noSecurityLabel, SwingConstants.BOTTOM, false);
		gbc.gridx = 0;
		gbc.gridy = gridy++;
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.anchor = GridBagConstraints.WEST;
		gbc.insets = new Insets(0, 40, 10, 10);
		mainPanel.add(noSecurityLabel, gbc);

		gbc.gridx = 0;
		gbc.gridy = gridy++;
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gbc.insets = new Insets(5, 10, 0, 0);
		mainPanel.add(httpSecurityAuthNRadioButton, gbc);

		ActionListener usernamePasswordListener = new ActionListener() {

			public void actionPerformed(ActionEvent e) {
				// Get Credential Manager UI to get the username and password for the service
				if (credManagerUI == null) {
					credManagerUI = new CredentialManagerUI(credentialManager);
				}
				credManagerUI.newPasswordForService(URI.create(getJson().get("operation")
						.get("wsdl").textValue()));
			}
		};

		httpSecurityAuthNLabel = new JLabel(
				"Service requires HTTP username and password in order to authenticate the user");
		httpSecurityAuthNLabel.setFont(httpSecurityAuthNLabel.getFont().deriveFont(11f));
		gbc.gridx = 0;
		gbc.gridy = gridy++;
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.anchor = GridBagConstraints.WEST;
		gbc.insets = new Insets(0, 40, 10, 10);
		mainPanel.add(httpSecurityAuthNLabel, gbc);

		// Set username and password button;
		setHttpUsernamePasswordButton = new JButton("Set username and password");
		gbc.gridx = 0;
		gbc.gridy = gridy++;
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.EAST;
		gbc.insets = new Insets(0, 40, 10, 10);
		gbc.weightx = 1.0;
		gbc.weighty = 1.0; // add any vertical space to this component
		mainPanel.add(setHttpUsernamePasswordButton, gbc);
		setHttpUsernamePasswordButton.addActionListener(usernamePasswordListener);

		gbc.gridx = 0;
		gbc.gridy = gridy++;
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gbc.insets = new Insets(5, 10, 0, 0);
		mainPanel.add(wsSecurityAuthNRadioButton, gbc);

		wsSecurityAuthNLabel = new JLabel(
				"Service requires WS-Security username and password in order to authenticate the user");
		wsSecurityAuthNLabel.setFont(wsSecurityAuthNLabel.getFont().deriveFont(11f));
		gbc.gridx = 0;
		gbc.gridy = gridy++;
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.anchor = GridBagConstraints.WEST;
		gbc.insets = new Insets(0, 40, 0, 0);
		mainPanel.add(wsSecurityAuthNLabel, gbc);

		// Password type list
		passwordTypeComboBox = new JComboBox<>(passwordTypes);
		passwordTypeComboBox.setRenderer(new ComboBoxTooltipRenderer());
		gbc.gridx = 0;
		gbc.gridy = gridy++;
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gbc.insets = new Insets(10, 40, 0, 0);
		mainPanel.add(passwordTypeComboBox, gbc);

		// 'Add timestamp' checkbox
		addTimestampCheckBox = new JCheckBox("Add a timestamp to SOAP message");
		gbc.gridx = 0;
		gbc.gridy = gridy++;
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.WEST;
		gbc.insets = new Insets(5, 40, 10, 10);
		mainPanel.add(addTimestampCheckBox, gbc);

		// Set username and password button;
		setWsdlUsernamePasswordButton = new JButton("Set username and password");
		gbc.gridx = 0;
		gbc.gridy = gridy++;
		gbc.fill = GridBagConstraints.NONE;
		gbc.anchor = GridBagConstraints.EAST;
		gbc.insets = new Insets(0, 40, 10, 10);
		gbc.weightx = 1.0;
		gbc.weighty = 1.0; // add any vertical space to this component
		mainPanel.add(setWsdlUsernamePasswordButton, gbc);
		setWsdlUsernamePasswordButton.addActionListener(usernamePasswordListener);

		addDivider(mainPanel, SwingConstants.BOTTOM, true);

		// Enable/disable controls based on what is the current security profiles
		if (!getJson().has("securityProfile")) {
			noSecurityRadioButton.setSelected(true);
		} else {
			URI securityProfile = URI.create(getJson().get("securityProfile").textValue());
			if (securityProfile.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_PLAINTEXTPASSWORD)
					|| securityProfile
							.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_DIGESTPASSWORD)
					|| securityProfile
							.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTEXTPASSWORD)
					|| securityProfile
							.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD)) {
				wsSecurityAuthNRadioButton.setSelected(true);
			}
			if (securityProfile.equals(SecurityProfiles.HTTP_BASIC_AUTHN)
					|| securityProfile.equals(SecurityProfiles.HTTP_DIGEST_AUTHN)) {
				httpSecurityAuthNRadioButton.setSelected(true);
			}
			if (securityProfile.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_PLAINTEXTPASSWORD)
					|| securityProfile
							.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTEXTPASSWORD)) {
				passwordTypeComboBox.setSelectedItem(PLAINTEXT_PASSWORD);
			} else if (securityProfile
					.equals(SecurityProfiles.WSSECURITY_USERNAMETOKEN_DIGESTPASSWORD)
					|| securityProfile
							.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD)) {
				passwordTypeComboBox.setSelectedItem(DIGEST_PASSWORD);
			}
			if (securityProfile
					.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_DIGESTPASSWORD)
					|| securityProfile
							.equals(SecurityProfiles.WSSECURITY_TIMESTAMP_USERNAMETOKEN_PLAINTEXTPASSWORD)) {
				addTimestampCheckBox.setSelected(true);
			} else {
				addTimestampCheckBox.setSelected(false);
			}
		}

		// Put everything together
		JPanel layoutPanel = new JPanel(new BorderLayout());
		layoutPanel.add(titlePanel, BorderLayout.NORTH);
		layoutPanel.add(mainPanel, BorderLayout.CENTER);
		layoutPanel.setPreferredSize(new Dimension(550, 400));

		add(layoutPanel);
	}