1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/task/XMasterPasswordHandling.hpp>
21 #include <com/sun/star/ucb/URLAuthenticationRequest.hpp>
22 #include <ucbhelper/simpleauthenticationrequest.hxx>
24 using namespace com::sun::star
;
25 using namespace ucbhelper
;
27 //=========================================================================
28 SimpleAuthenticationRequest::SimpleAuthenticationRequest(
29 const rtl::OUString
& rURL
,
30 const rtl::OUString
& rServerName
,
31 const rtl::OUString
& rRealm
,
32 const rtl::OUString
& rUserName
,
33 const rtl::OUString
& rPassword
,
34 const rtl::OUString
& rAccount
,
35 sal_Bool bAllowPersistentStoring
,
36 sal_Bool bAllowUseSystemCredentials
)
40 ucb::URLAuthenticationRequest aRequest
;
41 // aRequest.Message = // OUString
42 // aRequest.Context = // XInterface
43 aRequest
.Classification
= task::InteractionClassification_ERROR
;
44 aRequest
.ServerName
= rServerName
;
45 // aRequest.Diagnostic = // OUString
46 aRequest
.HasRealm
= !rRealm
.isEmpty();
47 if ( aRequest
.HasRealm
)
48 aRequest
.Realm
= rRealm
;
49 aRequest
.HasUserName
= sal_True
;
50 aRequest
.UserName
= rUserName
;
51 aRequest
.HasPassword
= sal_True
;
52 aRequest
.Password
= rPassword
;
53 aRequest
.HasAccount
= !rAccount
.isEmpty();
54 if ( aRequest
.HasAccount
)
55 aRequest
.Account
= rAccount
;
63 bAllowPersistentStoring
,
64 bAllowUseSystemCredentials
);
67 //=========================================================================
68 SimpleAuthenticationRequest::SimpleAuthenticationRequest(
69 const rtl::OUString
& rURL
,
70 const rtl::OUString
& rServerName
,
71 EntityType eRealmType
,
72 const rtl::OUString
& rRealm
,
73 EntityType eUserNameType
,
74 const rtl::OUString
& rUserName
,
75 EntityType ePasswordType
,
76 const rtl::OUString
& rPassword
,
77 EntityType eAccountType
,
78 const rtl::OUString
& rAccount
)
81 ucb::URLAuthenticationRequest aRequest
;
82 // aRequest.Message = // OUString
83 // aRequest.Context = // XInterface
84 aRequest
.Classification
= task::InteractionClassification_ERROR
;
85 aRequest
.ServerName
= rServerName
;
86 // aRequest.Diagnostic = // OUString
87 aRequest
.HasRealm
= eRealmType
!= ENTITY_NA
;
88 if ( aRequest
.HasRealm
)
89 aRequest
.Realm
= rRealm
;
90 aRequest
.HasUserName
= eUserNameType
!= ENTITY_NA
;
91 if ( aRequest
.HasUserName
)
92 aRequest
.UserName
= rUserName
;
93 aRequest
.HasPassword
= ePasswordType
!= ENTITY_NA
;
94 if ( aRequest
.HasPassword
)
95 aRequest
.Password
= rPassword
;
96 aRequest
.HasAccount
= eAccountType
!= ENTITY_NA
;
97 if ( aRequest
.HasAccount
)
98 aRequest
.Account
= rAccount
;
102 eRealmType
== ENTITY_MODIFY
,
103 eUserNameType
== ENTITY_MODIFY
,
104 ePasswordType
== ENTITY_MODIFY
,
105 eAccountType
== ENTITY_MODIFY
,
110 //=========================================================================
111 void SimpleAuthenticationRequest::initialize(
112 const ucb::URLAuthenticationRequest
& rRequest
,
113 sal_Bool bCanSetRealm
,
114 sal_Bool bCanSetUserName
,
115 sal_Bool bCanSetPassword
,
116 sal_Bool bCanSetAccount
,
117 sal_Bool bAllowPersistentStoring
,
118 sal_Bool bAllowUseSystemCredentials
)
120 setRequest( uno::makeAny( rRequest
) );
122 // Fill continuations...
123 uno::Sequence
< ucb::RememberAuthentication
> aRememberModes(
124 bAllowPersistentStoring
? 3 : 2 );
125 aRememberModes
[ 0 ] = ucb::RememberAuthentication_NO
;
126 aRememberModes
[ 1 ] = ucb::RememberAuthentication_SESSION
;
127 if (bAllowPersistentStoring
)
128 aRememberModes
[ 2 ] = ucb::RememberAuthentication_PERSISTENT
;
131 = new InteractionSupplyAuthentication(
137 aRememberModes
, // rRememberPasswordModes
138 ucb::RememberAuthentication_SESSION
, // eDefaultRememberPasswordMode
139 aRememberModes
, // rRememberAccountModes
140 ucb::RememberAuthentication_SESSION
, // eDefaultRememberAccountMode
141 bAllowUseSystemCredentials
, // bCanUseSystemCredentials,
142 false // bDefaultUseSystemCredentials
146 uno::Reference
< task::XInteractionContinuation
> > aContinuations( 3 );
147 aContinuations
[ 0 ] = new InteractionAbort( this );
148 aContinuations
[ 1 ] = new InteractionRetry( this );
149 aContinuations
[ 2 ] = m_xAuthSupplier
.get();
151 setContinuations( aContinuations
);
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */