Kaydet (Commit) 0abb975d authored tarafından Mikhail Voitenko's avatar Mikhail Voitenko

use password container to store passwords

üst 7f1c15e5
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
* *
* $RCSfile: EditSetting.xdl,v $ * $RCSfile: EditSetting.xdl,v $
* *
* $Revision: 1.2 $ * $Revision: 1.3 $
* *
* last change: $Author: mav $ $Date: 2007-11-28 10:57:45 $ * last change: $Author: mav $ $Date: 2007-12-13 15:11:05 $
* *
* The Contents of this file are made available subject to * The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1. * the terms of GNU Lesser General Public License Version 2.1.
...@@ -49,10 +49,9 @@ ...@@ -49,10 +49,9 @@
<dlg:button dlg:id="All.HelpButton" dlg:tab-index="11" dlg:left="6" dlg:top="139" dlg:width="50" dlg:height="14" dlg:help-url="HID:31702" dlg:value="Help"> <dlg:button dlg:id="All.HelpButton" dlg:tab-index="11" dlg:left="6" dlg:top="139" dlg:width="50" dlg:height="14" dlg:help-url="HID:31702" dlg:value="Help">
<script:event script:event-name="on-performaction" script:macro-name="vnd.sun.star.UNO:Help" script:language="UNO"/> <script:event script:event-name="on-performaction" script:macro-name="vnd.sun.star.UNO:Help" script:language="UNO"/>
</dlg:button> </dlg:button>
<dlg:fixedline dlg:id="All.WeblogLabel" dlg:tab-index="0" dlg:left="3" dlg:top="4" dlg:width="180" dlg:height="8" dlg:value="Weblog"/>
<dlg:text dlg:id="All.UsernameLabel" dlg:tab-index="6" dlg:left="6" dlg:top="93" dlg:width="46" dlg:height="8" dlg:value="Username" dlg:tabstop="false"/> <dlg:text dlg:id="All.UsernameLabel" dlg:tab-index="6" dlg:left="6" dlg:top="93" dlg:width="46" dlg:height="8" dlg:value="Username" dlg:tabstop="false"/>
<dlg:text dlg:id="All.PasswordLabel" dlg:tab-index="8" dlg:left="6" dlg:top="109" dlg:width="46" dlg:height="8" dlg:value="Password" dlg:tabstop="false"/> <dlg:text dlg:id="All.PasswordLabel" dlg:tab-index="8" dlg:left="6" dlg:top="109" dlg:width="46" dlg:height="8" dlg:value="Password" dlg:tabstop="false"/>
<dlg:checkbox dlg:id="All.SaveBox" dlg:tab-index="10" dlg:left="58" dlg:top="123" dlg:width="116" dlg:height="8" dlg:help-url="HID:31699" dlg:value="Save password" dlg:checked="false"/> <dlg:checkbox dlg:id="SaveBox" dlg:tab-index="10" dlg:left="58" dlg:top="123" dlg:width="116" dlg:height="8" dlg:help-url="HID:31699" dlg:value="Save password" dlg:checked="false"/>
<dlg:fixedline dlg:id="BottomLine" dlg:tab-index="1" dlg:left="0" dlg:top="131" dlg:width="186" dlg:height="8"/> <dlg:fixedline dlg:id="BottomLine" dlg:tab-index="1" dlg:left="0" dlg:top="131" dlg:width="186" dlg:height="8"/>
<dlg:fixedline dlg:id="AccountLine" dlg:tab-index="2" dlg:left="3" dlg:top="80" dlg:width="180" dlg:height="8" dlg:value="Account"/> <dlg:fixedline dlg:id="AccountLine" dlg:tab-index="2" dlg:left="3" dlg:top="80" dlg:width="180" dlg:height="8" dlg:value="Account"/>
<dlg:fixedline dlg:id="WikiLine" dlg:tab-index="3" dlg:left="3" dlg:top="4" dlg:width="180" dlg:height="8" dlg:value="Wiki"/> <dlg:fixedline dlg:id="WikiLine" dlg:tab-index="3" dlg:left="3" dlg:top="4" dlg:width="180" dlg:height="8" dlg:value="Wiki"/>
......
...@@ -5,9 +5,9 @@ ...@@ -5,9 +5,9 @@
* *
* $RCSfile: SendToMediaWiki.xdl,v $ * $RCSfile: SendToMediaWiki.xdl,v $
* *
* $Revision: 1.3 $ * $Revision: 1.4 $
* *
* last change: $Author: mav $ $Date: 2007-11-28 16:43:08 $ * last change: $Author: mav $ $Date: 2007-12-13 15:11:05 $
* *
* The Contents of this file are made available subject to * The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1. * the terms of GNU Lesser General Public License Version 2.1.
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
* *
************************************************************************ --> ************************************************************************ -->
<!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd"> <!DOCTYPE dlg:window PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "dialog.dtd">
<dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="SendToMediaWiki" dlg:left="62" dlg:top="57" dlg:width="288" dlg:height="129" dlg:closeable="true" dlg:moveable="true"> <dlg:window xmlns:dlg="http://openoffice.org/2000/dialog" xmlns:script="http://openoffice.org/2000/script" dlg:id="SendToMediaWiki" dlg:left="62" dlg:top="57" dlg:width="288" dlg:height="129" dlg:closeable="true" dlg:moveable="true" dlg:title="Send to MediaWiki">
<dlg:bulletinboard> <dlg:bulletinboard>
<dlg:text dlg:id="Label1" dlg:tab-index="0" dlg:left="9" dlg:top="10" dlg:width="62" dlg:height="10" dlg:value="~MediaWiki Server" dlg:tabstop="false"/> <dlg:text dlg:id="Label1" dlg:tab-index="0" dlg:left="9" dlg:top="10" dlg:width="62" dlg:height="10" dlg:value="~MediaWiki Server" dlg:tabstop="false"/>
<dlg:text dlg:id="Label2" dlg:tab-index="2" dlg:left="9" dlg:top="27" dlg:width="62" dlg:height="10" dlg:value="~Title"/> <dlg:text dlg:id="Label2" dlg:tab-index="2" dlg:left="9" dlg:top="27" dlg:width="62" dlg:height="10" dlg:value="~Title"/>
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
* *
* $RCSfile: Helper.java,v $ * $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 Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1. * the terms of GNU Lesser General Public License Version 2.1.
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
package com.sun.star.wiki; 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.awt.XDialog;
import com.sun.star.beans.NamedValue; import com.sun.star.beans.NamedValue;
import com.sun.star.beans.PropertyValue; import com.sun.star.beans.PropertyValue;
...@@ -53,6 +55,10 @@ import com.sun.star.lang.XMultiComponentFactory; ...@@ -53,6 +55,10 @@ import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.lang.XMultiServiceFactory; import com.sun.star.lang.XMultiServiceFactory;
import com.sun.star.system.SystemShellExecuteFlags; import com.sun.star.system.SystemShellExecuteFlags;
import com.sun.star.system.XSystemShellExecute; 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.AnyConverter;
import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext; import com.sun.star.uno.XComponentContext;
...@@ -85,6 +91,9 @@ public class Helper ...@@ -85,6 +91,9 @@ public class Helper
private static boolean m_bAllowConnection = true; private static boolean m_bAllowConnection = true;
private static Hashtable m_aAcceptedUnknownCerts; private static Hashtable m_aAcceptedUnknownCerts;
private static XPasswordContainer m_xPasswordContainer;
private static XInteractionHandler m_xInteractionHandler;
synchronized protected static HttpClient GetHttpClient() synchronized protected static HttpClient GetHttpClient()
throws WikiCancelException throws WikiCancelException
{ {
...@@ -121,6 +130,42 @@ public class Helper ...@@ -121,6 +130,42 @@ public class Helper
return m_bAllowConnection; 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 ) protected static Protocol GetOwnHttps( int nPort )
{ {
return new Protocol( "https", new WikiProtocolSocketFactory(), ( ( nPort < 0 ) ? 443 : nPort ) ); return new Protocol( "https", new WikiProtocolSocketFactory(), ( ( nPort < 0 ) ? 443 : nPort ) );
...@@ -630,7 +675,7 @@ public class Helper ...@@ -630,7 +675,7 @@ public class Helper
return null; 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 ) if ( xDialog != null && aControlName != null && aPropName != null && aPropValue != null )
{ {
...@@ -646,5 +691,37 @@ public class Helper ...@@ -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;
}
} }
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
* *
* $RCSfile: WikiArticle.java,v $ * $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 Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1. * the terms of GNU Lesser General Public License Version 2.1.
...@@ -35,13 +35,10 @@ ...@@ -35,13 +35,10 @@
package com.sun.star.wiki; package com.sun.star.wiki;
import com.sun.star.task.UrlRecord;
import java.io.*; import java.io.*;
import java.net.MalformedURLException;
import java.util.Hashtable; import java.util.Hashtable;
import javax.swing.text.html.*; 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 com.sun.star.uno.XComponentContext;
import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.*;
...@@ -87,7 +84,24 @@ public class WikiArticle ...@@ -87,7 +84,24 @@ public class WikiArticle
// loginURL = sMainUrl + "index.php?title=Special:Userlogin"; // loginURL = sMainUrl + "index.php?title=Special:Userlogin";
// loginSubmitURL = sMainUrl + "index.php?title=Special:Userlogin&action=submitlogin"; // 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 // TODO: be sure that this is no main thread
WikiEditSettingDialog wd = new WikiEditSettingDialog(m_xContext, "vnd.sun.star.script:WikiEditor.EditSetting?location=application", wikiSettings ); WikiEditSettingDialog wd = new WikiEditSettingDialog(m_xContext, "vnd.sun.star.script:WikiEditor.EditSetting?location=application", wikiSettings );
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
* *
* $RCSfile: WikiEditSettingDialog.java,v $ * $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 Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1. * the terms of GNU Lesser General Public License Version 2.1.
...@@ -36,13 +36,12 @@ ...@@ -36,13 +36,12 @@
package com.sun.star.wiki; package com.sun.star.wiki;
import com.sun.star.awt.XDialog; import com.sun.star.awt.XDialog;
import com.sun.star.beans.XPropertySet;
import com.sun.star.uno.XComponentContext; import com.sun.star.uno.XComponentContext;
import java.util.Hashtable; import java.util.Hashtable;
import javax.net.ssl.SSLException;
import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*; import org.apache.commons.httpclient.methods.*;
import org.apache.commons.httpclient.protocol.Protocol;
public class WikiEditSettingDialog extends WikiDialog public class WikiEditSettingDialog extends WikiDialog
{ {
...@@ -56,17 +55,19 @@ public class WikiEditSettingDialog extends WikiDialog ...@@ -56,17 +55,19 @@ public class WikiEditSettingDialog extends WikiDialog
private Hashtable setting; private Hashtable setting;
private boolean addMode; private boolean addMode;
public WikiEditSettingDialog( XComponentContext c, String DialogURL ) public WikiEditSettingDialog( XComponentContext xContext, String DialogURL )
{ {
super( c, DialogURL ); super( xContext, DialogURL );
super.setMethods( Methods ); super.setMethods( Methods );
setting = new Hashtable(); setting = new Hashtable();
addMode = true; 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 ); super.setMethods( Methods );
setting = ht; setting = ht;
try try
...@@ -80,18 +81,35 @@ public class WikiEditSettingDialog extends WikiDialog ...@@ -80,18 +81,35 @@ public class WikiEditSettingDialog extends WikiDialog
ex.printStackTrace(); ex.printStackTrace();
} }
addMode = false; 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 ) public boolean callHandlerMethod( XDialog xDialog, Object EventObject, String MethodName )
{ {
if ( MethodName.equals( sOKMethod ) ) if ( MethodName.equals( sOKMethod ) )
{ {
String sRedirectURL = "";
String sURL = "";
try try
{ {
String sURL = ( String ) getPropSet( "UrlField" ).getPropertyValue( "Text" ); sURL = ( String ) getPropSet( "UrlField" ).getPropertyValue( "Text" );
String sUserName = ( String ) getPropSet( "UsernameField" ).getPropertyValue( "Text" ); String sUserName = ( String ) getPropSet( "UsernameField" ).getPropertyValue( "Text" );
String sPassword = ( String ) getPropSet( "PasswordField" ).getPropertyValue( "Text" ); String sPassword = ( String ) getPropSet( "PasswordField" ).getPropertyValue( "Text" );
String sRedirectURL = "";
HostConfiguration aHostConfig = new HostConfiguration(); HostConfiguration aHostConfig = new HostConfiguration();
boolean bInitHost = true; boolean bInitHost = true;
...@@ -135,7 +153,7 @@ public class WikiEditSettingDialog extends WikiDialog ...@@ -135,7 +153,7 @@ public class WikiEditSettingDialog extends WikiDialog
if ( sRedirectURL.equals( "" ) ) if ( sRedirectURL.equals( "" ) )
{ {
// show error // 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(); ed.show();
} }
} }
...@@ -157,6 +175,20 @@ public class WikiEditSettingDialog extends WikiDialog ...@@ -157,6 +175,20 @@ public class WikiEditSettingDialog extends WikiDialog
if ( addMode ) if ( addMode )
Settings.getSettings( m_xContext ).addWikiCon( setting ); 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; m_bAction = true;
xDialog.endExecute(); xDialog.endExecute();
} }
...@@ -182,7 +214,7 @@ public class WikiEditSettingDialog extends WikiDialog ...@@ -182,7 +214,7 @@ public class WikiEditSettingDialog extends WikiDialog
} }
catch ( Exception ex ) 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(); ed.show();
ex.printStackTrace(); ex.printStackTrace();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment