os/persistentdata/persistentstorage/dbms/security/SC_Policy.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// CPolicyBase, CDbPolicy, CTblPolicy, CPolicyDomain, 
sl@0
    15
// TPolicyDomainBuilder, TPolicyDomainReader classes.
sl@0
    16
// MPolicyDomainPersister, MPolicyDomainLoader interfaces
sl@0
    17
// 
sl@0
    18
//
sl@0
    19
sl@0
    20
#ifndef __SC_POLICY_H__
sl@0
    21
#define __SC_POLICY_H__
sl@0
    22
sl@0
    23
#include <e32base.h>		//CBase
sl@0
    24
#include "D32Security.h"
sl@0
    25
sl@0
    26
namespace DBSC
sl@0
    27
{
sl@0
    28
sl@0
    29
//Forward declarations
sl@0
    30
class CPolicyDomain;
sl@0
    31
sl@0
    32
/**
sl@0
    33
CPolicyBase class implements MPolicy interface.
sl@0
    34
It describes an object that manages a set of TSecurityPolicy objects.
sl@0
    35
CPolicyBase::iPOType data member gives an information access to what kind of 
sl@0
    36
database object (database or table) is controlled by the set of security policies.
sl@0
    37
CPolicyBase::Check() can be used to check caller access rights against specified policy type.
sl@0
    38
@see MPolicy
sl@0
    39
@internalComponent
sl@0
    40
*/
sl@0
    41
NONSHARABLE_CLASS(CPolicyBase) : public CBase, public MPolicy
sl@0
    42
	{
sl@0
    43
public:
sl@0
    44
	struct TPolicy
sl@0
    45
		{
sl@0
    46
		TPolicyType		iType;
sl@0
    47
		TSecurityPolicy	iData;
sl@0
    48
		};
sl@0
    49
	typedef RArray<TPolicy> RPolicyCollection;
sl@0
    50
	typedef enum {EPCNotFound, EPCPassed, EPCNotPassed} TPolicyCheckResult;
sl@0
    51
sl@0
    52
public:
sl@0
    53
	virtual ~CPolicyBase();
sl@0
    54
	virtual TBool Check(const RMessage2& aMessage, TPolicyType aPolicyType) const = 0; 
sl@0
    55
	virtual TInt Get(TPolicyType aPolicyType, TSecurityPolicy& aPolicy) const;
sl@0
    56
	virtual void InvariantL() const;
sl@0
    57
	DECLARE_DB_INVARIANT()
sl@0
    58
	inline const RPolicyCollection& PolicyCollection() const;
sl@0
    59
sl@0
    60
protected:
sl@0
    61
	inline CPolicyBase();
sl@0
    62
	void ConstructL(const RPolicyCollection& aPolicyCollection);
sl@0
    63
	const TSecurityPolicy* Policy(TPolicyType aPolicyType) const;
sl@0
    64
	TPolicyCheckResult DoCheck(const RMessage2& aMessage, TPolicyType aPolicyType) const; 
sl@0
    65
	DECLARE_DB_DUMP2(aFile)
sl@0
    66
sl@0
    67
private:
sl@0
    68
	RPolicyCollection	iPolicyCollection;
sl@0
    69
sl@0
    70
	};
sl@0
    71
sl@0
    72
/**
sl@0
    73
CDbPolicy class describes an object that manages the access to all databases, which
sl@0
    74
have the same format UID.
sl@0
    75
@see CPolicyBase
sl@0
    76
@see MPolicy
sl@0
    77
@internalComponent
sl@0
    78
*/
sl@0
    79
NONSHARABLE_CLASS(CDbPolicy) : public CPolicyBase
sl@0
    80
	{
sl@0
    81
public:
sl@0
    82
	static CDbPolicy* NewLC(const RPolicyCollection& aPolicyCollection);
sl@0
    83
	inline static CDbPolicy* NewL(const RPolicyCollection& aPolicyCollection);
sl@0
    84
	virtual ~CDbPolicy();
sl@0
    85
	virtual TBool Check(const RMessage2& aMessage, TPolicyType aPolicyType) const; 
sl@0
    86
	virtual void InvariantL() const;
sl@0
    87
	DECLARE_DB_DUMP2(aFile)
sl@0
    88
sl@0
    89
private:
sl@0
    90
	inline CDbPolicy();
sl@0
    91
sl@0
    92
	};
sl@0
    93
sl@0
    94
/**
sl@0
    95
CTblPolicy class describes an object that manages the access to all tables, which
sl@0
    96
have particular format UID and particular name.
sl@0
    97
@see CPolicyBase
sl@0
    98
@see MPolicy
sl@0
    99
@internalComponent
sl@0
   100
*/
sl@0
   101
NONSHARABLE_CLASS(CTblPolicy) : public CPolicyBase
sl@0
   102
	{
sl@0
   103
public:
sl@0
   104
	static CTblPolicy* NewLC(const TDesC& aTblName, 
sl@0
   105
							 const RPolicyCollection& aPolicyCollection,
sl@0
   106
							 const CDbPolicy* aDbPolicy);
sl@0
   107
	inline static CTblPolicy* NewL(const TDesC& aTblName, 
sl@0
   108
								   const RPolicyCollection& aPolicyCollection,
sl@0
   109
								   const CDbPolicy* aDbPolicy);
sl@0
   110
	virtual ~CTblPolicy();
sl@0
   111
	virtual TBool Check(const RMessage2& aMessage, TPolicyType aPolicyType) const; 
sl@0
   112
	virtual TInt Get(TPolicyType aPolicyType, TSecurityPolicy& aPolicy) const;
sl@0
   113
	virtual void InvariantL() const;
sl@0
   114
	inline const TDesC& TableName() const;
sl@0
   115
	DECLARE_DB_DUMP2(aFile)
sl@0
   116
sl@0
   117
private:
sl@0
   118
	inline CTblPolicy(const CDbPolicy* aDbPolicy);
sl@0
   119
	void ConstructL(const TDesC& aTblName, const RPolicyCollection& aPolicyCollection);
sl@0
   120
sl@0
   121
private:
sl@0
   122
	HBufC*	iTblName;
sl@0
   123
	const CDbPolicy* iDbPolicy;
sl@0
   124
sl@0
   125
	};
sl@0
   126
sl@0
   127
/**
sl@0
   128
TPolicyDomainBuilder class describes an object that can be used during the initialization
sl@0
   129
to initialize CPolicyDomain objects. It is used by MPolicyDomainLoader interface.
sl@0
   130
@internalComponent
sl@0
   131
*/
sl@0
   132
class TPolicyDomainBuilder
sl@0
   133
	{
sl@0
   134
public:
sl@0
   135
	inline TPolicyDomainBuilder(CPolicyDomain& aPolicyDomain);
sl@0
   136
	void SetDbPolicyL(CDbPolicy* aDbPolicy);
sl@0
   137
	inline void AddTblPolicyL(CTblPolicy* aTblPolicy);
sl@0
   138
	inline void SetBackupSID(TSecureId& aSecureId);
sl@0
   139
private:
sl@0
   140
	CPolicyDomain&	iPolicyDomain;
sl@0
   141
	};
sl@0
   142
sl@0
   143
/**
sl@0
   144
TPolicyDomainBuilder class describes an object that can be used to explore the content of
sl@0
   145
CPolicyDomain objects. It is used by MPolicyDomainPersister interface.
sl@0
   146
@internalComponent
sl@0
   147
*/
sl@0
   148
class TPolicyDomainReader
sl@0
   149
	{
sl@0
   150
public:
sl@0
   151
	inline TPolicyDomainReader(const CPolicyDomain& aPolicyDomain);
sl@0
   152
	inline TUid Uid() const;
sl@0
   153
	inline const CDbPolicy& DbPolicy() const;
sl@0
   154
	inline void ResetTblPos() const;
sl@0
   155
	inline TInt TblPolicyCount() const;
sl@0
   156
	inline const CTblPolicy* NextTblPolicy() const;
sl@0
   157
	inline TSecureId BackupSID() const;
sl@0
   158
private:
sl@0
   159
	const CPolicyDomain&	iPolicyDomain;
sl@0
   160
	mutable TInt			iIndex;
sl@0
   161
	};
sl@0
   162
sl@0
   163
/**
sl@0
   164
MPolicyDomainPersister interface has to be implemented by DBSC clients, who want to store
sl@0
   165
the information from CPolicyDomain objects (set of security policies) somewhere - text files,
sl@0
   166
streams, ... It uses TPolicyDomainReader class to traverse CPolicyDomain collection of
sl@0
   167
security policies.
sl@0
   168
@see TPolicyDomainReader
sl@0
   169
@internalComponent
sl@0
   170
*/
sl@0
   171
class MPolicyDomainPersister
sl@0
   172
	{
sl@0
   173
public:
sl@0
   174
	virtual void RunL(const TPolicyDomainReader& aPolicyDomainReader) = 0;
sl@0
   175
	};
sl@0
   176
sl@0
   177
/**
sl@0
   178
MPolicyDomainPersister interface has to be implemented by DBSC clients, who want to load
sl@0
   179
set of security policies to CPolicyDomain objects from somewhere - text files,
sl@0
   180
streams, ... It uses TPolicyDomainBuilder class to add to CPolicyDomain collection new
sl@0
   181
security policies.
sl@0
   182
@see TPolicyDomainBuilder
sl@0
   183
@internalComponent
sl@0
   184
*/
sl@0
   185
class MPolicyDomainLoader
sl@0
   186
	{
sl@0
   187
public:
sl@0
   188
	virtual void RunL(TPolicyDomainBuilder& aPolicyDomainBuilder) = 0;
sl@0
   189
	};
sl@0
   190
sl@0
   191
/**
sl@0
   192
CPolicyDomain object describes a set of all security policies related to particular format UID.
sl@0
   193
It describes only a collection of security policies and offers some functionality for
sl@0
   194
retrieving particular database/table MPolicy interfaces.
sl@0
   195
The responsibility for adding new items to secirity policy collection is delegated to 
sl@0
   196
TPolicyDomainBuilder class.
sl@0
   197
The responsibility for traversing secirity policy collection is delegated to 
sl@0
   198
TPolicyDomainReader class.
sl@0
   199
Both, TPolicyDomainBuilder and TPolicyDomainReader classes are not used directly by 
sl@0
   200
the CPolicyDomain class implementation. CPolicyDomain instances are created using 
sl@0
   201
MPolicyDomainLoader interface and externalized using MPolicyDomainPersister interface and
sl@0
   202
they (the interfaces) use TPolicyDomainBuilder and TPolicyDomainReader respectively.
sl@0
   203
The delegation of responsibilities for creation/traversing of CPolicyDomain security policy collection
sl@0
   204
was done because CPolicyDomain class is a part of shared sources used in DBMS server implementation
sl@0
   205
and DbSpConv tool implementation.
sl@0
   206
DBMS server creates CPolicyDomain security policy collection from a binary policy files using
sl@0
   207
TPDStreamLoader class (which implements MPolicyDomainLoader) and TPolicyDomainBuilder class
sl@0
   208
to insert created CDbPolicy and CTblPolicy instances into CPolicyDomain collection.
sl@0
   209
The rest of the possibilities: creating CPolicyDomain collection from a text policy file,
sl@0
   210
exporting CPolicyDomain collection to a binary policy file, 
sl@0
   211
exporting CPolicyDomain collection to a text policy file, are used by the DbSpConv tool.
sl@0
   212
So, CPolicyDomain class uses interfaces for its loading/storing, but their 
sl@0
   213
implementations are part of separate exe-s - no waste of production code.
sl@0
   214
@see MPolicy
sl@0
   215
@see CDbPolicy
sl@0
   216
@see CTblPolicy
sl@0
   217
@see TPolicyDomainBuilder
sl@0
   218
@see TPolicyDomainReader
sl@0
   219
@see MPolicyDomainLoader
sl@0
   220
@see MPolicyDomainPersister
sl@0
   221
@internalComponent
sl@0
   222
*/
sl@0
   223
NONSHARABLE_CLASS(CPolicyDomain) : public CBase
sl@0
   224
	{
sl@0
   225
	friend class TPolicyDomainBuilder;
sl@0
   226
	friend class TPolicyDomainReader;
sl@0
   227
public:
sl@0
   228
	static CPolicyDomain* NewLC(TUid aUid, MPolicyDomainLoader& aPDLoader);
sl@0
   229
	inline static CPolicyDomain* NewL(TUid aUid, MPolicyDomainLoader& aPDLoader);
sl@0
   230
	virtual ~CPolicyDomain();
sl@0
   231
	void ExternalizeL(MPolicyDomainPersister& aPDPersister) const;
sl@0
   232
sl@0
   233
	inline TUid Uid() const;
sl@0
   234
	const MPolicy* DbPolicy() const;
sl@0
   235
	const MPolicy* TblPolicy(const TDesC& aTblName) const;
sl@0
   236
	inline TSecureId BackupSID() const;
sl@0
   237
sl@0
   238
	virtual void InvariantL() const;
sl@0
   239
	DECLARE_DB_DUMP3(aFile)
sl@0
   240
sl@0
   241
private:
sl@0
   242
	inline CPolicyDomain(TUid aUid);
sl@0
   243
	void InternalizeL(MPolicyDomainLoader& aPDLoader);
sl@0
   244
	void Destroy();
sl@0
   245
	DECLARE_DB_INVARIANT2()
sl@0
   246
sl@0
   247
private:
sl@0
   248
	TUid						iUid;
sl@0
   249
	CDbPolicy*					iDbPolicy;
sl@0
   250
	RPointerArray<CTblPolicy>	iTPCollection;
sl@0
   251
	TSecureId 					iBackupSID;
sl@0
   252
sl@0
   253
	};
sl@0
   254
sl@0
   255
} //end of - namespace DBSC
sl@0
   256
sl@0
   257
#include "SC_Policy.inl"
sl@0
   258
sl@0
   259
#endif//__SC_POLICY_H__