1*ac9096f4SAndrew Rist /**************************************************************
2*ac9096f4SAndrew Rist  *
3*ac9096f4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*ac9096f4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*ac9096f4SAndrew Rist  * distributed with this work for additional information
6*ac9096f4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*ac9096f4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*ac9096f4SAndrew Rist  * "License"); you may not use this file except in compliance
9*ac9096f4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*ac9096f4SAndrew Rist  *
11*ac9096f4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*ac9096f4SAndrew Rist  *
13*ac9096f4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*ac9096f4SAndrew Rist  * software distributed under the License is distributed on an
15*ac9096f4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*ac9096f4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*ac9096f4SAndrew Rist  * specific language governing permissions and limitations
18*ac9096f4SAndrew Rist  * under the License.
19*ac9096f4SAndrew Rist  *
20*ac9096f4SAndrew Rist  *************************************************************/
21*ac9096f4SAndrew Rist 
22*ac9096f4SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_ucbhelper.hxx"
26cdf0e10cSrcweir #include <com/sun/star/task/XMasterPasswordHandling.hpp>
27cdf0e10cSrcweir #include <com/sun/star/ucb/URLAuthenticationRequest.hpp>
28cdf0e10cSrcweir #include <ucbhelper/simpleauthenticationrequest.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir using namespace com::sun::star;
31cdf0e10cSrcweir using namespace ucbhelper;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir //=========================================================================
SimpleAuthenticationRequest(const rtl::OUString & rURL,const rtl::OUString & rServerName,const rtl::OUString & rRealm,const rtl::OUString & rUserName,const rtl::OUString & rPassword,const rtl::OUString & rAccount)34cdf0e10cSrcweir SimpleAuthenticationRequest::SimpleAuthenticationRequest(
35cdf0e10cSrcweir                                       const rtl::OUString & rURL,
36cdf0e10cSrcweir                                       const rtl::OUString & rServerName,
37cdf0e10cSrcweir                                       const rtl::OUString & rRealm,
38cdf0e10cSrcweir                                       const rtl::OUString & rUserName,
39cdf0e10cSrcweir                                       const rtl::OUString & rPassword,
40cdf0e10cSrcweir                                       const rtl::OUString & rAccount )
41cdf0e10cSrcweir {
42cdf0e10cSrcweir     // Fill request...
43cdf0e10cSrcweir     ucb::URLAuthenticationRequest aRequest;
44cdf0e10cSrcweir //    aRequest.Message        = // OUString
45cdf0e10cSrcweir //    aRequest.Context        = // XInterface
46cdf0e10cSrcweir     aRequest.Classification = task::InteractionClassification_ERROR;
47cdf0e10cSrcweir     aRequest.ServerName     = rServerName;
48cdf0e10cSrcweir //    aRequest.Diagnostic     = // OUString
49cdf0e10cSrcweir     aRequest.HasRealm       = ( rRealm.getLength() > 0 );
50cdf0e10cSrcweir     if ( aRequest.HasRealm )
51cdf0e10cSrcweir         aRequest.Realm = rRealm;
52cdf0e10cSrcweir     aRequest.HasUserName    = sal_True;
53cdf0e10cSrcweir     aRequest.UserName       = rUserName;
54cdf0e10cSrcweir     aRequest.HasPassword    = sal_True;
55cdf0e10cSrcweir     aRequest.Password       = rPassword;
56cdf0e10cSrcweir     aRequest.HasAccount     = ( rAccount.getLength() > 0 );
57cdf0e10cSrcweir     if ( aRequest.HasAccount )
58cdf0e10cSrcweir         aRequest.Account = rAccount;
59cdf0e10cSrcweir     aRequest.URL = rURL;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     initialize(aRequest,
62cdf0e10cSrcweir        sal_False,
63cdf0e10cSrcweir        sal_True,
64cdf0e10cSrcweir        sal_True,
65cdf0e10cSrcweir        aRequest.HasAccount,
66cdf0e10cSrcweir        sal_True,
67cdf0e10cSrcweir        sal_False );
68cdf0e10cSrcweir }
69cdf0e10cSrcweir //=========================================================================
SimpleAuthenticationRequest(const rtl::OUString & rURL,const rtl::OUString & rServerName,const rtl::OUString & rRealm,const rtl::OUString & rUserName,const rtl::OUString & rPassword,const rtl::OUString & rAccount,sal_Bool bAllowPersistentStoring,sal_Bool bAllowUseSystemCredentials)70cdf0e10cSrcweir SimpleAuthenticationRequest::SimpleAuthenticationRequest(
71cdf0e10cSrcweir                                       const rtl::OUString & rURL,
72cdf0e10cSrcweir                                       const rtl::OUString & rServerName,
73cdf0e10cSrcweir                                       const rtl::OUString & rRealm,
74cdf0e10cSrcweir                                       const rtl::OUString & rUserName,
75cdf0e10cSrcweir                                       const rtl::OUString & rPassword,
76cdf0e10cSrcweir                                       const rtl::OUString & rAccount,
77cdf0e10cSrcweir                                       sal_Bool bAllowPersistentStoring,
78cdf0e10cSrcweir                                       sal_Bool bAllowUseSystemCredentials )
79cdf0e10cSrcweir {
80cdf0e10cSrcweir 
81cdf0e10cSrcweir     // Fill request...
82cdf0e10cSrcweir     ucb::URLAuthenticationRequest aRequest;
83cdf0e10cSrcweir //    aRequest.Message        = // OUString
84cdf0e10cSrcweir //    aRequest.Context        = // XInterface
85cdf0e10cSrcweir     aRequest.Classification = task::InteractionClassification_ERROR;
86cdf0e10cSrcweir     aRequest.ServerName     = rServerName;
87cdf0e10cSrcweir //    aRequest.Diagnostic     = // OUString
88cdf0e10cSrcweir     aRequest.HasRealm       = ( rRealm.getLength() > 0 );
89cdf0e10cSrcweir     if ( aRequest.HasRealm )
90cdf0e10cSrcweir         aRequest.Realm = rRealm;
91cdf0e10cSrcweir     aRequest.HasUserName    = sal_True;
92cdf0e10cSrcweir     aRequest.UserName       = rUserName;
93cdf0e10cSrcweir     aRequest.HasPassword    = sal_True;
94cdf0e10cSrcweir     aRequest.Password       = rPassword;
95cdf0e10cSrcweir     aRequest.HasAccount     = ( rAccount.getLength() > 0 );
96cdf0e10cSrcweir     if ( aRequest.HasAccount )
97cdf0e10cSrcweir         aRequest.Account = rAccount;
98cdf0e10cSrcweir     aRequest.URL = rURL;
99cdf0e10cSrcweir 
100cdf0e10cSrcweir     initialize(aRequest,
101cdf0e10cSrcweir        sal_False,
102cdf0e10cSrcweir        sal_True,
103cdf0e10cSrcweir        sal_True,
104cdf0e10cSrcweir        aRequest.HasAccount,
105cdf0e10cSrcweir        bAllowPersistentStoring,
106cdf0e10cSrcweir        bAllowUseSystemCredentials );
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir //=========================================================================
SimpleAuthenticationRequest(const rtl::OUString & rURL,const rtl::OUString & rServerName,EntityType eRealmType,const rtl::OUString & rRealm,EntityType eUserNameType,const rtl::OUString & rUserName,EntityType ePasswordType,const rtl::OUString & rPassword,EntityType eAccountType,const rtl::OUString & rAccount)110cdf0e10cSrcweir SimpleAuthenticationRequest::SimpleAuthenticationRequest(
111cdf0e10cSrcweir                                       const rtl::OUString & rURL,
112cdf0e10cSrcweir                                       const rtl::OUString & rServerName,
113cdf0e10cSrcweir                                       EntityType eRealmType,
114cdf0e10cSrcweir                                       const rtl::OUString & rRealm,
115cdf0e10cSrcweir                                       EntityType eUserNameType,
116cdf0e10cSrcweir                                       const rtl::OUString & rUserName,
117cdf0e10cSrcweir                                       EntityType ePasswordType,
118cdf0e10cSrcweir                                       const rtl::OUString & rPassword,
119cdf0e10cSrcweir                                       EntityType eAccountType,
120cdf0e10cSrcweir                                       const rtl::OUString & rAccount )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     // Fill request...
123cdf0e10cSrcweir     ucb::URLAuthenticationRequest aRequest;
124cdf0e10cSrcweir //    aRequest.Message        = // OUString
125cdf0e10cSrcweir //    aRequest.Context        = // XInterface
126cdf0e10cSrcweir     aRequest.Classification = task::InteractionClassification_ERROR;
127cdf0e10cSrcweir     aRequest.ServerName     = rServerName;
128cdf0e10cSrcweir //    aRequest.Diagnostic     = // OUString
129cdf0e10cSrcweir     aRequest.HasRealm       = eRealmType != ENTITY_NA;
130cdf0e10cSrcweir     if ( aRequest.HasRealm )
131cdf0e10cSrcweir         aRequest.Realm = rRealm;
132cdf0e10cSrcweir     aRequest.HasUserName    = eUserNameType != ENTITY_NA;
133cdf0e10cSrcweir     if ( aRequest.HasUserName )
134cdf0e10cSrcweir         aRequest.UserName = rUserName;
135cdf0e10cSrcweir     aRequest.HasPassword    = ePasswordType != ENTITY_NA;
136cdf0e10cSrcweir     if ( aRequest.HasPassword )
137cdf0e10cSrcweir         aRequest.Password = rPassword;
138cdf0e10cSrcweir     aRequest.HasAccount     = eAccountType != ENTITY_NA;
139cdf0e10cSrcweir     if ( aRequest.HasAccount )
140cdf0e10cSrcweir         aRequest.Account = rAccount;
141cdf0e10cSrcweir     aRequest.URL = rURL;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     initialize(aRequest,
144cdf0e10cSrcweir        eRealmType == ENTITY_MODIFY,
145cdf0e10cSrcweir        eUserNameType == ENTITY_MODIFY,
146cdf0e10cSrcweir        ePasswordType == ENTITY_MODIFY,
147cdf0e10cSrcweir        eAccountType == ENTITY_MODIFY,
148cdf0e10cSrcweir        sal_True,
149cdf0e10cSrcweir        sal_False );
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir //=========================================================================
SimpleAuthenticationRequest(const rtl::OUString & rURL,const rtl::OUString & rServerName,EntityType eRealmType,const rtl::OUString & rRealm,EntityType eUserNameType,const rtl::OUString & rUserName,EntityType ePasswordType,const rtl::OUString & rPassword,EntityType eAccountType,const rtl::OUString & rAccount,sal_Bool bAllowPersistentStoring,sal_Bool bAllowUseSystemCredentials)153cdf0e10cSrcweir SimpleAuthenticationRequest::SimpleAuthenticationRequest(
154cdf0e10cSrcweir                                       const rtl::OUString & rURL,
155cdf0e10cSrcweir                                       const rtl::OUString & rServerName,
156cdf0e10cSrcweir                                       EntityType eRealmType,
157cdf0e10cSrcweir                                       const rtl::OUString & rRealm,
158cdf0e10cSrcweir                                       EntityType eUserNameType,
159cdf0e10cSrcweir                                       const rtl::OUString & rUserName,
160cdf0e10cSrcweir                                       EntityType ePasswordType,
161cdf0e10cSrcweir                                       const rtl::OUString & rPassword,
162cdf0e10cSrcweir                                       EntityType eAccountType,
163cdf0e10cSrcweir                                       const rtl::OUString & rAccount,
164cdf0e10cSrcweir                                       sal_Bool bAllowPersistentStoring,
165cdf0e10cSrcweir                                       sal_Bool bAllowUseSystemCredentials )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir     // Fill request...
168cdf0e10cSrcweir     ucb::URLAuthenticationRequest aRequest;
169cdf0e10cSrcweir //    aRequest.Message        = // OUString
170cdf0e10cSrcweir //    aRequest.Context        = // XInterface
171cdf0e10cSrcweir     aRequest.Classification = task::InteractionClassification_ERROR;
172cdf0e10cSrcweir     aRequest.ServerName     = rServerName;
173cdf0e10cSrcweir //    aRequest.Diagnostic     = // OUString
174cdf0e10cSrcweir     aRequest.HasRealm       = eRealmType != ENTITY_NA;
175cdf0e10cSrcweir     if ( aRequest.HasRealm )
176cdf0e10cSrcweir         aRequest.Realm = rRealm;
177cdf0e10cSrcweir     aRequest.HasUserName    = eUserNameType != ENTITY_NA;
178cdf0e10cSrcweir     if ( aRequest.HasUserName )
179cdf0e10cSrcweir         aRequest.UserName = rUserName;
180cdf0e10cSrcweir     aRequest.HasPassword    = ePasswordType != ENTITY_NA;
181cdf0e10cSrcweir     if ( aRequest.HasPassword )
182cdf0e10cSrcweir         aRequest.Password = rPassword;
183cdf0e10cSrcweir     aRequest.HasAccount     = eAccountType != ENTITY_NA;
184cdf0e10cSrcweir     if ( aRequest.HasAccount )
185cdf0e10cSrcweir         aRequest.Account = rAccount;
186cdf0e10cSrcweir     aRequest.URL = rURL;
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     initialize(aRequest,
189cdf0e10cSrcweir        eRealmType == ENTITY_MODIFY,
190cdf0e10cSrcweir        eUserNameType == ENTITY_MODIFY,
191cdf0e10cSrcweir        ePasswordType == ENTITY_MODIFY,
192cdf0e10cSrcweir        eAccountType == ENTITY_MODIFY,
193cdf0e10cSrcweir        bAllowPersistentStoring,
194cdf0e10cSrcweir        bAllowUseSystemCredentials );
195cdf0e10cSrcweir }
196cdf0e10cSrcweir 
197cdf0e10cSrcweir //=========================================================================
initialize(const ucb::URLAuthenticationRequest & rRequest,sal_Bool bCanSetRealm,sal_Bool bCanSetUserName,sal_Bool bCanSetPassword,sal_Bool bCanSetAccount,sal_Bool bAllowPersistentStoring,sal_Bool bAllowUseSystemCredentials)198cdf0e10cSrcweir void SimpleAuthenticationRequest::initialize(
199cdf0e10cSrcweir       const ucb::URLAuthenticationRequest & rRequest,
200cdf0e10cSrcweir       sal_Bool bCanSetRealm,
201cdf0e10cSrcweir       sal_Bool bCanSetUserName,
202cdf0e10cSrcweir       sal_Bool bCanSetPassword,
203cdf0e10cSrcweir       sal_Bool bCanSetAccount,
204cdf0e10cSrcweir       sal_Bool bAllowPersistentStoring,
205cdf0e10cSrcweir       sal_Bool bAllowUseSystemCredentials )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir     setRequest( uno::makeAny( rRequest ) );
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     // Fill continuations...
210cdf0e10cSrcweir     uno::Sequence< ucb::RememberAuthentication > aRememberModes(
211cdf0e10cSrcweir         bAllowPersistentStoring ? 3 : 2 );
212cdf0e10cSrcweir     aRememberModes[ 0 ] = ucb::RememberAuthentication_NO;
213cdf0e10cSrcweir     aRememberModes[ 1 ] = ucb::RememberAuthentication_SESSION;
214cdf0e10cSrcweir     if (bAllowPersistentStoring)
215cdf0e10cSrcweir         aRememberModes[ 2 ] = ucb::RememberAuthentication_PERSISTENT;
216cdf0e10cSrcweir 
217cdf0e10cSrcweir     m_xAuthSupplier
218cdf0e10cSrcweir         = new InteractionSupplyAuthentication(
219cdf0e10cSrcweir                 this,
220cdf0e10cSrcweir                 bCanSetRealm,
221cdf0e10cSrcweir                 bCanSetUserName,
222cdf0e10cSrcweir                 bCanSetPassword,
223cdf0e10cSrcweir                 bCanSetAccount,
224cdf0e10cSrcweir                 aRememberModes, // rRememberPasswordModes
225cdf0e10cSrcweir                 ucb::RememberAuthentication_SESSION, // eDefaultRememberPasswordMode
226cdf0e10cSrcweir                 aRememberModes, // rRememberAccountModes
227cdf0e10cSrcweir                 ucb::RememberAuthentication_SESSION, // eDefaultRememberAccountMode
228cdf0e10cSrcweir                 bAllowUseSystemCredentials, // bCanUseSystemCredentials,
229cdf0e10cSrcweir                 false // bDefaultUseSystemCredentials
230cdf0e10cSrcweir             );
231cdf0e10cSrcweir 
232cdf0e10cSrcweir     uno::Sequence<
233cdf0e10cSrcweir         uno::Reference< task::XInteractionContinuation > > aContinuations( 3 );
234cdf0e10cSrcweir     aContinuations[ 0 ] = new InteractionAbort( this );
235cdf0e10cSrcweir     aContinuations[ 1 ] = new InteractionRetry( this );
236cdf0e10cSrcweir     aContinuations[ 2 ] = m_xAuthSupplier.get();
237cdf0e10cSrcweir 
238cdf0e10cSrcweir     setContinuations( aContinuations );
239cdf0e10cSrcweir }
240