From 42cfba94eaf2efa4420cba4db482801a3420429f Mon Sep 17 00:00:00 2001 From: Damian Minkov Date: Mon, 29 Nov 2010 13:37:08 +0000 Subject: [PATCH] Update check detecting wrong password on secure locations. --- .../updatechecker/UpdateCheckActivator.java | 76 ++++++++++++++++++- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/src/net/java/sip/communicator/plugin/updatechecker/UpdateCheckActivator.java b/src/net/java/sip/communicator/plugin/updatechecker/UpdateCheckActivator.java index 83dfc047f..4952aa345 100644 --- a/src/net/java/sip/communicator/plugin/updatechecker/UpdateCheckActivator.java +++ b/src/net/java/sip/communicator/plugin/updatechecker/UpdateCheckActivator.java @@ -95,6 +95,21 @@ public class UpdateCheckActivator */ private static UserCredentials userCredentials = null; + /** + * The error message is any. + */ + private static String errorMessage = null; + + /** + * The host we are querying for updates. + */ + private static String host = null; + + /** + * Whether user has canceled authentication process. + */ + private static boolean isAuthenticationCanceled = false; + /** * Property name of the username used if HTTP authentication is required. */ @@ -330,6 +345,36 @@ private boolean isNewestVersion() URL url = new URL(configString); URLConnection conn = url.openConnection(); + + if (conn instanceof HttpURLConnection) + { + while(((HttpURLConnection)conn).getResponseCode() == + HttpURLConnection.HTTP_UNAUTHORIZED + && !isAuthenticationCanceled) + { + if(userCredentials.getUserName() != null) + { + errorMessage = getResources().getI18NString( + "service.gui.AUTHENTICATION_FAILED", + new String[]{ + userCredentials.getUserName(), + host}); + + userCredentials.setUserName(null); + userCredentials.setPasswordPersistent(false); + userCredentials = null; + + getConfigurationService().removeProperty( + UPDATE_USERNAME_CONFIG); + getConfigurationService().removeProperty( + UPDATE_PASSWORD_CONFIG); + + conn = url.openConnection(); + } + else + break; + } + } conn.setConnectTimeout(10000); conn.setReadTimeout(10000); @@ -614,6 +659,10 @@ else if(u.getProtocol().equals("https")) vs.getSSLContext( u.getHost(), port).getSocketFactory()); } + + // we don't handle here authentication fails cause + // still we gone to downloading file we have gone through + // successful authentication } InputStream in = uc.getInputStream(); @@ -760,7 +809,8 @@ protected PasswordAuthentication getPasswordAuthentication() { userCredentials = new UserCredentials(); userCredentials.setUserName(uName); - userCredentials.setPassword(pass.toCharArray()); + userCredentials.setPassword(new String( + Base64.decode(pass)).toCharArray()); userCredentials.setPasswordPersistent(true); } } @@ -774,9 +824,20 @@ protected PasswordAuthentication getPasswordAuthentication() } else { - AuthenticationWindow authWindow = - new AuthenticationWindow( - getRequestingHost(), true, null); + host = getRequestingHost(); + + AuthenticationWindow authWindow = null; + if(errorMessage == null) + { + authWindow = new AuthenticationWindow(host, true, null); + } + else + { + authWindow = new AuthenticationWindow( + null, null, host, true, null, errorMessage); + // we showed the message, remove it + errorMessage = null; + } userCredentials = new UserCredentials(); @@ -784,6 +845,7 @@ protected PasswordAuthentication getPasswordAuthentication() if (!authWindow.isCanceled()) { + isAuthenticationCanceled = false; userCredentials.setUserName(authWindow.getUserName()); userCredentials.setPassword(authWindow.getPassword()); userCredentials.setPasswordPersistent( @@ -808,8 +870,14 @@ protected PasswordAuthentication getPasswordAuthentication() } else { + isAuthenticationCanceled = true; userCredentials.setUserName(null); userCredentials = null; + + getConfigurationService().removeProperty( + UPDATE_USERNAME_CONFIG); + getConfigurationService().removeProperty( + UPDATE_PASSWORD_CONFIG); } return null;