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