bump product version to 6.3.0.0.beta1
[LibreOffice.git] / connectivity / source / drivers / ado / AUser.cxx
blob4e595de36bac00414fbda058ce280ad1f8f5097c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <ado/AUser.hxx>
21 #include <ado/ACatalog.hxx>
22 #include <ado/AGroups.hxx>
23 #include <cppuhelper/typeprovider.hxx>
24 #include <com/sun/star/sdbc/XRow.hpp>
25 #include <com/sun/star/sdbc/XResultSet.hpp>
26 #include <ado/AConnection.hxx>
27 #include <ado/Awrapado.hxx>
29 using namespace connectivity::ado;
30 using namespace com::sun::star::uno;
31 using namespace com::sun::star::lang;
32 using namespace com::sun::star::beans;
33 using namespace com::sun::star::sdbc;
36 OAdoUser::OAdoUser(OCatalog* _pParent,bool _bCase, ADOUser* _pUser)
37 : OUser_TYPEDEF(_bCase)
38 ,m_pCatalog(_pParent)
40 construct();
42 if(_pUser)
43 m_aUser = WpADOUser(_pUser);
44 else
45 m_aUser.Create();
48 OAdoUser::OAdoUser(OCatalog* _pParent,bool _bCase, const OUString& Name)
49 : OUser_TYPEDEF(Name,_bCase)
50 , m_pCatalog(_pParent)
52 construct();
53 m_aUser.Create();
54 m_aUser.put_Name(Name);
57 void OAdoUser::refreshGroups()
59 ::std::vector< OUString> aVector;
60 WpADOGroups aGroups(m_aUser.get_Groups());
61 aGroups.fillElementNames(aVector);
62 if(m_pGroups)
63 m_pGroups->reFill(aVector);
64 else
65 m_pGroups.reset(new OGroups(m_pCatalog, m_aMutex, aVector, aGroups, isCaseSensitive()));
68 Sequence< sal_Int8 > OAdoUser::getUnoTunnelImplementationId()
70 static ::cppu::OImplementationId implId;
72 return implId.getImplementationId();
75 // css::lang::XUnoTunnel
77 sal_Int64 OAdoUser::getSomething( const Sequence< sal_Int8 > & rId )
79 return (rId.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
80 ? reinterpret_cast< sal_Int64 >( this )
81 : OUser_TYPEDEF::getSomething(rId);
85 void OAdoUser::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)
87 if(m_aUser.IsValid())
90 switch(nHandle)
92 case PROPERTY_ID_NAME:
94 OUString aVal;
95 rValue >>= aVal;
96 m_aUser.put_Name(aVal);
98 break;
103 void OAdoUser::getFastPropertyValue(Any& rValue,sal_Int32 nHandle) const
105 if(m_aUser.IsValid())
107 switch(nHandle)
109 case PROPERTY_ID_NAME:
110 rValue <<= m_aUser.get_Name();
111 break;
116 OUserExtend::OUserExtend(OCatalog* _pParent,bool _bCase, ADOUser* _pUser)
117 : OAdoUser(_pParent,_bCase,_pUser)
121 OUserExtend::OUserExtend(OCatalog* _pParent,bool _bCase, const OUString& Name)
122 : OAdoUser(_pParent,_bCase,Name)
127 void OUserExtend::construct()
129 OUser_TYPEDEF::construct();
130 registerProperty(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_PASSWORD), PROPERTY_ID_PASSWORD,0,&m_Password,::cppu::UnoType<OUString>::get());
133 cppu::IPropertyArrayHelper* OUserExtend::createArrayHelper() const
135 Sequence< css::beans::Property > aProps;
136 describeProperties(aProps);
137 return new cppu::OPropertyArrayHelper(aProps);
140 cppu::IPropertyArrayHelper & OUserExtend::getInfoHelper()
142 return *OUserExtend_PROP::getArrayHelper();
145 sal_Int32 SAL_CALL OAdoUser::getPrivileges( const OUString& objName, sal_Int32 objType )
147 ::osl::MutexGuard aGuard(m_aMutex);
148 checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
150 return ADOS::mapAdoRights2Sdbc(m_aUser.GetPermissions(objName, ADOS::mapObjectType2Ado(objType)));
153 sal_Int32 SAL_CALL OAdoUser::getGrantablePrivileges( const OUString& objName, sal_Int32 objType )
155 ::osl::MutexGuard aGuard(m_aMutex);
156 checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
158 sal_Int32 nRights = 0;
159 RightsEnum eRights = m_aUser.GetPermissions(objName, ADOS::mapObjectType2Ado(objType));
160 if((eRights & adRightWithGrant) == adRightWithGrant)
161 nRights = ADOS::mapAdoRights2Sdbc(eRights);
162 ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
163 return nRights;
166 void SAL_CALL OAdoUser::grantPrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges )
168 ::osl::MutexGuard aGuard(m_aMutex);
169 checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
170 m_aUser.SetPermissions(objName,ADOS::mapObjectType2Ado(objType),adAccessGrant,RightsEnum(ADOS::mapRights2Ado(objPrivileges)));
171 ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
174 void SAL_CALL OAdoUser::revokePrivileges( const OUString& objName, sal_Int32 objType, sal_Int32 objPrivileges )
176 ::osl::MutexGuard aGuard(m_aMutex);
177 checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
178 m_aUser.SetPermissions(objName,ADOS::mapObjectType2Ado(objType),adAccessRevoke,RightsEnum(ADOS::mapRights2Ado(objPrivileges)));
179 ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
182 // XUser
183 void SAL_CALL OAdoUser::changePassword( const OUString& objPassword, const OUString& newPassword )
185 ::osl::MutexGuard aGuard(m_aMutex);
186 checkDisposed(OUser_BASE_TYPEDEF::rBHelper.bDisposed);
187 m_aUser.ChangePassword(objPassword,newPassword);
188 ADOS::ThrowException(*m_pCatalog->getConnection()->getConnection(),*this);
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */