Creates authenticate windows service that will create the dialog and will show it to user used with different impl on android and desktop.

Expose some common functionality in httputil and reuse it in xcap implementation in sip provider.
Wraps sslSocketFactory to use the constructor that is common for android and desktop httpclient lib.
Creates separate bundle for httpclient libs in order to separate it from httputil bundle which will be used in android.
cusax-fix
Damian Minkov 13 years ago
parent 76631ca877
commit e35e4a7974

@ -13,7 +13,7 @@
<classpathentry kind="lib" path="lib/installer-exclude/aclibico-2.1.jar"/> <classpathentry kind="lib" path="lib/installer-exclude/aclibico-2.1.jar"/>
<classpathentry kind="lib" path="lib/installer-exclude/apache-ant-1.7.0.jar"/> <classpathentry kind="lib" path="lib/installer-exclude/apache-ant-1.7.0.jar"/>
<classpathentry kind="lib" path="lib/installer-exclude/cglib-nodep.osgi-2.1_3.jar"/> <classpathentry kind="lib" path="lib/installer-exclude/cglib-nodep.osgi-2.1_3.jar"/>
<classpathentry kind="lib" path="lib/installer-exclude/commons-logging-1.1.1.jar"/> <classpathentry kind="lib" path="lib/installer-exclude/commons-logging-1.1.2.jar"/>
<classpathentry kind="lib" path="lib/installer-exclude/dhcp4java-1.00.jar"/> <classpathentry kind="lib" path="lib/installer-exclude/dhcp4java-1.00.jar"/>
<classpathentry kind="lib" path="lib/installer-exclude/dict4j.jar"/> <classpathentry kind="lib" path="lib/installer-exclude/dict4j.jar"/>
<classpathentry kind="lib" path="lib/installer-exclude/dnsjava.jar"> <classpathentry kind="lib" path="lib/installer-exclude/dnsjava.jar">

@ -921,7 +921,8 @@
bundle-plugin-icqaccregwizz,bundle-plugin-jabberaccregwizz, bundle-plugin-icqaccregwizz,bundle-plugin-jabberaccregwizz,
bundle-plugin-msnaccregwizz,bundle-plugin-sipaccregwizz, bundle-plugin-msnaccregwizz,bundle-plugin-sipaccregwizz,
bundle-plugin-yahooaccregwizz,bundle-plugin-aimaccregwizz, bundle-plugin-yahooaccregwizz,bundle-plugin-aimaccregwizz,
bundle-commons-codec,bundle-httputil,bundle-plugin-spellcheck, bundle-commons-codec,bundle-commons-logging,
bundle-httputil,bundle-plugin-spellcheck,
bundle-version-impl,bundle-shutdown-timeout,bundle-windows-clean-shutdown, bundle-version-impl,bundle-shutdown-timeout,bundle-windows-clean-shutdown,
bundle-growlnotification,bundle-swingnotification,bundle-galagonotification, bundle-growlnotification,bundle-swingnotification,bundle-galagonotification,
bundle-sparkle, bundle-plugin-branding, bundle-sparkle, bundle-plugin-branding,
@ -1964,20 +1965,8 @@ javax.swing.event, javax.swing.border"/>
<!--BUNDLE-COMMONS-LOGGING --> <!--BUNDLE-COMMONS-LOGGING -->
<target name="bundle-commons-logging"> <target name="bundle-commons-logging">
<jar compress="true" destfile="lib/bundle/commons-logging.jar" <copy file="${lib.noinst}/commons-logging-1.1.2.jar"
filesetmanifest="merge"> tofile="${bundles.dest}/commons-logging.jar"/>
<zipfileset src="${lib.noinst}/commons-logging-1.1.1.jar"
prefix=""/>
<manifest>
<attribute name="Export-Package"
value="org.apache.commons.logging"/>
<attribute name="Bundle-Name"
value="Apache Commons Logging"/>
<attribute name="Bundle-Description"
value="An ultra-thin bridge between different logging implementations."/>
<attribute name="System-Bundle" value="yes"/>
</manifest>
</jar>
</target> </target>
<!--BUNDLE-COMMONS-CODEC --> <!--BUNDLE-COMMONS-CODEC -->
@ -1999,9 +1988,21 @@ javax.swing.event, javax.swing.border"/>
manifest="${src}/net/java/sip/communicator/service/httputil/httputil.manifest.mf"> manifest="${src}/net/java/sip/communicator/service/httputil/httputil.manifest.mf">
<zipfileset dir="${dest}/net/java/sip/communicator/service/httputil" <zipfileset dir="${dest}/net/java/sip/communicator/service/httputil"
prefix="net/java/sip/communicator/service/httputil"/> prefix="net/java/sip/communicator/service/httputil"/>
<zipfileset src="${lib.noinst}/httpclient-osgi-4.2.3.jar" prefix=""/>
<zipfileset src="${lib.noinst}/httpcore-osgi-4.2.3.jar" prefix=""/>
</jar> </jar>
<!--
Re-packaging into new bundle as original having wrong paths in osgi
bundle manifest and getting exceptions
'No paths specified in header' while loading
-->
<jar
compress="false" destfile="${bundles.dest}/httpclient.jar"
manifest="${lib.noinst}/httpclient.manifest.mf">
<zipfileset src="${lib.noinst}/httpclient-osgi-4.2.3.jar"
prefix=""/>
<zipfileset src="${lib.noinst}/httpcore-osgi-4.2.3.jar"
prefix=""/>
</jar>
</target> </target>
<!-- BUNDLE-NOTIFICATION --> <!-- BUNDLE-NOTIFICATION -->
@ -2369,7 +2370,7 @@ javax.swing.event, javax.swing.border"/>
<!--BUNDLE-BOUNCYCASTLE --> <!--BUNDLE-BOUNCYCASTLE -->
<target name="bundle-bouncycastle"> <target name="bundle-bouncycastle">
<copy file="${lib.noinst}/bcprov-jdk15on-148.jar" tofile="${bundles.dest}/bouncycastle.jar"/> <copy file="${lib.noinst}/bcprov-jdk15on-148.jar" tofile="${bundles.dest}/bouncycastle.jar"/>
<copy file="${lib.noinst}/bccontrib-1.0-SNAPSHOT.jar" tofile="${bundles.dest}/bccontrib.jar"/> <copy file="${lib.noinst}/bccontrib-1.0-SNAPSHOT.jar" tofile="${bundles.dest}/bccontrib.jar"/>
</target> </target>
<!--BUNDLE-PLUGIN-OTR --> <!--BUNDLE-PLUGIN-OTR -->

@ -60,6 +60,8 @@ felix.auto.start.32= \
felix.auto.start.35= \ felix.auto.start.35= \
reference:file:sc-bundles/commons-codec.jar \ reference:file:sc-bundles/commons-codec.jar \
reference:file:sc-bundles/commons-logging.jar \
reference:file:sc-bundles/httpclient.jar \
reference:file:sc-bundles/httputil.jar reference:file:sc-bundles/httputil.jar
felix.auto.start.40= \ felix.auto.start.40= \

@ -0,0 +1,38 @@
Bundle-Name: Apache Http Client
Bundle-Description: Apache Http Client
Bundle-Vendor: jitsi.org
Bundle-Version: 4.2.3
System-Bundle: yes
Import-Package: org.apache.commons.logging,
javax.net.ssl
Export-Package: org.apache.http,
org.apache.http.entity,
org.apache.http.entity.mime,
org.apache.http.entity.mime.content,
org.apache.http.impl,
org.apache.http.impl.conn,
org.apache.http.impl.entity,
org.apache.http.impl.io,
org.apache.http.io,
org.apache.http.message,
org.apache.http.params,
org.apache.http.protocol,
org.apache.http.util,
org.apache.http.annotation,
org.apache.http.auth,
org.apache.http.auth.params,
org.apache.http.client,
org.apache.http.client.entity,
org.apache.http.client.methods,
org.apache.http.client.params,
org.apache.http.client.protocol,
org.apache.http.client.utils,
org.apache.http.conn,
org.apache.http.conn.params,
org.apache.http.conn.routing,
org.apache.http.conn.scheme,
org.apache.http.conn.ssl,
org.apache.http.conn.util,
org.apache.http.impl.client

@ -19,9 +19,9 @@
import javax.net.ssl.*; import javax.net.ssl.*;
import javax.security.auth.callback.*; import javax.security.auth.callback.*;
import net.java.sip.communicator.plugin.desktoputil.*;
import net.java.sip.communicator.service.certificate.*; import net.java.sip.communicator.service.certificate.*;
import net.java.sip.communicator.service.credentialsstorage.*; import net.java.sip.communicator.service.credentialsstorage.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.httputil.*; import net.java.sip.communicator.service.httputil.*;
import net.java.sip.communicator.util.Logger; import net.java.sip.communicator.util.Logger;
@ -430,14 +430,29 @@ public void handle(Callback[] callbacks)
} }
else else
{ {
AuthenticationWindow aw = AuthenticationWindowService
new AuthenticationWindow( authenticationWindowService =
f.getName(), CertificateVerificationActivator
null, .getAuthenticationWindowService();
kt.getName(),
false, if(authenticationWindowService == null)
null {
); logger.error(
"No AuthenticationWindowService " +
"implementation");
throw new IOException("User cancel");
}
AuthenticationWindowService.AuthenticationWindow
aw = authenticationWindowService.create(
f.getName(),
null,
kt.getName(),
false,
false,
null, null, null, null,
null, null, null);
aw.setAllowSavePassword(false); aw.setAllowSavePassword(false);
aw.setVisible(true); aw.setVisible(true);
if (!aw.isCanceled()) if (!aw.isCanceled())

@ -8,6 +8,7 @@
import net.java.sip.communicator.service.certificate.*; import net.java.sip.communicator.service.certificate.*;
import net.java.sip.communicator.service.credentialsstorage.*; import net.java.sip.communicator.service.credentialsstorage.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.*;
import org.jitsi.service.configuration.*; import org.jitsi.service.configuration.*;
@ -154,4 +155,14 @@ public static VerifyCertificateDialogService getCertificateDialogService()
} }
return certificateDialogService; return certificateDialogService;
} }
/**
* Returns service to show authentication window.
* @return return service to show authentication window.
*/
public static AuthenticationWindowService getAuthenticationWindowService()
{
return ServiceUtils.getService(
bundleContext, AuthenticationWindowService.class);
}
} }

@ -6,6 +6,7 @@ Bundle-Version: 0.0.1
System-Bundle: yes System-Bundle: yes
Export-Package: net.java.sip.communicator.service.certificate Export-Package: net.java.sip.communicator.service.certificate
Import-Package: org.osgi.framework, Import-Package: org.osgi.framework,
net.java.sip.communicator.service.gui,
net.java.sip.communicator.util, net.java.sip.communicator.util,
net.java.sip.communicator.plugin.desktoputil, net.java.sip.communicator.plugin.desktoputil,
org.jitsi.service.configuration, org.jitsi.service.configuration,

@ -19,6 +19,7 @@ Import-Package: ch.imvs.sdes4j.srtp,
net.java.sip.communicator.service.certificate, net.java.sip.communicator.service.certificate,
net.java.sip.communicator.service.gui, net.java.sip.communicator.service.gui,
net.java.sip.communicator.service.hid, net.java.sip.communicator.service.hid,
net.java.sip.communicator.service.httputil,
net.java.sip.communicator.service.netaddr, net.java.sip.communicator.service.netaddr,
net.java.sip.communicator.service.netaddr.event, net.java.sip.communicator.service.netaddr.event,
net.java.sip.communicator.service.protocol, net.java.sip.communicator.service.protocol,

@ -10,7 +10,6 @@
import java.net.*; import java.net.*;
import java.net.URI; import java.net.URI;
import javax.net.ssl.*;
import javax.sip.address.*; import javax.sip.address.*;
import net.java.sip.communicator.impl.protocol.sip.*; import net.java.sip.communicator.impl.protocol.sip.*;
@ -19,17 +18,15 @@
import net.java.sip.communicator.impl.protocol.sip.xcap.utils.*; import net.java.sip.communicator.impl.protocol.sip.xcap.utils.*;
import net.java.sip.communicator.service.certificate.*; import net.java.sip.communicator.service.certificate.*;
import net.java.sip.communicator.service.gui.*; import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.httputil.*;
import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.*;
import org.apache.http.*; import org.apache.http.*;
import org.apache.http.auth.*; import org.apache.http.auth.*;
import org.apache.http.client.*;
import org.apache.http.client.methods.*; import org.apache.http.client.methods.*;
import org.apache.http.conn.*;
import org.apache.http.conn.scheme.*;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.*; import org.apache.http.entity.*;
import org.apache.http.impl.client.*; import org.apache.http.impl.client.*;
import org.apache.http.params.*;
import org.osgi.framework.*; import org.osgi.framework.*;
/** /**
@ -68,11 +65,6 @@ public abstract class BaseHttpXCapClient implements HttpXCapClient
public static final String XCAP_ERROR_CONTENT_TYPE public static final String XCAP_ERROR_CONTENT_TYPE
= "application/xcap-error+xml"; = "application/xcap-error+xml";
/**
* The default timeout (10 seconds)
*/
private static int DEFAULT_TIMEOUT = 10 * 1000;
/** /**
* Current server uri. * Current server uri.
*/ */
@ -98,11 +90,6 @@ public abstract class BaseHttpXCapClient implements HttpXCapClient
*/ */
private boolean connected; private boolean connected;
/**
* How many seconds should the client wait for HTTP response.
*/
private int timeout;
/** /**
* The service we use to interact with user regarding certificates. * The service we use to interact with user regarding certificates.
*/ */
@ -113,8 +100,6 @@ public abstract class BaseHttpXCapClient implements HttpXCapClient
*/ */
public BaseHttpXCapClient() public BaseHttpXCapClient()
{ {
timeout = DEFAULT_TIMEOUT;
ServiceReference guiVerifyReference ServiceReference guiVerifyReference
= SipActivator.getBundleContext().getServiceReference( = SipActivator.getBundleContext().getServiceReference(
CertificateService.class.getName()); CertificateService.class.getName());
@ -194,15 +179,13 @@ public XCapHttpResponse get(XCapResourceId resourceId)
protected XCapHttpResponse get(URI uri) protected XCapHttpResponse get(URI uri)
throws XCapException throws XCapException
{ {
DefaultHttpClient httpClient = createHttpClient(); DefaultHttpClient httpClient = null;
try try
{ {
httpClient = createHttpClient();
HttpGet getMethod = new HttpGet(uri); HttpGet getMethod = new HttpGet(uri);
getMethod.setHeader("Connection", "close"); getMethod.setHeader("Connection", "close");
Credentials credentials =
new UsernamePasswordCredentials(getUserName(), password);
httpClient.getCredentialsProvider().
setCredentials(AuthScope.ANY, credentials);
HttpResponse response = httpClient.execute(getMethod); HttpResponse response = httpClient.execute(getMethod);
XCapHttpResponse result = createResponse(response); XCapHttpResponse result = createResponse(response);
@ -246,7 +229,8 @@ protected XCapHttpResponse get(URI uri)
} }
finally finally
{ {
httpClient.getConnectionManager().shutdown(); if(httpClient != null)
httpClient.getConnectionManager().shutdown();
} }
} }
@ -292,9 +276,11 @@ static void showError(Exception ex, String title, String message)
public XCapHttpResponse put(XCapResource resource) public XCapHttpResponse put(XCapResource resource)
throws XCapException throws XCapException
{ {
DefaultHttpClient httpClient = createHttpClient(); DefaultHttpClient httpClient = null;
try try
{ {
httpClient = createHttpClient();
URI resourceUri = getResourceURI(resource.getId()); URI resourceUri = getResourceURI(resource.getId());
HttpPut putMethod = new HttpPut(resourceUri); HttpPut putMethod = new HttpPut(resourceUri);
putMethod.setHeader("Connection", "close"); putMethod.setHeader("Connection", "close");
@ -302,10 +288,7 @@ public XCapHttpResponse put(XCapResource resource)
stringEntity.setContentType(resource.getContentType()); stringEntity.setContentType(resource.getContentType());
stringEntity.setContentEncoding("UTF-8"); stringEntity.setContentEncoding("UTF-8");
putMethod.setEntity(stringEntity); putMethod.setEntity(stringEntity);
Credentials credentials =
new UsernamePasswordCredentials(getUserName(), password);
httpClient.getCredentialsProvider().
setCredentials(AuthScope.ANY, credentials);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
String logMessage = String.format( String logMessage = String.format(
@ -327,7 +310,8 @@ public XCapHttpResponse put(XCapResource resource)
} }
finally finally
{ {
httpClient.getConnectionManager().shutdown(); if(httpClient != null)
httpClient.getConnectionManager().shutdown();
} }
} }
@ -343,16 +327,15 @@ public XCapHttpResponse delete(XCapResourceId resourceId)
throws XCapException throws XCapException
{ {
assertConnected(); assertConnected();
DefaultHttpClient httpClient = createHttpClient(); DefaultHttpClient httpClient = null;
try try
{ {
httpClient = createHttpClient();
URI resourceUri = getResourceURI(resourceId); URI resourceUri = getResourceURI(resourceId);
HttpDelete deleteMethod = new HttpDelete(resourceUri); HttpDelete deleteMethod = new HttpDelete(resourceUri);
deleteMethod.setHeader("Connection", "close"); deleteMethod.setHeader("Connection", "close");
Credentials credentials =
new UsernamePasswordCredentials(getUserName(), password);
httpClient.getCredentialsProvider().
setCredentials(AuthScope.ANY, credentials);
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
String logMessage = String.format( String logMessage = String.format(
@ -373,7 +356,8 @@ public XCapHttpResponse delete(XCapResourceId resourceId)
} }
finally finally
{ {
httpClient.getConnectionManager().shutdown(); if(httpClient != null)
httpClient.getConnectionManager().shutdown();
} }
} }
@ -397,26 +381,6 @@ public URI getUri()
return uri; return uri;
} }
/**
* Gets operation timeout.The deffault value is 10 seconds.
*
* @return operation timeout.
*/
public int getTimeout()
{
return timeout;
}
/**
* Sets operation timeout. The deffault value is 10 seconds.
*
* @param timeout operation timeout.
*/
public void setTimeout(int timeout)
{
this.timeout = timeout;
}
/** /**
* Utility method throwing an exception if the user is not connected. * Utility method throwing an exception if the user is not connected.
* *
@ -456,32 +420,16 @@ protected URI getResourceURI(XCapResourceId resourceId)
* @return the HTTP client. * @return the HTTP client.
*/ */
private DefaultHttpClient createHttpClient() private DefaultHttpClient createHttpClient()
throws IOException
{ {
//TODO: move to HttpUtil XCapCredentialsProvider credentialsProvider
DefaultHttpClient httpClient = new DefaultHttpClient(); = new XCapCredentialsProvider();
try credentialsProvider.setCredentials(
{ AuthScope.ANY,
// make sure we use Certificate Verification Service if new UsernamePasswordCredentials(getUserName(), password));
// for some reason the certificate needs to be shown to user
// for approval return HttpUtils.getHttpClient(
ClientConnectionManager ccm = httpClient.getConnectionManager(); null , null, uri.getHost(), credentialsProvider);
SchemeRegistry sr = ccm.getSchemeRegistry();
SSLContext ctx =
certificateVerification.getSSLContext(
certificateVerification.getTrustManager(uri.getHost()));
org.apache.http.conn.ssl.SSLSocketFactory ssf =
new org.apache.http.conn.ssl.SSLSocketFactory(ctx,
SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
sr.register(new Scheme("https", 443, ssf));
}
catch(Throwable e)
{
logger.error("Cannot add our trust manager to httpClient", e);
}
HttpParams httpParams = httpClient.getParams();
HttpConnectionParams.setConnectionTimeout(httpParams, timeout);
HttpConnectionParams.setSoTimeout(httpParams, timeout);
return httpClient;
} }
/** /**
@ -584,4 +532,45 @@ protected String getXCapErrorMessage(XCapHttpResponse response)
return null; return null;
} }
} }
/**
* Our credentials provider simple impl.
*/
private class XCapCredentialsProvider
implements CredentialsProvider
{
/**
* The credentials to use.
*/
private Credentials credentials;
/**
* Sets credentials no matter of the scope.
* @param authscope the scope is not used.
* @param credentials the credentials to use
*/
public void setCredentials(AuthScope authscope,
Credentials credentials)
{
this.credentials = credentials;
}
/**
* Returns the credentials no matter of the scope.
* @param authscope not important
* @return the credentials.
*/
public Credentials getCredentials(AuthScope authscope)
{
return credentials;
}
/**
* Clears credentials.
*/
public void clear()
{
credentials = null;
}
}
} }

@ -89,19 +89,4 @@ public XCapHttpResponse delete(XCapResourceId resourceId)
* @return server location. * @return server location.
*/ */
public URI getUri(); public URI getUri();
/**
* Gets operation timeout.
*
* @return operation timeout.
*/
public int getTimeout();
/**
* Sets operation timeout.
*
* @param timeout operation timeout.
*/
public void setTimeout(int timeout);
} }

@ -11,6 +11,7 @@
import javax.swing.*; import javax.swing.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.util.Logger; import net.java.sip.communicator.util.Logger;
import org.jitsi.util.*; import org.jitsi.util.*;
@ -23,7 +24,8 @@
*/ */
public class AuthenticationWindow public class AuthenticationWindow
extends SIPCommDialog extends SIPCommDialog
implements ActionListener implements ActionListener,
AuthenticationWindowService.AuthenticationWindow
{ {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@ -172,7 +174,7 @@ public AuthenticationWindow(String server,
* the user that something went wrong * the user that something went wrong
* @param signupLink an URL that allows the user to sign up * @param signupLink an URL that allows the user to sign up
*/ */
private AuthenticationWindow(String userName, AuthenticationWindow(String userName,
char[] password, char[] password,
String server, String server,
boolean isUserNameEditable, boolean isUserNameEditable,

@ -5,6 +5,7 @@
import java.security.cert.*; import java.security.cert.*;
import javax.imageio.*; import javax.imageio.*;
import javax.swing.*;
import net.java.sip.communicator.service.browserlauncher.*; import net.java.sip.communicator.service.browserlauncher.*;
import net.java.sip.communicator.service.certificate.*; import net.java.sip.communicator.service.certificate.*;
@ -71,6 +72,43 @@ public String showInputDialog(boolean prevSuccess)
} }
}, },
null); null);
bundleContext.registerService(
AuthenticationWindowService.class.getName(),
new AuthenticationWindowService()
{
public AuthenticationWindow create(
String userName,
char[] password,
String server,
boolean isUserNameEditable,
boolean isRememberPassword,
Object icon,
String windowTitle,
String windowText,
String usernameLabelText,
String passwordLabelText,
String errorMessage,
String signupLink)
{
ImageIcon imageIcon = null;
if(icon instanceof ImageIcon)
imageIcon = (ImageIcon)icon;
return new net.java.sip.communicator.plugin.desktoputil
.AuthenticationWindow(
userName, password,
server,
isUserNameEditable, isRememberPassword,
imageIcon,
windowTitle, windowText,
usernameLabelText, passwordLabelText,
errorMessage,
signupLink);
}
},
null);
} }
/** /**

@ -19,6 +19,7 @@ Import-Package: org.osgi.framework,
org.jitsi.util, org.jitsi.util,
net.java.sip.communicator.util, net.java.sip.communicator.util,
net.java.sip.communicator.plugin.desktoputil, net.java.sip.communicator.plugin.desktoputil,
org.apache.http.params,
javax.swing, javax.swing,
javax.swing.event, javax.swing.event,
javax.swing.table, javax.swing.table,

@ -0,0 +1,95 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.gui;
import javax.swing.*;
/**
* Creates and show authentication window, normally to fill in username and
* password.
* @author Damian Minkov
*/
public interface AuthenticationWindowService
{
/**
* Creates an instance of the <tt>AuthenticationWindow</tt> implementation.
*
* @param server the server name
* @param isUserNameEditable indicates if the user name is editable
* @param icon the icon to display on the left of the authentication window
* @param windowTitle customized window title
* @param windowText customized window text
* @param usernameLabelText customized username field label text
* @param passwordLabelText customized password field label text
* @param errorMessage an error message if this dialog is shown to indicate
* the user that something went wrong
* @param signupLink an URL that allows the user to sign up
*/
public AuthenticationWindow create(String userName,
char[] password,
String server,
boolean isUserNameEditable,
boolean isRememberPassword,
Object icon,
String windowTitle,
String windowText,
String usernameLabelText,
String passwordLabelText,
String errorMessage,
String signupLink);
/**
* The window interface used by implementers.
*/
public interface AuthenticationWindow
{
/**
* Shows window implementation.
*
* @param isVisible specifies whether we should be showing or hiding the
* window.
*/
public void setVisible(final boolean isVisible);
/**
* Indicates if this window has been canceled.
*
* @return <tt>true</tt> if this window has been canceled,
* <tt>false</tt> - otherwise.
*/
public boolean isCanceled();
/**
* Returns the user name entered by the user or previously set if the
* user name is not editable.
*
* @return the user name.
*/
public String getUserName();
/**
* Returns the password entered by the user.
*
* @return the password.
*/
public char[] getPassword();
/**
* Indicates if the password should be remembered.
*
* @return <tt>true</tt> if the password should be remembered,
* <tt>false</tt> - otherwise.
*/
public boolean isRememberPassword();
/**
* Shows or hides the "save password" checkbox.
* @param allow the checkbox is shown when allow is <tt>true</tt>
*/
public void setAllowSavePassword(boolean allow);
}
}

@ -2,6 +2,7 @@
import net.java.sip.communicator.service.certificate.*; import net.java.sip.communicator.service.certificate.*;
import net.java.sip.communicator.service.credentialsstorage.*; import net.java.sip.communicator.service.credentialsstorage.*;
import net.java.sip.communicator.service.gui.*;
import net.java.sip.communicator.service.resources.*; import net.java.sip.communicator.service.resources.*;
import net.java.sip.communicator.util.*; import net.java.sip.communicator.util.*;
@ -146,4 +147,14 @@ public static ConfigurationService getConfigurationService()
} }
return configurationService; return configurationService;
} }
/**
* Returns service to show authentication window.
* @return return service to show authentication window.
*/
public static AuthenticationWindowService getAuthenticationWindowService()
{
return ServiceUtils.getService(
bundleContext, AuthenticationWindowService.class);
}
} }

@ -14,7 +14,7 @@
import javax.net.ssl.*; import javax.net.ssl.*;
import net.java.sip.communicator.util.Logger; import net.java.sip.communicator.util.Logger;
import net.java.sip.communicator.plugin.desktoputil.*; import net.java.sip.communicator.service.gui.*;
import org.apache.http.*; import org.apache.http.*;
import org.apache.http.Header; import org.apache.http.Header;
@ -24,7 +24,6 @@
import org.apache.http.client.params.*; import org.apache.http.client.params.*;
import org.apache.http.client.utils.*; import org.apache.http.client.utils.*;
import org.apache.http.conn.scheme.*; import org.apache.http.conn.scheme.*;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.*; import org.apache.http.entity.*;
import org.apache.http.entity.mime.*; import org.apache.http.entity.mime.*;
import org.apache.http.entity.mime.content.*; import org.apache.http.entity.mime.content.*;
@ -524,11 +523,11 @@ else if(i == passwordParamIx && creds != null)
* in the new client * in the new client
* @param address the address we will be connecting to * @param address the address we will be connecting to
*/ */
private static DefaultHttpClient getHttpClient( public static DefaultHttpClient getHttpClient(
String usernamePropertyName, String usernamePropertyName,
String passwordPropertyName, String passwordPropertyName,
final String address, final String address,
HTTPCredentialsProvider credentialsProvider) CredentialsProvider credentialsProvider)
throws IOException throws IOException
{ {
HttpParams params = new BasicHttpParams(); HttpParams params = new BasicHttpParams();
@ -559,12 +558,16 @@ private static DefaultHttpClient getHttpClient(
// note to any reviewer concerned about ALLOW_ALL_HOSTNAME_VERIFIER: // note to any reviewer concerned about ALLOW_ALL_HOSTNAME_VERIFIER:
// the SSL context obtained from the certificate service takes care of // the SSL context obtained from the certificate service takes care of
// certificate validation // certificate validation
Scheme sch = try
new Scheme("https", 443, new SSLSocketFactory(sslCtx, {
SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER)); Scheme sch =
httpClient.getConnectionManager().getSchemeRegistry().register(sch); new Scheme("https", 443, new SSLSocketFactoryEx(sslCtx));
//TODO: wrap the SSLSocketFactory to use our own DNS resolution httpClient.getConnectionManager().getSchemeRegistry().register(sch);
//TODO: register socketfactory for http to use our own DNS resolution }
catch(Throwable t)
{
logger.error("Error creating ssl socket factory", t);
}
// set proxy from default jre settings // set proxy from default jre settings
ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner( ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(
@ -679,11 +682,24 @@ public Credentials getCredentials(AuthScope authscope)
// if password is not saved ask user for credentials // if password is not saved ask user for credentials
if(pass == null) if(pass == null)
{ {
AuthenticationWindowService authenticationWindowService =
HttpUtilActivator.getAuthenticationWindowService();
if(authenticationWindowService == null)
{
logger.error(
"No AuthenticationWindowService implementation");
return null;
}
AuthenticationWindow authWindow = AuthenticationWindowService.AuthenticationWindow authWindow =
new AuthenticationWindow( authenticationWindowService.create(
authUsername, null, authUsername, null,
authscope.getHost(), true, null, errorMessage, authscope.getHost(),
true,
false,
null, null, null, null, null,
errorMessage,
HttpUtilActivator.getResources().getSettingsString( HttpUtilActivator.getResources().getSettingsString(
"plugin.provisioning.SIGN_UP_LINK")); "plugin.provisioning.SIGN_UP_LINK"));
authWindow.setVisible(true); authWindow.setVisible(true);

@ -0,0 +1,156 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.httputil;
import org.apache.http.conn.*;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.params.*;
import javax.net.ssl.*;
import java.io.*;
import java.net.*;
import java.security.*;
/**
* Wrapper for SSLSocketFactory to use the constructor which is available
* in android. The certificate validation is handled by the SSLContext
* which we use to create sockets for this factory.
*
* TODO: wrap the SSLSocketFactory to use our own DNS resolution
* TODO: register socketfactory for http to use our own DNS resolution
*
* @author Damian Minkov
*/
public class SSLSocketFactoryEx
extends SSLSocketFactory
{
/**
* The context that will be used to create sockets.
*/
private SSLContext context;
/**
* Constructor using the super constructor available for android.
*
* @param context the context to use
* @throws UnrecoverableKeyException
* @throws KeyStoreException
* @throws KeyManagementException
* @throws NoSuchAlgorithmException
*/
public SSLSocketFactoryEx(SSLContext context)
throws
UnrecoverableKeyException,
KeyStoreException,
KeyManagementException,
NoSuchAlgorithmException
{
super((KeyStore) null);
this.context = context;
}
/**
* Creates socket.
* @param params
* @return
* @throws IOException
*/
public Socket createSocket(final HttpParams params)
throws
IOException
{
return this.context.getSocketFactory().createSocket();
}
/**
* @since 4.2
*/
public Socket createLayeredSocket(
final Socket socket,
final String host,
final int port,
final HttpParams params)
throws IOException,
UnknownHostException
{
return this.context.getSocketFactory()
.createSocket(
socket,
host,
port,
true);
}
/**
* @since 4.1
*/
public Socket connectSocket(
final Socket socket,
final InetSocketAddress remoteAddress,
final InetSocketAddress localAddress,
final HttpParams params)
throws IOException,
UnknownHostException,
ConnectTimeoutException
{
if(remoteAddress == null)
{
throw new IllegalArgumentException("Remote address may not be null");
}
if(params == null)
{
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Socket sock = socket != null ?
socket : this.context.getSocketFactory().createSocket();
if(localAddress != null)
{
sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
sock.bind(localAddress);
}
int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
int soTimeout = HttpConnectionParams.getSoTimeout(params);
try
{
sock.setSoTimeout(soTimeout);
sock.connect(remoteAddress, connTimeout);
}
catch(SocketTimeoutException ex)
{
throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
}
String hostname;
if(remoteAddress instanceof HttpInetSocketAddress)
{
hostname = ((HttpInetSocketAddress) remoteAddress)
.getHttpHost().getHostName();
}
else
{
hostname = remoteAddress.getHostName();
}
SSLSocket sslsock;
// Setup SSL layering if necessary
if(sock instanceof SSLSocket)
{
sslsock = (SSLSocket) sock;
}
else
{
int port = remoteAddress.getPort();
sslsock = (SSLSocket) this.context.getSocketFactory()
.createSocket(sock, hostname, port, true);
}
return sslsock;
}
}

@ -32,6 +32,7 @@ Import-Package: org.xml.sax,
net.java.sip.communicator.service.resources, net.java.sip.communicator.service.resources,
net.java.sip.communicator.service.certificate, net.java.sip.communicator.service.certificate,
net.java.sip.communicator.service.credentialsstorage, net.java.sip.communicator.service.credentialsstorage,
net.java.sip.communicator.service.gui,
net.java.sip.communicator.service.keybindings, net.java.sip.communicator.service.keybindings,
net.java.sip.communicator.service.netaddr, net.java.sip.communicator.service.netaddr,
net.java.sip.communicator.service.netaddr.event, net.java.sip.communicator.service.netaddr.event,
@ -47,14 +48,12 @@ Import-Package: org.xml.sax,
org.apache.commons.codec.digest, org.apache.commons.codec.digest,
org.apache.commons.codec.binary, org.apache.commons.codec.binary,
org.apache.commons.logging, org.apache.commons.logging,
javax.net.ssl,
javax.security.auth.x500
Export-Package: net.java.sip.communicator.service.httputil,
org.apache.http, org.apache.http,
org.apache.http.entity, org.apache.http.entity,
org.apache.http.entity.mime, org.apache.http.entity.mime,
org.apache.http.entity.mime.content, org.apache.http.entity.mime.content,
org.apache.http.impl, org.apache.http.impl,
org.apache.http.impl.conn,
org.apache.http.impl.entity, org.apache.http.impl.entity,
org.apache.http.impl.io, org.apache.http.impl.io,
org.apache.http.io, org.apache.http.io,
@ -77,4 +76,7 @@ Export-Package: net.java.sip.communicator.service.httputil,
org.apache.http.conn.scheme, org.apache.http.conn.scheme,
org.apache.http.conn.ssl, org.apache.http.conn.ssl,
org.apache.http.conn.util, org.apache.http.conn.util,
org.apache.http.impl.client org.apache.http.impl.client,
javax.net.ssl,
javax.security.auth.x500
Export-Package: net.java.sip.communicator.service.httputil

Loading…
Cancel
Save