os/security/authorisation/userpromptservice/policies/test/testpolicyevaluator/source/testpolicyevaluator.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
* refpolicyevaluator.cpp
sl@0
    16
*
sl@0
    17
*/
sl@0
    18
sl@0
    19
sl@0
    20
#include "testpolicyevaluator.h"
sl@0
    21
#include <ecom/implementationproxy.h>
sl@0
    22
#include <ups/cliententity.h>
sl@0
    23
#include <ups/fingerprint.h>
sl@0
    24
#include <ups/upsdb.h>
sl@0
    25
sl@0
    26
using namespace UserPromptService;
sl@0
    27
sl@0
    28
static const TUint KTestPolicyEvaluatorImplementationId = 0x10283698;
sl@0
    29
sl@0
    30
CPolicyEvaluator* CTestPolicyEvaluator::CreatePolicyEvaluatorL()
sl@0
    31
/**
sl@0
    32
Factory method that instantiates a new policy evaluator ECOM plug-in.
sl@0
    33
sl@0
    34
@return A pointer to the new reference policy evaluator object.
sl@0
    35
*/
sl@0
    36
	{
sl@0
    37
	CTestPolicyEvaluator* self = new (ELeave)CTestPolicyEvaluator();
sl@0
    38
	CleanupStack::PushL(self);
sl@0
    39
	self->ConstructL();
sl@0
    40
	CleanupStack::Pop(self);
sl@0
    41
	return self;
sl@0
    42
	}
sl@0
    43
sl@0
    44
static const TImplementationProxy ImplementationTable[] = 
sl@0
    45
	{
sl@0
    46
	IMPLEMENTATION_PROXY_ENTRY(KTestPolicyEvaluatorImplementationId, CTestPolicyEvaluator::CreatePolicyEvaluatorL)
sl@0
    47
	};
sl@0
    48
sl@0
    49
EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount)
sl@0
    50
/**
sl@0
    51
Standard ECOM factory
sl@0
    52
*/
sl@0
    53
	{
sl@0
    54
	aTableCount = sizeof(ImplementationTable) / sizeof(TImplementationProxy);
sl@0
    55
	return ImplementationTable;
sl@0
    56
	}	
sl@0
    57
	
sl@0
    58
sl@0
    59
CTestPolicyEvaluator::CTestPolicyEvaluator()
sl@0
    60
/**
sl@0
    61
Constructor
sl@0
    62
*/
sl@0
    63
	: CPolicyEvaluator()
sl@0
    64
	{
sl@0
    65
	CActiveScheduler::Add(this);
sl@0
    66
	}
sl@0
    67
	
sl@0
    68
CTestPolicyEvaluator::~CTestPolicyEvaluator()
sl@0
    69
/**
sl@0
    70
Destructor
sl@0
    71
*/
sl@0
    72
	{
sl@0
    73
	Deque();
sl@0
    74
	delete iDigest;
sl@0
    75
	delete iClientEntity;
sl@0
    76
	}
sl@0
    77
sl@0
    78
void CTestPolicyEvaluator::ConstructL()
sl@0
    79
/**
sl@0
    80
Second phase constructor, creates the message digest
sl@0
    81
*/
sl@0
    82
	{	
sl@0
    83
	iDigest = CMessageDigestFactory::NewDigestL(CMessageDigest::EMD5);
sl@0
    84
	}
sl@0
    85
sl@0
    86
sl@0
    87
// From CActive
sl@0
    88
void CTestPolicyEvaluator::DoCancel()
sl@0
    89
	{	
sl@0
    90
	// Logically should Cancel the internal outstanding requst, but
sl@0
    91
	// currently GenerateFingerprints has already completed it.
sl@0
    92
sl@0
    93
	// And need to complete the clients request
sl@0
    94
	if (iClientStatus)
sl@0
    95
		{
sl@0
    96
		User::RequestComplete(iClientStatus, KErrCancel);
sl@0
    97
		}
sl@0
    98
	}
sl@0
    99
	
sl@0
   100
TInt CTestPolicyEvaluator::RunError(TInt aError)
sl@0
   101
	{
sl@0
   102
	if (iClientStatus)
sl@0
   103
		{
sl@0
   104
		User::RequestComplete(iClientStatus, aError);
sl@0
   105
		}
sl@0
   106
	return KErrNone;
sl@0
   107
	}
sl@0
   108
	
sl@0
   109
void CTestPolicyEvaluator::RunL()
sl@0
   110
	{
sl@0
   111
	// This plug-in doesn't use the opaque data	
sl@0
   112
	TInt opaqueDataLen = iRequest->OpaqueData().Length();
sl@0
   113
	if (opaqueDataLen > 0)
sl@0
   114
		{
sl@0
   115
		RDebug::Printf("Received %d bytes of opaque data", opaqueDataLen);
sl@0
   116
		}
sl@0
   117
		
sl@0
   118
	SetClientEntityL();
sl@0
   119
	
sl@0
   120
	// Create most specific hash first i.e. HASH(destination)
sl@0
   121
	// N.B. Normally, the destination field should be parsed so that only relevant data is hashed.		
sl@0
   122
	iDigest->Reset();
sl@0
   123
	const TDesC& d = iRequest->Destination();
sl@0
   124
	TPtrC8 p(reinterpret_cast<const TUint8*>(d.Ptr()), d.Length() * 2);
sl@0
   125
	TPtrC8 h(iDigest->Hash(p));
sl@0
   126
	
sl@0
   127
	CFingerprint* f = CFingerprint::NewLC(h, d);
sl@0
   128
	iFingerprints->AppendL(f);
sl@0
   129
	CleanupStack::Pop(f);
sl@0
   130
sl@0
   131
	// An empty fingerprint may be used for decisions that apply to
sl@0
   132
	// all destinations.
sl@0
   133
	f = CFingerprint::NewLC(KNullDesC8, KNullDesC);
sl@0
   134
	iFingerprints->AppendL(f);
sl@0
   135
	CleanupStack::Pop(f);
sl@0
   136
		
sl@0
   137
	User::RequestComplete(iClientStatus, KErrNone);
sl@0
   138
	}
sl@0
   139
sl@0
   140
void CTestPolicyEvaluator::SetClientEntityL()
sl@0
   141
/**
sl@0
   142
Sets the name of the entity within the client process that made the request.
sl@0
   143
This is optional functionality designed to allow permissions to be set for scripts
sl@0
   144
where the scripting host process can execute a number of different scripts.
sl@0
   145
*/
sl@0
   146
	{
sl@0
   147
	// This doesn't really support client entities, so for testing purposes we
sl@0
   148
	// extract the client entity name from the opaque data.
sl@0
   149
	_LIT8(KClientEntityTagStart, "<ce>");
sl@0
   150
	_LIT8(KClientEntityTagEnd, "</ce>");
sl@0
   151
	TInt startPos;
sl@0
   152
	TInt endPos;
sl@0
   153
	if ((startPos = iRequest->OpaqueData().FindF(KClientEntityTagStart)) != KErrNotFound)
sl@0
   154
		{
sl@0
   155
		startPos += KClientEntityTagStart().Length();
sl@0
   156
		if ((endPos = iRequest->OpaqueData().FindF(KClientEntityTagEnd)) != KErrNotFound)	
sl@0
   157
			{
sl@0
   158
			if (endPos > startPos)	
sl@0
   159
				{
sl@0
   160
				TPtrC8 entityName = iRequest->OpaqueData().Mid(startPos, endPos - startPos);
sl@0
   161
				iClientEntity = CClientEntity::NewL(entityName);
sl@0
   162
				*iClientEntityPtr = iClientEntity;			
sl@0
   163
				}	
sl@0
   164
			}
sl@0
   165
		}
sl@0
   166
	}
sl@0
   167
	
sl@0
   168
void CTestPolicyEvaluator::GenerateFingerprints(
sl@0
   169
	const CPromptRequest& aRequest, const CPolicy& aPolicy, 
sl@0
   170
	RPointerArray<CFingerprint>& aFingerprints, const CClientEntity*& aClientEntity, 
sl@0
   171
	const TAny*& aDialogCreatorParams, TRequestStatus& aStatus)
sl@0
   172
	{
sl@0
   173
	iRequest = &aRequest;
sl@0
   174
	iPolicy = &aPolicy;
sl@0
   175
	iFingerprints = &aFingerprints;		
sl@0
   176
	iClientEntityPtr = &aClientEntity;	
sl@0
   177
	aDialogCreatorParams = 0;			
sl@0
   178
	
sl@0
   179
	iClientStatus = &aStatus;
sl@0
   180
	aStatus = KRequestPending;
sl@0
   181
	
sl@0
   182
	// Kick off policy evaluator state machine
sl@0
   183
	iStatus = KRequestPending;
sl@0
   184
	TRequestStatus* status = &iStatus;
sl@0
   185
	SetActive();
sl@0
   186
	User::RequestComplete(status, KErrNone);
sl@0
   187
	}
sl@0
   188
sl@0
   189
TBool CTestPolicyEvaluator::ForcePromptL(const CDecisionRecord& aDecision, TUint& aNewEvaluatorInfo)
sl@0
   190
	{
sl@0
   191
	(void) aDecision;
sl@0
   192
	aNewEvaluatorInfo = aDecision.iEvaluatorInfo + 10;
sl@0
   193
	return EFalse;
sl@0
   194
	}