LibreOffice Module ucbhelper (master)  1
simpleauthenticationrequest.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <com/sun/star/ucb/URLAuthenticationRequest.hpp>
22 
23 using namespace com::sun::star;
24 using namespace ucbhelper;
25 
26 
27 SimpleAuthenticationRequest::SimpleAuthenticationRequest(
28  const OUString & rURL,
29  const OUString & rServerName,
30  const OUString & rRealm,
31  const OUString & rUserName,
32  const OUString & rPassword,
33  bool bAllowUseSystemCredentials,
34  bool bAllowSessionStoring )
35 {
36 
37  // Fill request...
38  ucb::URLAuthenticationRequest aRequest;
39 // aRequest.Message = // OUString
40 // aRequest.Context = // XInterface
41  aRequest.Classification = task::InteractionClassification_ERROR;
42  aRequest.ServerName = rServerName;
43 // aRequest.Diagnostic = // OUString
44  aRequest.HasRealm = !rRealm.isEmpty();
45  if ( aRequest.HasRealm )
46  aRequest.Realm = rRealm;
47  aRequest.HasUserName = true;
48  aRequest.UserName = rUserName;
49  aRequest.HasPassword = true;
50  aRequest.Password = rPassword;
51  aRequest.HasAccount = false;
52  aRequest.URL = rURL;
53 
54  initialize(aRequest,
55  false,
56  true,
57  true,
58  aRequest.HasAccount,
59  bAllowUseSystemCredentials,
60  bAllowSessionStoring );
61 }
62 
63 
64 SimpleAuthenticationRequest::SimpleAuthenticationRequest(
65  const OUString & rURL,
66  const OUString & rServerName,
67  EntityType eRealmType,
68  const OUString & rRealm,
69  EntityType eUserNameType,
70  const OUString & rUserName,
71  EntityType ePasswordType,
72  const OUString & rPassword)
73 {
74  // Fill request...
75  ucb::URLAuthenticationRequest aRequest;
76 // aRequest.Message = // OUString
77 // aRequest.Context = // XInterface
78  aRequest.Classification = task::InteractionClassification_ERROR;
79  aRequest.ServerName = rServerName;
80 // aRequest.Diagnostic = // OUString
81  aRequest.HasRealm = eRealmType != ENTITY_NA;
82  if ( aRequest.HasRealm )
83  aRequest.Realm = rRealm;
84  aRequest.HasUserName = eUserNameType != ENTITY_NA;
85  if ( aRequest.HasUserName )
86  aRequest.UserName = rUserName;
87  aRequest.HasPassword = ePasswordType != ENTITY_NA;
88  if ( aRequest.HasPassword )
89  aRequest.Password = rPassword;
90  aRequest.HasAccount = false;
91  aRequest.URL = rURL;
92 
93  initialize(aRequest,
94  eRealmType == ENTITY_MODIFY,
95  eUserNameType == ENTITY_MODIFY,
96  ePasswordType == ENTITY_MODIFY,
97  false,
98  false,
99  true );
100 }
101 
102 
103 void SimpleAuthenticationRequest::initialize(
104  const ucb::URLAuthenticationRequest & rRequest,
105  bool bCanSetRealm,
106  bool bCanSetUserName,
107  bool bCanSetPassword,
108  bool bCanSetAccount,
109  bool bAllowUseSystemCredentials,
110  bool bAllowSessionStoring )
111 {
112  setRequest( uno::makeAny( rRequest ) );
113 
114  // Fill continuations...
115  unsigned int nSize = 1;
116  unsigned int nPos = 0;
117 
118  if( bAllowSessionStoring )
119  nSize++;
120 
121  nSize++;
122 
123  uno::Sequence< ucb::RememberAuthentication > aRememberModes( nSize );
124  aRememberModes[ nPos++ ] = ucb::RememberAuthentication_NO;
125 
126  if( bAllowSessionStoring )
127  aRememberModes[ nPos++ ] = ucb::RememberAuthentication_SESSION;
128 
129  aRememberModes[ nPos++ ] = ucb::RememberAuthentication_PERSISTENT;
130 
131  m_xAuthSupplier
132  = new InteractionSupplyAuthentication(
133  this,
134  bCanSetRealm,
135  bCanSetUserName,
136  bCanSetPassword,
137  bCanSetAccount,
138  aRememberModes, // rRememberPasswordModes
139  ucb::RememberAuthentication_SESSION, // eDefaultRememberPasswordMode
140  aRememberModes, // rRememberAccountModes
141  ucb::RememberAuthentication_SESSION, // eDefaultRememberAccountMode
142  bAllowUseSystemCredentials // bCanUseSystemCredentials,
143  );
144 
145  uno::Sequence<
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();
150 
151  setContinuations( aContinuations );
152 }
153 
154 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
EntityType
Specification whether some entity (realm, username, password, account) is either not applicable at al...
This class implements a standard interaction continuation, namely the interface XInteractionRetry.
Any makeAny(Color const &value)
This class implements a standard interaction continuation, namely the interface XInteractionAbort.
sal_uInt16 nPos