summaryrefslogtreecommitdiff
path: root/svtools/source/passwordcontainer
diff options
context:
space:
mode:
Diffstat (limited to 'svtools/source/passwordcontainer')
-rw-r--r--svtools/source/passwordcontainer/makefile.mk3
-rw-r--r--svtools/source/passwordcontainer/passwordcontainer.cxx151
-rw-r--r--svtools/source/passwordcontainer/syscreds.cxx298
-rw-r--r--svtools/source/passwordcontainer/syscreds.hxx95
4 files changed, 492 insertions, 55 deletions
diff --git a/svtools/source/passwordcontainer/makefile.mk b/svtools/source/passwordcontainer/makefile.mk
index 70692ecbf06b..31e1336ad966 100644
--- a/svtools/source/passwordcontainer/makefile.mk
+++ b/svtools/source/passwordcontainer/makefile.mk
@@ -43,7 +43,8 @@ DLLPRE=
# --- Files -------------------------------------
SLOFILES= \
- $(SLO)$/passwordcontainer.obj
+ $(SLO)$/passwordcontainer.obj\
+ $(SLO)$/syscreds.obj
SHL1TARGET= $(TARGET)
SHL1IMPLIB= i$(TARGET)
diff --git a/svtools/source/passwordcontainer/passwordcontainer.cxx b/svtools/source/passwordcontainer/passwordcontainer.cxx
index 9855e7e3c487..cebde0705f12 100644
--- a/svtools/source/passwordcontainer/passwordcontainer.cxx
+++ b/svtools/source/passwordcontainer/passwordcontainer.cxx
@@ -152,10 +152,17 @@ static vector< ::rtl::OUString > getInfoFromInd( ::rtl::OUString aInd )
static sal_Bool shorterUrl( ::rtl::OUString& aURL )
{
sal_Int32 aInd = aURL.lastIndexOf( sal_Unicode( '/' ) );
- if( aInd > 0 && aURL.indexOf( ::rtl::OUString::createFromAscii( "://" ) ) != aInd-2 )
+
+ if( aInd > 0 )
{
- aURL = aURL.copy( 0, aInd );
- return sal_True;
+ sal_Int32 aPrevInd = aURL.lastIndexOf( sal_Unicode( '/' ), aInd );
+ if ( aURL.indexOf( ::rtl::OUString::createFromAscii( "://" ) )
+ != aPrevInd - 2 ||
+ aInd != aURL.getLength() - 1 )
+ {
+ aURL = aURL.copy( 0, aInd );
+ return sal_True;
+ }
}
return sal_False;
@@ -753,37 +760,14 @@ void PasswordContainer::PrivateAdd( const ::rtl::OUString& Url, const ::rtl::OUS
UrlRecord SAL_CALL PasswordContainer::find( const ::rtl::OUString& aURL, const Reference< XInteractionHandler >& aHandler ) throw(RuntimeException)
{
- ::osl::MutexGuard aGuard( mMutex );
-
- if( !m_aContainer.empty() )
- {
- ::rtl::OUString aUrl( aURL );
- PassMap::iterator aIter = m_aContainer.find( aUrl );
-
- if( aIter != m_aContainer.end() )
- return UrlRecord( aIter->first, CopyToUserRecordSequence( aIter->second, aHandler ) );
-
- // each iteration remove last '/...' section from the aUrl
- // while it's possible, up to the most left '://'
- while( shorterUrl( aUrl ) )
- {
- // first look for <url>/somename and then look for <url>/somename/...
- aIter = m_aContainer.find( aUrl );
- if( aIter != m_aContainer.end() )
- return UrlRecord( aIter->first, CopyToUserRecordSequence( aIter->second, aHandler ) );
- else
- {
- ::rtl::OUString tmpUrl( aUrl );
- tmpUrl += ::rtl::OUString::createFromAscii( "/" );
+ return find( aURL, rtl::OUString(), false, aHandler );
+}
- aIter = m_aContainer.lower_bound( aUrl );
- if( aIter != m_aContainer.end() )
- return UrlRecord( aIter->first, CopyToUserRecordSequence( aIter->second, aHandler ) );
- }
- }
- }
+//-------------------------------------------------------------------------
- return UrlRecord();
+UrlRecord SAL_CALL PasswordContainer::findForName( const ::rtl::OUString& aURL, const ::rtl::OUString& aName, const Reference< XInteractionHandler >& aHandler ) throw(RuntimeException)
+{
+ return find( aURL, aName, true, aHandler );
}
//-------------------------------------------------------------------------
@@ -810,48 +794,76 @@ Sequence< UserRecord > PasswordContainer::FindUsr( const list< NamePassRecord >&
//-------------------------------------------------------------------------
-UrlRecord SAL_CALL PasswordContainer::findForName( const ::rtl::OUString& aURL, const ::rtl::OUString& aName, const Reference< XInteractionHandler >& aHandler ) throw(RuntimeException)
+bool PasswordContainer::createUrlRecord(
+ const PassMap::iterator & rIter,
+ bool bName,
+ const ::rtl::OUString & aName,
+ const Reference< XInteractionHandler >& aHandler,
+ UrlRecord & rRec )
+ throw( RuntimeException )
{
+ if ( bName )
+ {
+ Sequence< UserRecord > aUsrRec
+ = FindUsr( rIter->second, aName, aHandler );
+ if( aUsrRec.getLength() )
+ {
+ rRec = UrlRecord( rIter->first, aUsrRec );
+ return true;
+ }
+ }
+ else
+ {
+ rRec = UrlRecord(
+ rIter->first,
+ CopyToUserRecordSequence( rIter->second, aHandler ) );
+ return true;
+ }
+ return false;
+}
+
+//-------------------------------------------------------------------------
+UrlRecord PasswordContainer::find(
+ const ::rtl::OUString& aURL,
+ const ::rtl::OUString& aName,
+ bool bName, // only needed to support empty user names
+ const Reference< XInteractionHandler >& aHandler ) throw(RuntimeException)
+{
::osl::MutexGuard aGuard( mMutex );
- if( !m_aContainer.empty() )
+
+ if( !m_aContainer.empty() && aURL.getLength() )
{
::rtl::OUString aUrl( aURL );
- PassMap::iterator aIter = m_aContainer.find( aUrl );
-
- if( aIter != m_aContainer.end() )
- {
- Sequence< UserRecord > aUsrRec = FindUsr( aIter->second, aName, aHandler );
- if( aUsrRec.getLength() )
- return UrlRecord( aIter->first, aUsrRec );
- }
// each iteration remove last '/...' section from the aUrl
// while it's possible, up to the most left '://'
- while( shorterUrl( aUrl ) )
+ do
{
// first look for <url>/somename and then look for <url>/somename/...
- aIter = m_aContainer.find( aUrl );
+ PassMap::iterator aIter = m_aContainer.find( aUrl );
if( aIter != m_aContainer.end() )
{
- Sequence< UserRecord > aUsrRec = FindUsr( aIter->second, aName, aHandler );
- if( aUsrRec.getLength() )
- return UrlRecord( aIter->first, aUsrRec );
+ UrlRecord aRec;
+ if ( createUrlRecord( aIter, bName, aName, aHandler, aRec ) )
+ return aRec;
}
else
{
::rtl::OUString tmpUrl( aUrl );
- tmpUrl += ::rtl::OUString::createFromAscii( "/" );
+ if ( tmpUrl.getStr()[tmpUrl.getLength() - 1] != (sal_Unicode)'/' )
+ tmpUrl += ::rtl::OUString::createFromAscii( "/" );
- aIter = m_aContainer.lower_bound( aUrl );
- if( aIter != m_aContainer.end() )
+ aIter = m_aContainer.lower_bound( tmpUrl );
+ if( aIter != m_aContainer.end() && aIter->first.match( tmpUrl ) )
{
- Sequence< UserRecord > aUsrRec = FindUsr( aIter->second, aName, aHandler );
- if( aUsrRec.getLength() )
- return UrlRecord( aIter->first, aUsrRec );
+ UrlRecord aRec;
+ if ( createUrlRecord( aIter, bName, aName, aHandler, aRec ) )
+ return aRec;
}
}
}
+ while( shorterUrl( aUrl ) && aUrl.getLength() );
}
return UrlRecord();
@@ -1355,6 +1367,35 @@ void SAL_CALL PasswordContainer::removeMasterPassword()
return ( m_pStorageFile->useStorage() && m_pStorageFile->getEncodedMP( aEncodedMP ) && !aEncodedMP.getLength() );
}
+
+//-------------------------------------------------------------------------
+void SAL_CALL PasswordContainer::addUrl( const ::rtl::OUString& Url, ::sal_Bool MakePersistent )
+ throw (uno::RuntimeException)
+{
+ mUrlContainer.add( Url, MakePersistent );
+}
+
+//-------------------------------------------------------------------------
+::rtl::OUString SAL_CALL PasswordContainer::findUrl( const ::rtl::OUString& Url )
+ throw (uno::RuntimeException)
+{
+ return mUrlContainer.find( Url );
+}
+
+//-------------------------------------------------------------------------
+void SAL_CALL PasswordContainer::removeUrl( const ::rtl::OUString& Url )
+ throw (uno::RuntimeException)
+{
+ mUrlContainer.remove( Url );
+}
+
+//-------------------------------------------------------------------------
+uno::Sequence< ::rtl::OUString > SAL_CALL PasswordContainer::getUrls( ::sal_Bool OnlyPersistent )
+ throw (uno::RuntimeException)
+{
+ return mUrlContainer.list( OnlyPersistent );
+}
+
//-------------------------------------------------------------------------
void PasswordContainer::Notify()
@@ -1487,7 +1528,9 @@ MasterPasswordRequest_Impl::MasterPasswordRequest_Impl( PasswordRequestMode Mode
aRememberModes, // rRememberPasswordModes
RememberAuthentication_NO, // eDefaultRememberPasswordMode
aRememberModes, // rRememberAccountModes
- RememberAuthentication_NO // eDefaultRememberAccountMode
+ RememberAuthentication_NO, // eDefaultRememberAccountMode
+ sal_False, // bCanUseSystemCredentials
+ sal_False // bDefaultUseSystemCredentials
);
Sequence<
diff --git a/svtools/source/passwordcontainer/syscreds.cxx b/svtools/source/passwordcontainer/syscreds.cxx
new file mode 100644
index 000000000000..b8c223040e6d
--- /dev/null
+++ b/svtools/source/passwordcontainer/syscreds.cxx
@@ -0,0 +1,298 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: $
+ * $Revision: $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "syscreds.hxx"
+#include "com/sun/star/beans/PropertyValue.hpp"
+
+using namespace com::sun::star;
+
+SysCredentialsConfigItem::SysCredentialsConfigItem(
+ SysCredentialsConfig * pOwner )
+: utl::ConfigItem( rtl::OUString::createFromAscii( "Office.Common/Passwords" ),
+ CONFIG_MODE_IMMEDIATE_UPDATE ),
+ m_bInited( false ),
+ m_pOwner( pOwner )
+{
+ uno::Sequence< ::rtl::OUString > aNode( 1 );
+ aNode[ 0 ] = rtl::OUString::createFromAscii(
+ "Office.Common/Passwords/AuthenticateUsingSystemCredentials" );
+ EnableNotification( aNode );
+}
+
+//virtual
+void SysCredentialsConfigItem::Notify(
+ const uno::Sequence< rtl::OUString > & /*seqPropertyNames*/ )
+{
+ {
+ ::osl::MutexGuard aGuard( m_aMutex );
+ m_bInited = false;
+ // rebuild m_seqURLs
+ getSystemCredentialsURLs();
+ }
+ m_pOwner->persistentConfigChanged();
+}
+
+uno::Sequence< rtl::OUString >
+SysCredentialsConfigItem::getSystemCredentialsURLs()
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ if ( !m_bInited )
+ {
+ // read config item
+ uno::Sequence< ::rtl::OUString > aPropNames( 1 );
+ aPropNames[ 0 ] = rtl::OUString::createFromAscii(
+ "AuthenticateUsingSystemCredentials" );
+ uno::Sequence< uno::Any > aAnyValues(
+ utl::ConfigItem::GetProperties( aPropNames ) );
+
+ OSL_ENSURE(
+ aAnyValues.getLength() == 1,
+ "SysCredentialsConfigItem::getSystemCredentialsURLs: "
+ "Error reading config item!" );
+
+ uno::Sequence< rtl::OUString > aValues;
+ if ( ( aAnyValues[ 0 ] >>= aValues ) ||
+ ( !aAnyValues[ 0 ].hasValue() ) )
+ {
+ m_seqURLs = aValues;
+ m_bInited = true;
+ }
+ }
+ return m_seqURLs;
+}
+
+void SysCredentialsConfigItem::setSystemCredentialsURLs(
+ const uno::Sequence< rtl::OUString > & seqURLList )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ // write config item.
+ uno::Sequence< rtl::OUString > aPropNames( 1 );
+ uno::Sequence< uno::Any > aPropValues( 1 );
+ aPropNames[ 0 ]
+ = ::rtl::OUString::createFromAscii(
+ "AuthenticateUsingSystemCredentials" );
+ aPropValues[ 0 ] <<= seqURLList;
+
+ utl::ConfigItem::SetModified();
+ utl::ConfigItem::PutProperties( aPropNames, aPropValues );
+
+ m_seqURLs = seqURLList;
+ m_bInited = true;
+}
+
+//============================================================================
+
+namespace
+{
+ // TODO: This code is actually copied from svtools/source/passwordcontainer.cxx
+ bool removeLastSegment( ::rtl::OUString & aURL )
+ {
+ sal_Int32 aInd = aURL.lastIndexOf( sal_Unicode( '/' ) );
+
+ if( aInd > 0 )
+ {
+ sal_Int32 aPrevInd = aURL.lastIndexOf( sal_Unicode( '/' ), aInd );
+ if ( aURL.indexOf( ::rtl::OUString::createFromAscii( "://" ) )
+ != aPrevInd - 2 ||
+ aInd != aURL.getLength() - 1 )
+ {
+ aURL = aURL.copy( 0, aInd );
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ bool findURL( StringSet const & rContainer, rtl::OUString const & aURL, rtl::OUString & aResult )
+ {
+ // TODO: This code is actually copied from svtools/source/passwordcontainer.cxx
+ if( !rContainer.empty() && aURL.getLength() )
+ {
+ ::rtl::OUString aUrl( aURL );
+
+ // each iteration remove last '/...' section from the aUrl
+ // while it's possible, up to the most left '://'
+ do
+ {
+ // first look for <url>/somename and then look for <url>/somename/...
+ StringSet::const_iterator aIter = rContainer.find( aUrl );
+ if( aIter != rContainer.end() )
+ {
+ aResult = *aIter;
+ return true;
+ }
+ else
+ {
+ ::rtl::OUString tmpUrl( aUrl );
+ if ( tmpUrl.getStr()[tmpUrl.getLength() - 1] != (sal_Unicode)'/' )
+ tmpUrl += ::rtl::OUString::createFromAscii( "/" );
+
+ aIter = rContainer.lower_bound( tmpUrl );
+ if( aIter != rContainer.end() && aIter->match( tmpUrl ) )
+ {
+ aResult = *aIter;
+ return true;
+ }
+ }
+ }
+ while( removeLastSegment( aUrl ) && aUrl.getLength() );
+ }
+ aResult = rtl::OUString();
+ return false;
+ }
+
+} // namespace
+
+SysCredentialsConfig::SysCredentialsConfig()
+: m_aConfigItem( this ),
+ m_bCfgInited( false )
+{
+}
+
+void SysCredentialsConfig::initCfg()
+{
+ osl::MutexGuard aGuard( m_aMutex );
+ if ( !m_bCfgInited )
+ {
+ uno::Sequence< rtl::OUString > aURLs(
+ m_aConfigItem.getSystemCredentialsURLs() );
+ for ( sal_Int32 n = 0; n < aURLs.getLength(); ++n )
+ m_aCfgContainer.insert( aURLs[ n ] );
+
+ m_bCfgInited = true;
+ }
+}
+
+void SysCredentialsConfig::writeCfg()
+{
+ osl::MutexGuard aGuard( m_aMutex );
+
+ OSL_ENSURE( m_bCfgInited, "SysCredentialsConfig::writeCfg : not initialized!" );
+
+ uno::Sequence< rtl::OUString > aURLs( m_aCfgContainer.size() );
+ StringSet::const_iterator it = m_aCfgContainer.begin();
+ const StringSet::const_iterator end = m_aCfgContainer.end();
+ sal_Int32 n = 0;
+
+ while ( it != end )
+ {
+ aURLs[ n ] = *it;
+ ++it;
+ ++n;
+ }
+
+ m_aConfigItem.setSystemCredentialsURLs( aURLs );
+}
+
+rtl::OUString SysCredentialsConfig::find( rtl::OUString const & aURL )
+{
+ osl::MutexGuard aGuard( m_aMutex );
+ rtl::OUString aResult;
+ if ( findURL( m_aMemContainer, aURL, aResult ) )
+ return aResult;
+
+ initCfg();
+ if ( findURL( m_aCfgContainer, aURL, aResult ) )
+ return aResult;
+
+ return rtl::OUString();
+}
+
+void SysCredentialsConfig::add( rtl::OUString const & rURL, bool bPersistent )
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+
+ if ( bPersistent )
+ {
+ m_aMemContainer.erase( rURL );
+
+ initCfg();
+ m_aCfgContainer.insert( rURL );
+ writeCfg();
+ }
+ else
+ {
+ initCfg();
+ if ( m_aCfgContainer.erase( rURL ) > 0 )
+ writeCfg();
+
+ m_aMemContainer.insert( rURL );
+ }
+}
+
+void SysCredentialsConfig::remove( rtl::OUString const & rURL )
+{
+ m_aMemContainer.erase( rURL );
+
+ initCfg();
+ if ( m_aCfgContainer.erase( rURL ) > 0 )
+ writeCfg();
+}
+
+uno::Sequence< rtl::OUString > SysCredentialsConfig::list( bool bOnlyPersistent )
+{
+ initCfg();
+ sal_Int32 nCount = m_aCfgContainer.size()
+ + ( bOnlyPersistent ? 0 : m_aMemContainer.size() );
+ uno::Sequence< rtl::OUString > aResult( nCount );
+
+ StringSet::const_iterator it = m_aCfgContainer.begin();
+ StringSet::const_iterator end = m_aCfgContainer.end();
+ sal_Int32 n = 0;
+
+ while ( it != end )
+ {
+ aResult[ n ] = *it;
+ ++it;
+ ++n;
+ }
+
+ if ( !bOnlyPersistent )
+ {
+ it = m_aMemContainer.begin();
+ end = m_aMemContainer.end();
+
+ while ( it != end )
+ {
+ aResult[ n ] = *it;
+ ++it;
+ ++n;
+ }
+ }
+ return aResult;
+}
+
+void SysCredentialsConfig::persistentConfigChanged()
+{
+ ::osl::MutexGuard aGuard( m_aMutex );
+ m_bCfgInited = false; // re-init on demand.
+}
diff --git a/svtools/source/passwordcontainer/syscreds.hxx b/svtools/source/passwordcontainer/syscreds.hxx
new file mode 100644
index 000000000000..b037e17c348e
--- /dev/null
+++ b/svtools/source/passwordcontainer/syscreds.hxx
@@ -0,0 +1,95 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: $
+ * $Revision: $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_SVTOOLS_SYSCREDS_HXX
+#define INCLUDED_SVTOOLS_SYSCREDS_HXX
+
+#include <set>
+#include <memory>
+#include "osl/mutex.hxx"
+#include "rtl/ustring.hxx"
+#include "com/sun/star/uno/Sequence.hxx"
+#include "unotools/configitem.hxx"
+
+class SysCredentialsConfig;
+
+class SysCredentialsConfigItem : public utl::ConfigItem
+{
+ public:
+ SysCredentialsConfigItem( SysCredentialsConfig * pOwner );
+ //virtual ~SysCredentialsConfigItem();
+
+ virtual void Notify(
+ const com::sun::star::uno::Sequence< rtl::OUString > &
+ seqPropertyNames );
+ //virtual void Commit();
+
+ com::sun::star::uno::Sequence< rtl::OUString >
+ getSystemCredentialsURLs();
+
+ void setSystemCredentialsURLs(
+ const com::sun::star::uno::Sequence< rtl::OUString > &
+ seqURLList );
+
+ //bool isSystemCredentialsURL( const rtl::OUString & rURL ) const;
+
+private:
+ ::osl::Mutex m_aMutex;
+ bool m_bInited;
+ com::sun::star::uno::Sequence< rtl::OUString > m_seqURLs;
+ SysCredentialsConfig * m_pOwner;
+};
+
+typedef std::set< rtl::OUString > StringSet;
+
+class SysCredentialsConfig
+{
+ public:
+ SysCredentialsConfig();
+
+ rtl::OUString find( rtl::OUString const & rURL );
+ void add( rtl::OUString const & rURL, bool bPersistent );
+ void remove( rtl::OUString const & rURL );
+ com::sun::star::uno::Sequence< rtl::OUString > list( bool bOnlyPersistent );
+
+ void persistentConfigChanged();
+
+ private:
+ void initCfg();
+ void writeCfg();
+
+ ::osl::Mutex m_aMutex;
+ StringSet m_aMemContainer;
+ StringSet m_aCfgContainer;
+ SysCredentialsConfigItem m_aConfigItem;
+ bool m_bCfgInited;
+};
+
+#endif // INCLUDED_SVTOOLS_SYSCREDS_HXX