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