Skip to content

Commit

Permalink
Merge pull request #885 from stokito/login
Browse files Browse the repository at this point in the history
Remove LoginDialog
  • Loading branch information
Plyha authored Oct 17, 2024
2 parents 65f647e + 8669fc3 commit 35cd2a3
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 1,761 deletions.
1,634 changes: 0 additions & 1,634 deletions core/src/main/java/org/jivesoftware/LoginDialog.java

This file was deleted.

128 changes: 66 additions & 62 deletions core/src/main/java/org/jivesoftware/gui/LoginUIPanel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
/**
* Copyright (C) 2004-2011 Jive Software. All rights reserved.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.gui;

Expand Down Expand Up @@ -108,6 +118,8 @@
import org.jivesoftware.spark.util.*;

import static org.jivesoftware.spark.util.StringUtils.modifyWildcards;
import static org.jivesoftware.sparkimpl.certificates.SparkSSLContextCreator.Options.BOTH;
import static org.jivesoftware.sparkimpl.certificates.SparkSSLContextCreator.Options.ONLY_SERVER_SIDE;

import org.jivesoftware.spark.util.log.Log;
import org.jivesoftware.sparkimpl.certificates.CertificateModel;
Expand All @@ -130,7 +142,8 @@
import org.minidns.record.A;

/**
*
* Dialog to log in a user into the XMPP server.
* The LoginDialog is used only for login in registered users into the XMPP server.
* @author KeepToo
*/
public class LoginUIPanel extends javax.swing.JPanel implements KeyListener, ActionListener, FocusListener, CallbackHandler {
Expand Down Expand Up @@ -561,8 +574,7 @@ private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
try {
BrowserLauncher.openURL(url);
} catch (Exception e) {
Log.error("Unable to load password "
+ "reset.", e);
Log.error("Unable to load password reset.", e);
}
}//GEN-LAST:event_btnResetActionPerformed

Expand Down Expand Up @@ -681,11 +693,13 @@ protected XMPPTCPConnectionConfiguration retrieveConnectionConfiguration() {

int checkForPort = loginServer.indexOf(":");
if (checkForPort != -1) {
String portString = loginServer.substring(checkForPort + 1);
if (ModelUtil.hasLength(portString)) {
if (checkForPort != loginServer.length() - 2) { // : at end of string, so no port
String portString = loginServer.substring(checkForPort + 1);
// Set new port.
port = Integer.valueOf(portString);
port = Integer.parseInt(portString);
}
// strip the port from loginServer hostname
loginServer = loginServer.substring(0, checkForPort);
}

ConnectionConfiguration.SecurityMode securityMode = localPref.getSecurityMode();
Expand Down Expand Up @@ -735,9 +749,6 @@ protected XMPPTCPConnectionConfiguration retrieveConnectionConfiguration() {
.setCompressionEnabled(localPref.isCompressionEnabled())
.setSecurityMode(securityMode);

if (securityMode != ConnectionConfiguration.SecurityMode.disabled && localPref.isDisableHostnameVerification()) {
TLSUtils.disableHostnameVerificationForTlsCertificates(builder);
}
if (localPref.isDebuggerEnabled()) {
builder.enableDefaultDebugger();
}
Expand All @@ -749,55 +760,7 @@ protected XMPPTCPConnectionConfiguration retrieveConnectionConfiguration() {
if (localPref.isProxyEnabled()) {
builder.setProxyInfo(proxyInfo);
}

if (securityMode != ConnectionConfiguration.SecurityMode.disabled && !useDirectTls) {
// This use STARTTLS which starts initially plain connection to upgrade it to TLS, it use the same port as
// plain connections which is 5222.
SparkSSLContextCreator.Options options;
if (localPref.isAllowClientSideAuthentication()) {
options = SparkSSLContextCreator.Options.BOTH;
} else {
options = SparkSSLContextCreator.Options.ONLY_SERVER_SIDE;
}
try {
SSLContext context = SparkSSLContextCreator.setUpContext(options);
builder.setSslContextFactory(() -> { return context; });
builder.setSecurityMode(securityMode);
builder.setCustomX509TrustManager(new SparkTrustManager());
} catch (NoSuchAlgorithmException | KeyManagementException | UnrecoverableKeyException | KeyStoreException | NoSuchProviderException e) {
Log.warning("Couldnt establish secured connection", e);
}
}

if (securityMode != ConnectionConfiguration.SecurityMode.disabled && useDirectTls) {
if (!hostPortConfigured) {
// SMACK 4.1.9 does not support XEP-0368, and does not apply a port change, if the host is not changed too.
// Here, we force the host to be set (by doing a DNS lookup), and force the port to 5223 (which is the
// default 'old-style' SSL port).
DnsName serverNameDnsName = DnsName.from(loginServer);
java.util.List<InetAddress> resolvedAddresses = DNSUtil.getDNSResolver().lookupHostAddress(serverNameDnsName, null, DnssecMode.disabled);
if (resolvedAddresses.isEmpty()) {
throw new RuntimeException("Could not resolve " + serverNameDnsName);
}
builder.setHost(resolvedAddresses.get(0).getHostName());
builder.setPort(5223);
}
SparkSSLContextCreator.Options options;
if (localPref.isAllowClientSideAuthentication()) {
options = SparkSSLContextCreator.Options.BOTH;
} else {
options = SparkSSLContextCreator.Options.ONLY_SERVER_SIDE;
}
builder.setSocketFactory(new SparkSSLSocketFactory(options));
// SMACK 4.1.9 does not recognize an 'old-style' SSL socket as being secure, which will cause a failure when
// the 'required' Security Mode is defined. Here, we work around this by replacing that security mode with an
// 'if-possible' setting.
builder.setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible);
}

if (securityMode != ConnectionConfiguration.SecurityMode.disabled) {
SASLAuthentication.registerSASLMechanism(new SASLExternalMechanism());
}
configureConnectionTls(builder, securityMode, useDirectTls, hostPortConfigured, loginServer);

// SPARK-1747: Don't use the GSS-API SASL mechanism when SSO is disabled.
SASLAuthentication.unregisterSASLMechanism(SASLGSSAPIMechanism.class.getName());
Expand Down Expand Up @@ -828,6 +791,47 @@ protected XMPPTCPConnectionConfiguration retrieveConnectionConfiguration() {
return builder.build();
}

private void configureConnectionTls(XMPPTCPConnectionConfiguration.Builder builder, ConnectionConfiguration.SecurityMode securityMode, boolean useDirectTls, boolean hostPortConfigured, String serverName) {
if (securityMode != ConnectionConfiguration.SecurityMode.disabled) {
if (localPref.isDisableHostnameVerification()) {
TLSUtils.disableHostnameVerificationForTlsCertificates(builder);
}
if (!useDirectTls) {
// This use STARTTLS which starts initially plain connection to upgrade it to TLS.
// It will use the same port as plain connections which is 5222.
SparkSSLContextCreator.Options options = localPref.isAllowClientSideAuthentication() ? BOTH : ONLY_SERVER_SIDE;
try {
SSLContext context = SparkSSLContextCreator.setUpContext(options);
builder.setSslContextFactory(() -> context);
builder.setSecurityMode(securityMode);
builder.setCustomX509TrustManager(new SparkTrustManager());
} catch (NoSuchAlgorithmException | KeyManagementException | UnrecoverableKeyException | KeyStoreException | NoSuchProviderException e) {
Log.warning("Could not establish secured connection", e);
}
} else { // useDirectTls
if (!hostPortConfigured) {
// SMACK 4.1.9 does not support XEP-0368, and does not apply a port change, if the host is not changed too.
// Here, we force the host to be set (by doing a DNS lookup), and force the port to 5223 (which is the
// default 'old-style' SSL port).
DnsName serverNameDnsName = DnsName.from(serverName);
List<InetAddress> resolvedAddresses = DNSUtil.getDNSResolver().lookupHostAddress(serverNameDnsName, null, DnssecMode.disabled);
if (resolvedAddresses.isEmpty()) {
throw new RuntimeException("Could not resolve " + serverNameDnsName);
}
builder.setHost(resolvedAddresses.get(0).getHostName());
builder.setPort(5223);
}
SparkSSLContextCreator.Options options = localPref.isAllowClientSideAuthentication() ? BOTH : ONLY_SERVER_SIDE;
builder.setSocketFactory(new SparkSSLSocketFactory(options));
// SMACK 4.1.9 does not recognize an 'old-style' SSL socket as being secure, which will cause a failure when
// the 'required' Security Mode is defined. Here, we work around this by replacing that security mode with an
// 'if-possible' setting.
builder.setSecurityMode(ConnectionConfiguration.SecurityMode.ifpossible);
}
SASLAuthentication.registerSASLMechanism(new SASLExternalMechanism());
}
}

/**
* Returns the username the user defined.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,16 @@
*/
package org.jivesoftware.spark.component;

import org.jivesoftware.resource.Default;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.geom.AffineTransform;

import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

/**
* <code>TitlePanel</code> class is the top panel displayed in this application.
Expand Down Expand Up @@ -128,28 +119,5 @@ public final void setDescription(String desc) {
}
descriptionLabel.setText(desc);
}

public static class ImagePanel extends JPanel {

private static final long serialVersionUID = 5155908601530113727L;
final ImageIcon icons = Default.getImageIcon(Default.SECONDARY_BACKGROUND_IMAGE);

public ImagePanel() {

}

public ImagePanel(LayoutManager layout) {
super(layout);
}

@Override
public void paintComponent(Graphics g) {
Image backgroundImage = icons.getImage();
double scaleX = getWidth() / (double) backgroundImage.getWidth(null);
double scaleY = getHeight() / (double) backgroundImage.getHeight(null);
AffineTransform xform = AffineTransform.getScaleInstance(scaleX, scaleY);
((Graphics2D) g).drawImage(backgroundImage, xform, this);
}
}

}
59 changes: 28 additions & 31 deletions core/src/main/java/org/jivesoftware/spark/util/BrowserLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,32 @@

public class BrowserLauncher {

public static void openURL(String url) throws Exception {
if (url.startsWith("http") || url.startsWith("ftp") || url.startsWith("file") || url.startsWith("www")) {

if (url.startsWith("file") && url.contains(" ")) {
url = url.replace(" ", "%20");
}
if (url.startsWith("www")) {
url = "http://" + url;
}
try
{
Desktop.getDesktop().browse(new URI(url));
}
catch(Exception ex)
{
Runtime.getRuntime().exec("xdg-open " + url);

}

} else {
File f = new File(url);
if (f.exists() && Desktop.isDesktopSupported()){
try {
Desktop.getDesktop().open(f);
} catch (Exception ex){
if (!url.toLowerCase().startsWith("//")) url = "//" + url;
Desktop.getDesktop().browse(new URI("http:" + url));
}
}
}
}
public static void openURL(String url) throws Exception {
if (url.startsWith("http") || url.startsWith("ftp") || url.startsWith("file") || url.startsWith("www")) {
if (url.startsWith("file") && url.contains(" ")) {
url = url.replace(" ", "%20");
}
if (url.startsWith("www")) {
url = "http://" + url;
}
try {
Desktop.getDesktop().browse(new URI(url));
} catch (Exception ex) {
// fallback on Linux
Runtime.getRuntime().exec("xdg-open " + url);
}
} else {
File f = new File(url);
if (f.exists() && Desktop.isDesktopSupported()) {
try {
Desktop.getDesktop().open(f);
} catch (Exception ex) {
if (!url.startsWith("//")) {
url = "//" + url;
}
Desktop.getDesktop().browse(new URI("http:" + url));
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Arrays;

import org.apache.commons.lang3.reflect.ConstructorUtils;
import org.jivesoftware.LoginDialog;
import org.jivesoftware.gui.LoginUIPanel;
import org.jivesoftware.smackx.muc.MultiUserChat;
import org.jivesoftware.spark.ButtonFactory;
Expand Down
1 change: 0 additions & 1 deletion core/src/main/resources/default.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ USER_DIRECTORY_MAC = Library/Application Support/Spark

LOGIN_DIALOG_BACKGROUND_IMAGE = images/login_dialog_background.png
TOP_BOTTOM_BACKGROUND_IMAGE = images/top_bottom_background_image.png
SECONDARY_BACKGROUND_IMAGE = images/steel.png

# Specify a fixed Hostname
# Changing the Hostname will also be prohibited if set
Expand Down
Binary file removed core/src/main/resources/images/steel.png
Binary file not shown.

0 comments on commit 35cd2a3

Please sign in to comment.