Add TLS client certificate configuration option in XMPP wizard (Patch by Stefan Sieber)

cusax-fix
Ingo Bauersachs 14 years ago
parent 3c25b96887
commit 9ec95536ec

@ -12,8 +12,8 @@
import javax.swing.*;
import javax.swing.event.*;
import net.java.sip.communicator.service.certificate.*;
import net.java.sip.communicator.plugin.desktoputil.*;
import org.jitsi.util.*;
/**
@ -105,6 +105,11 @@ public class ConnectionPanel
*/
private JTextField dtmfMinimalToneDurationValue = new JTextField();
private final JLabel certificateLabel = new JLabel(
Resources.getString("plugin.sipaccregwizz.CLIENT_CERTIFICATE"));
private final JComboBox certificate = new JComboBox();
private final JabberAccountRegistrationForm parentForm;
/**
@ -171,9 +176,12 @@ public void actionPerformed(ActionEvent e)
labelsAdvOpPanel.add(serverLabel);
labelsAdvOpPanel.add(portLabel);
labelsAdvOpPanel.add(certificateLabel);
valuesAdvOpPanel.add(serverField);
valuesAdvOpPanel.add(portField);
valuesAdvOpPanel.add(certificate);
initCertificateAliases(null);
serverOpPanel.add(serverAutoCheckBox, BorderLayout.NORTH);
serverOpPanel.add(labelsAdvOpPanel, BorderLayout.WEST);
@ -622,4 +630,51 @@ void enablesServerAutoConfigure(boolean isEnable)
portField.setEnabled(isEnable);
parentForm.reValidateInput();
}
/**
* Sets the client TLS certificate ID.
* @param certificateId The ID of the TLS certificate to use or
* <tt>null</tt> if none should be selected.
*/
public void setClientTlsCertificateId(String certificateId)
{
initCertificateAliases(certificateId);
}
/**
* Gets the ID of the selected client TLS certificate or <tt>null</tt> if no
* certificate is selected.
*
* @return the ID of the selected client TLS certificate or <tt>null</tt> if
* no certificate is selected.
*/
String getClientTlsCertificateId()
{
if(certificate.getSelectedItem() != null
&& certificate.getSelectedItem() instanceof CertificateConfigEntry)
return ((CertificateConfigEntry)certificate.getSelectedItem())
.getId();
return null;
}
/**
* Initializes the certificate combo box with certificate names
*
* @param id ID of the selected certificate
* (can be null if no certificate is selected).
*/
private void initCertificateAliases(String id)
{
certificate.removeAllItems();
certificate.insertItemAt(
Resources.getString("plugin.sipaccregwizz.NO_CERTIFICATE"), 0);
certificate.setSelectedIndex(0);
for(CertificateConfigEntry e : JabberAccRegWizzActivator
.getCertificateService().getClientAuthCertificateConfigs())
{
certificate.addItem(e);
if(e.getId().equals(id))
certificate.setSelectedItem(e);
}
}
}

@ -9,6 +9,7 @@
import java.util.*;
import net.java.sip.communicator.service.browserlauncher.*;
import net.java.sip.communicator.service.certificate.*;
import net.java.sip.communicator.service.credentialsstorage.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.protocol.*;
@ -42,6 +43,8 @@ public class JabberAccRegWizzActivator
private static CredentialsStorageService credentialsService = null;
private static CertificateService certService;
private static WizardContainer wizardContainer;
private static JabberAccountRegistrationWizard jabberWizard;
@ -193,6 +196,26 @@ public static ConfigurationService getConfigurationService()
return configService;
}
/**
* Returns the <tt>CertificateService</tt> obtained from the bundle
* context.
* @return the <tt>CertificateService</tt> obtained from the bundle
* context
*/
public static CertificateService getCertificateService()
{
if (certService == null)
{
ServiceReference serviceReference = bundleContext
.getServiceReference(CertificateService.class.getName());
certService = (CertificateService)bundleContext
.getService(serviceReference);
}
return certService;
}
/**
* Indicates if the advanced account configuration is currently disabled.
*

@ -222,6 +222,11 @@ public class JabberAccountRegistration
*/
private String dtmfMinimalToneDuration = DEFAULT_MINIMAL_DTMF_TONE_DURATION;
/**
* The client TLS certificate ID.
*/
private String clientCertificateId = null;
/**
* Initializes a new JabberAccountRegistration.
*/
@ -943,4 +948,22 @@ public void setEncodingProperties(Map<String, String> encodingProperties)
{
this.encodingProperties = encodingProperties;
}
/**
* Sets the client certificate configuration entry ID.
* @param clientCertificateId the client certificate configuration entry ID.
*/
public void setClientCertificateId(String clientCertificateId)
{
this.clientCertificateId = clientCertificateId;
}
/**
* Gets the client certificate configuration entry ID.
* @returns the client certificate configuration entry ID.
*/
public String getClientCertificateId()
{
return clientCertificateId;
}
}

@ -295,6 +295,8 @@ public boolean commitPage(JabberAccountRegistration registration)
registration.setUserID(userID);
registration.setPassword(new String(password));
registration.setRememberPassword(accountPanel.isRememberPassword());
registration.setClientCertificateId(
connectionPanel.getClientTlsCertificateId());
registration.setServerAddress(serverAddress);
registration.setServerOverridden(connectionPanel.isServerOverridden());
registration.setSendKeepAlive(connectionPanel.isSendKeepAlive());
@ -393,6 +395,9 @@ public void loadAccount(AccountID accountID)
connectionPanel.setServerAddress(serverAddress);
connectionPanel.setClientTlsCertificateId(
accountID.getAccountPropertyString(ProtocolProviderFactory.CLIENT_TLS_CERTIFICATE));
String serverPort
= accountProperties.get(ProtocolProviderFactory.SERVER_PORT);

@ -368,6 +368,19 @@ protected ProtocolProviderService installAccount(
String smsServerAddress = registration.getSmsServerAddress();
String clientCertId = registration.getClientCertificateId();
if(clientCertId != null)
{
accountProperties.put(
ProtocolProviderFactory.CLIENT_TLS_CERTIFICATE,
clientCertId);
}
else
{
accountProperties.remove(
ProtocolProviderFactory.CLIENT_TLS_CERTIFICATE);
}
if (smsServerAddress != null)
{
accountProperties.put( ProtocolProviderFactory.SMS_SERVER_ADDRESS,

@ -7,6 +7,7 @@ System-Bundle: yes
Export-package: net.java.sip.communicator.plugin.jabberaccregwizz
Import-Package: org.osgi.framework,
net.java.sip.communicator.service.browserlauncher,
net.java.sip.communicator.service.certificate,
org.jitsi.service.configuration,
net.java.sip.communicator.service.credentialsstorage,
net.java.sip.communicator.service.contactlist,

Loading…
Cancel
Save