summaryrefslogtreecommitdiff
path: root/swext/mediawiki/src/com/sun/star
diff options
context:
space:
mode:
authorMikhail Voitenko <mav@openoffice.org>2007-12-13 14:11:05 +0000
committerMikhail Voitenko <mav@openoffice.org>2007-12-13 14:11:05 +0000
commit0abb975d91fad4ff55930f22c382bc6cb1bffb67 (patch)
treee1395620b10ca2f3597d9f4c7089efa763994780 /swext/mediawiki/src/com/sun/star
parent7f1c15e5149bbe53918d99f47cbbe15643ded35c (diff)
use password container to store passwords
Diffstat (limited to 'swext/mediawiki/src/com/sun/star')
-rw-r--r--swext/mediawiki/src/com/sun/star/wiki/Helper.java83
-rw-r--r--swext/mediawiki/src/com/sun/star/wiki/WikiArticle.java28
-rw-r--r--swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog.java56
3 files changed, 145 insertions, 22 deletions
diff --git a/swext/mediawiki/src/com/sun/star/wiki/Helper.java b/swext/mediawiki/src/com/sun/star/wiki/Helper.java
index f3101987a86d..2dfac486d25b 100644
--- a/swext/mediawiki/src/com/sun/star/wiki/Helper.java
+++ b/swext/mediawiki/src/com/sun/star/wiki/Helper.java
@@ -4,9 +4,9 @@
*
* $RCSfile: Helper.java,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: mav $ $Date: 2007-12-13 10:34:07 $
+ * last change: $Author: mav $ $Date: 2007-12-13 15:11:05 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -35,6 +35,8 @@
package com.sun.star.wiki;
+import com.sun.star.awt.XControl;
+import com.sun.star.awt.XControlContainer;
import com.sun.star.awt.XDialog;
import com.sun.star.beans.NamedValue;
import com.sun.star.beans.PropertyValue;
@@ -53,6 +55,10 @@ import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.system.SystemShellExecuteFlags;
import com.sun.star.system.XSystemShellExecute;
+import com.sun.star.task.UrlRecord;
+import com.sun.star.task.XInteractionHandler;
+import com.sun.star.task.XMasterPasswordHandling;
+import com.sun.star.task.XPasswordContainer;
import com.sun.star.uno.AnyConverter;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;
@@ -85,6 +91,9 @@ public class Helper
private static boolean m_bAllowConnection = true;
private static Hashtable m_aAcceptedUnknownCerts;
+ private static XPasswordContainer m_xPasswordContainer;
+ private static XInteractionHandler m_xInteractionHandler;
+
synchronized protected static HttpClient GetHttpClient()
throws WikiCancelException
{
@@ -121,6 +130,42 @@ public class Helper
return m_bAllowConnection;
}
+ synchronized protected static XPasswordContainer GetPasswordContainer( XComponentContext xContext )
+ throws com.sun.star.uno.Exception
+ {
+ if ( m_xPasswordContainer == null && xContext != null )
+ {
+ XMultiComponentFactory xFactory = xContext.getServiceManager();
+ if ( xFactory != null )
+ m_xPasswordContainer = (XPasswordContainer)UnoRuntime.queryInterface(
+ XPasswordContainer.class,
+ xFactory.createInstanceWithContext( "com.sun.star.task.PasswordContainer", xContext ) );
+ }
+
+ if ( m_xPasswordContainer == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ return m_xPasswordContainer;
+ }
+
+ synchronized protected static XInteractionHandler GetInteractionHandler( XComponentContext xContext )
+ throws com.sun.star.uno.Exception
+ {
+ if ( m_xInteractionHandler == null && xContext != null )
+ {
+ XMultiComponentFactory xFactory = xContext.getServiceManager();
+ if ( xFactory != null )
+ m_xInteractionHandler = ( XInteractionHandler )UnoRuntime.queryInterface(
+ XInteractionHandler.class,
+ xFactory.createInstanceWithContext( "com.sun.star.task.InteractionHandler", xContext ) );
+ }
+
+ if ( m_xInteractionHandler == null )
+ throw new com.sun.star.uno.RuntimeException();
+
+ return m_xInteractionHandler;
+ }
+
protected static Protocol GetOwnHttps( int nPort )
{
return new Protocol( "https", new WikiProtocolSocketFactory(), ( ( nPort < 0 ) ? 443 : nPort ) );
@@ -630,7 +675,7 @@ public class Helper
return null;
}
- private static void SetControlPropInDialog( XDialog xDialog, String aControlName, String aPropName, Object aPropValue )
+ protected static void SetControlPropInDialog( XDialog xDialog, String aControlName, String aPropName, Object aPropValue )
{
if ( xDialog != null && aControlName != null && aPropName != null && aPropValue != null )
{
@@ -646,5 +691,37 @@ public class Helper
}
}
}
+
+ protected static UrlRecord GetUsersForURL( XComponentContext xContext, String sURL )
+ {
+ UrlRecord aResult = null;
+ try
+ {
+ aResult = GetPasswordContainer( xContext ).find( sURL, GetInteractionHandler( xContext ) );
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+
+ return aResult;
+ }
+
+ protected static boolean PasswordStoringIsAllowed( XComponentContext xContext )
+ {
+ boolean bResult = false;
+ try
+ {
+ XMasterPasswordHandling xMasterHdl = (XMasterPasswordHandling)UnoRuntime.queryInterface( XMasterPasswordHandling.class, GetPasswordContainer( xContext ) );
+ if ( xMasterHdl != null )
+ bResult = xMasterHdl.isPersistentStoringAllowed();
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+
+ return bResult;
+ }
}
diff --git a/swext/mediawiki/src/com/sun/star/wiki/WikiArticle.java b/swext/mediawiki/src/com/sun/star/wiki/WikiArticle.java
index 13d115a28fd4..f1cfc1a94313 100644
--- a/swext/mediawiki/src/com/sun/star/wiki/WikiArticle.java
+++ b/swext/mediawiki/src/com/sun/star/wiki/WikiArticle.java
@@ -4,9 +4,9 @@
*
* $RCSfile: WikiArticle.java,v $
*
- * $Revision: 1.1 $
+ * $Revision: 1.2 $
*
- * last change: $Author: mav $ $Date: 2007-11-28 11:14:22 $
+ * last change: $Author: mav $ $Date: 2007-12-13 15:11:05 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -35,13 +35,10 @@
package com.sun.star.wiki;
+import com.sun.star.task.UrlRecord;
import java.io.*;
-import java.net.MalformedURLException;
import java.util.Hashtable;
import javax.swing.text.html.*;
-import org.w3c.tidy.Configuration;
-import org.w3c.tidy.Tidy;
-import org.xml.sax.InputSource;
import com.sun.star.uno.XComponentContext;
import org.apache.commons.httpclient.*;
@@ -87,7 +84,24 @@ public class WikiArticle
// loginURL = sMainUrl + "index.php?title=Special:Userlogin";
// loginSubmitURL = sMainUrl + "index.php?title=Special:Userlogin&action=submitlogin";
- while( bLogin && !Login() )
+ boolean bGotLogin = false;
+ if ( bLogin && m_sWikiUser.equals( "" ) && m_sWikiPass.equals( "" ) )
+ {
+ UrlRecord aRecord = Helper.GetUsersForURL( m_xContext, m_aMainURI.toString() );
+ // TODO: there could be more users available, it should probably be possible to select from them
+ // from other side, asking each time for the user name could disturb the user
+ // For now the first acceptable user will be used.
+ if ( aRecord != null && aRecord.UserList != null )
+ for ( int nUserInd = 0; !bGotLogin && nUserInd < aRecord.UserList.length; nUserInd++ )
+ for ( int nPassInd = 0; !bGotLogin && nPassInd < aRecord.UserList[nUserInd].Passwords.length; nPassInd++ )
+ {
+ m_sWikiUser = aRecord.UserList[nUserInd].UserName;
+ m_sWikiPass = aRecord.UserList[nUserInd].Passwords[nPassInd];
+ bGotLogin = Login();
+ }
+ }
+
+ while( bLogin && !bGotLogin && !Login() )
{
// TODO: be sure that this is no main thread
WikiEditSettingDialog wd = new WikiEditSettingDialog(m_xContext, "vnd.sun.star.script:WikiEditor.EditSetting?location=application", wikiSettings );
diff --git a/swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog.java b/swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog.java
index 025a0569e21e..2607267d4471 100644
--- a/swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog.java
+++ b/swext/mediawiki/src/com/sun/star/wiki/WikiEditSettingDialog.java
@@ -4,9 +4,9 @@
*
* $RCSfile: WikiEditSettingDialog.java,v $
*
- * $Revision: 1.2 $
+ * $Revision: 1.3 $
*
- * last change: $Author: mav $ $Date: 2007-12-13 10:34:07 $
+ * last change: $Author: mav $ $Date: 2007-12-13 15:11:05 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -36,13 +36,12 @@
package com.sun.star.wiki;
import com.sun.star.awt.XDialog;
+import com.sun.star.beans.XPropertySet;
import com.sun.star.uno.XComponentContext;
import java.util.Hashtable;
-import javax.net.ssl.SSLException;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;
-import org.apache.commons.httpclient.protocol.Protocol;
public class WikiEditSettingDialog extends WikiDialog
{
@@ -56,17 +55,19 @@ public class WikiEditSettingDialog extends WikiDialog
private Hashtable setting;
private boolean addMode;
- public WikiEditSettingDialog( XComponentContext c, String DialogURL )
+ public WikiEditSettingDialog( XComponentContext xContext, String DialogURL )
{
- super( c, DialogURL );
+ super( xContext, DialogURL );
super.setMethods( Methods );
setting = new Hashtable();
addMode = true;
+
+ InitSaveCheckbox( xContext );
}
- public WikiEditSettingDialog( XComponentContext c, String DialogURL, Hashtable ht )
+ public WikiEditSettingDialog( XComponentContext xContext, String DialogURL, Hashtable ht )
{
- super( c, DialogURL );
+ super( xContext, DialogURL );
super.setMethods( Methods );
setting = ht;
try
@@ -80,18 +81,35 @@ public class WikiEditSettingDialog extends WikiDialog
ex.printStackTrace();
}
addMode = false;
+
+ InitSaveCheckbox( xContext );
+ }
+
+ private void InitSaveCheckbox( XComponentContext xContext )
+ {
+ XPropertySet xSaveCheck = getPropSet( "SaveBox" );
+ try
+ {
+ xSaveCheck.setPropertyValue( "State", new Short( (short)0 ) );
+ xSaveCheck.setPropertyValue( "Enabled", new Boolean( Helper.PasswordStoringIsAllowed( xContext ) ) );
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
}
public boolean callHandlerMethod( XDialog xDialog, Object EventObject, String MethodName )
{
if ( MethodName.equals( sOKMethod ) )
{
+ String sRedirectURL = "";
+ String sURL = "";
try
{
- String sURL = ( String ) getPropSet( "UrlField" ).getPropertyValue( "Text" );
+ sURL = ( String ) getPropSet( "UrlField" ).getPropertyValue( "Text" );
String sUserName = ( String ) getPropSet( "UsernameField" ).getPropertyValue( "Text" );
String sPassword = ( String ) getPropSet( "PasswordField" ).getPropertyValue( "Text" );
- String sRedirectURL = "";
HostConfiguration aHostConfig = new HostConfiguration();
boolean bInitHost = true;
@@ -135,7 +153,7 @@ public class WikiEditSettingDialog extends WikiDialog
if ( sRedirectURL.equals( "" ) )
{
// show error
- ErrorDialog ed = new ErrorDialog( m_xContext, "vnd.sun.star.script:WikiEditor.Error?location=application", "A connection to the MediaWiki system at '" + sRedirectURL + "' could not be created." );
+ ErrorDialog ed = new ErrorDialog( m_xContext, "vnd.sun.star.script:WikiEditor.Error?location=application", "A connection to the MediaWiki system at '" + sURL + "' could not be created." );
ed.show();
}
}
@@ -157,6 +175,20 @@ public class WikiEditSettingDialog extends WikiDialog
if ( addMode )
Settings.getSettings( m_xContext ).addWikiCon( setting );
+ if ( Helper.PasswordStoringIsAllowed( m_xContext )
+ && ( (Short)( getPropSet( "SaveBox" ).getPropertyValue("State") ) ) != 0 )
+ {
+ String[] pPasswords = { sPassword };
+ try
+ {
+ Helper.GetPasswordContainer( m_xContext ).addPersistent( sMainURL, sUserName, pPasswords, Helper.GetInteractionHandler( m_xContext ) );
+ }
+ catch( Exception e )
+ {
+ e.printStackTrace();
+ }
+ }
+
m_bAction = true;
xDialog.endExecute();
}
@@ -182,7 +214,7 @@ public class WikiEditSettingDialog extends WikiDialog
}
catch ( Exception ex )
{
- ErrorDialog ed = new ErrorDialog( m_xContext, "vnd.sun.star.script:WikiEditor.Error?location=application", "A connection to the MediaWiki system at '" + sRedirectURL + "' could not be created." );
+ ErrorDialog ed = new ErrorDialog( m_xContext, "vnd.sun.star.script:WikiEditor.Error?location=application", "A connection to the MediaWiki system at '" + sURL + "' could not be created." );
ed.show();
ex.printStackTrace();