1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_ucbhelper.hxx" 30 #include <com/sun/star/task/XMasterPasswordHandling.hpp> 31 #include <com/sun/star/ucb/URLAuthenticationRequest.hpp> 32 #include <ucbhelper/simpleauthenticationrequest.hxx> 33 34 using namespace com::sun::star; 35 using namespace ucbhelper; 36 37 //========================================================================= 38 SimpleAuthenticationRequest::SimpleAuthenticationRequest( 39 const rtl::OUString & rURL, 40 const rtl::OUString & rServerName, 41 const rtl::OUString & rRealm, 42 const rtl::OUString & rUserName, 43 const rtl::OUString & rPassword, 44 const rtl::OUString & rAccount ) 45 { 46 // Fill request... 47 ucb::URLAuthenticationRequest aRequest; 48 // aRequest.Message = // OUString 49 // aRequest.Context = // XInterface 50 aRequest.Classification = task::InteractionClassification_ERROR; 51 aRequest.ServerName = rServerName; 52 // aRequest.Diagnostic = // OUString 53 aRequest.HasRealm = ( rRealm.getLength() > 0 ); 54 if ( aRequest.HasRealm ) 55 aRequest.Realm = rRealm; 56 aRequest.HasUserName = sal_True; 57 aRequest.UserName = rUserName; 58 aRequest.HasPassword = sal_True; 59 aRequest.Password = rPassword; 60 aRequest.HasAccount = ( rAccount.getLength() > 0 ); 61 if ( aRequest.HasAccount ) 62 aRequest.Account = rAccount; 63 aRequest.URL = rURL; 64 65 initialize(aRequest, 66 sal_False, 67 sal_True, 68 sal_True, 69 aRequest.HasAccount, 70 sal_True, 71 sal_False ); 72 } 73 //========================================================================= 74 SimpleAuthenticationRequest::SimpleAuthenticationRequest( 75 const rtl::OUString & rURL, 76 const rtl::OUString & rServerName, 77 const rtl::OUString & rRealm, 78 const rtl::OUString & rUserName, 79 const rtl::OUString & rPassword, 80 const rtl::OUString & rAccount, 81 sal_Bool bAllowPersistentStoring, 82 sal_Bool bAllowUseSystemCredentials ) 83 { 84 85 // Fill request... 86 ucb::URLAuthenticationRequest aRequest; 87 // aRequest.Message = // OUString 88 // aRequest.Context = // XInterface 89 aRequest.Classification = task::InteractionClassification_ERROR; 90 aRequest.ServerName = rServerName; 91 // aRequest.Diagnostic = // OUString 92 aRequest.HasRealm = ( rRealm.getLength() > 0 ); 93 if ( aRequest.HasRealm ) 94 aRequest.Realm = rRealm; 95 aRequest.HasUserName = sal_True; 96 aRequest.UserName = rUserName; 97 aRequest.HasPassword = sal_True; 98 aRequest.Password = rPassword; 99 aRequest.HasAccount = ( rAccount.getLength() > 0 ); 100 if ( aRequest.HasAccount ) 101 aRequest.Account = rAccount; 102 aRequest.URL = rURL; 103 104 initialize(aRequest, 105 sal_False, 106 sal_True, 107 sal_True, 108 aRequest.HasAccount, 109 bAllowPersistentStoring, 110 bAllowUseSystemCredentials ); 111 } 112 113 //========================================================================= 114 SimpleAuthenticationRequest::SimpleAuthenticationRequest( 115 const rtl::OUString & rURL, 116 const rtl::OUString & rServerName, 117 EntityType eRealmType, 118 const rtl::OUString & rRealm, 119 EntityType eUserNameType, 120 const rtl::OUString & rUserName, 121 EntityType ePasswordType, 122 const rtl::OUString & rPassword, 123 EntityType eAccountType, 124 const rtl::OUString & rAccount ) 125 { 126 // Fill request... 127 ucb::URLAuthenticationRequest aRequest; 128 // aRequest.Message = // OUString 129 // aRequest.Context = // XInterface 130 aRequest.Classification = task::InteractionClassification_ERROR; 131 aRequest.ServerName = rServerName; 132 // aRequest.Diagnostic = // OUString 133 aRequest.HasRealm = eRealmType != ENTITY_NA; 134 if ( aRequest.HasRealm ) 135 aRequest.Realm = rRealm; 136 aRequest.HasUserName = eUserNameType != ENTITY_NA; 137 if ( aRequest.HasUserName ) 138 aRequest.UserName = rUserName; 139 aRequest.HasPassword = ePasswordType != ENTITY_NA; 140 if ( aRequest.HasPassword ) 141 aRequest.Password = rPassword; 142 aRequest.HasAccount = eAccountType != ENTITY_NA; 143 if ( aRequest.HasAccount ) 144 aRequest.Account = rAccount; 145 aRequest.URL = rURL; 146 147 initialize(aRequest, 148 eRealmType == ENTITY_MODIFY, 149 eUserNameType == ENTITY_MODIFY, 150 ePasswordType == ENTITY_MODIFY, 151 eAccountType == ENTITY_MODIFY, 152 sal_True, 153 sal_False ); 154 } 155 156 //========================================================================= 157 SimpleAuthenticationRequest::SimpleAuthenticationRequest( 158 const rtl::OUString & rURL, 159 const rtl::OUString & rServerName, 160 EntityType eRealmType, 161 const rtl::OUString & rRealm, 162 EntityType eUserNameType, 163 const rtl::OUString & rUserName, 164 EntityType ePasswordType, 165 const rtl::OUString & rPassword, 166 EntityType eAccountType, 167 const rtl::OUString & rAccount, 168 sal_Bool bAllowPersistentStoring, 169 sal_Bool bAllowUseSystemCredentials ) 170 { 171 // Fill request... 172 ucb::URLAuthenticationRequest aRequest; 173 // aRequest.Message = // OUString 174 // aRequest.Context = // XInterface 175 aRequest.Classification = task::InteractionClassification_ERROR; 176 aRequest.ServerName = rServerName; 177 // aRequest.Diagnostic = // OUString 178 aRequest.HasRealm = eRealmType != ENTITY_NA; 179 if ( aRequest.HasRealm ) 180 aRequest.Realm = rRealm; 181 aRequest.HasUserName = eUserNameType != ENTITY_NA; 182 if ( aRequest.HasUserName ) 183 aRequest.UserName = rUserName; 184 aRequest.HasPassword = ePasswordType != ENTITY_NA; 185 if ( aRequest.HasPassword ) 186 aRequest.Password = rPassword; 187 aRequest.HasAccount = eAccountType != ENTITY_NA; 188 if ( aRequest.HasAccount ) 189 aRequest.Account = rAccount; 190 aRequest.URL = rURL; 191 192 initialize(aRequest, 193 eRealmType == ENTITY_MODIFY, 194 eUserNameType == ENTITY_MODIFY, 195 ePasswordType == ENTITY_MODIFY, 196 eAccountType == ENTITY_MODIFY, 197 bAllowPersistentStoring, 198 bAllowUseSystemCredentials ); 199 } 200 201 //========================================================================= 202 void SimpleAuthenticationRequest::initialize( 203 const ucb::URLAuthenticationRequest & rRequest, 204 sal_Bool bCanSetRealm, 205 sal_Bool bCanSetUserName, 206 sal_Bool bCanSetPassword, 207 sal_Bool bCanSetAccount, 208 sal_Bool bAllowPersistentStoring, 209 sal_Bool bAllowUseSystemCredentials ) 210 { 211 setRequest( uno::makeAny( rRequest ) ); 212 213 // Fill continuations... 214 uno::Sequence< ucb::RememberAuthentication > aRememberModes( 215 bAllowPersistentStoring ? 3 : 2 ); 216 aRememberModes[ 0 ] = ucb::RememberAuthentication_NO; 217 aRememberModes[ 1 ] = ucb::RememberAuthentication_SESSION; 218 if (bAllowPersistentStoring) 219 aRememberModes[ 2 ] = ucb::RememberAuthentication_PERSISTENT; 220 221 m_xAuthSupplier 222 = new InteractionSupplyAuthentication( 223 this, 224 bCanSetRealm, 225 bCanSetUserName, 226 bCanSetPassword, 227 bCanSetAccount, 228 aRememberModes, // rRememberPasswordModes 229 ucb::RememberAuthentication_SESSION, // eDefaultRememberPasswordMode 230 aRememberModes, // rRememberAccountModes 231 ucb::RememberAuthentication_SESSION, // eDefaultRememberAccountMode 232 bAllowUseSystemCredentials, // bCanUseSystemCredentials, 233 false // bDefaultUseSystemCredentials 234 ); 235 236 uno::Sequence< 237 uno::Reference< task::XInteractionContinuation > > aContinuations( 3 ); 238 aContinuations[ 0 ] = new InteractionAbort( this ); 239 aContinuations[ 1 ] = new InteractionRetry( this ); 240 aContinuations[ 2 ] = m_xAuthSupplier.get(); 241 242 setContinuations( aContinuations ); 243 } 244