authenticationservices/authenticationserver/source/client/authmgrclient.cpp
changeset 19 ece3df019add
equal deleted inserted replaced
17:cd501b96611d 19:ece3df019add
       
     1 /*
       
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 * authmgrclient - exported authentication client session  implementation
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 /**
       
    21  @file 
       
    22 */
       
    23 
       
    24 #include "authclient_impl.h"
       
    25 #include "authserverutil.h"
       
    26 
       
    27 using namespace AuthServer;
       
    28 
       
    29 /**
       
    30  * Register a new identity. This causes the server to create a new
       
    31  * identity and attempt to train the user with all available active
       
    32  * plugins. At least one plugin must be trained for this to be succesful.
       
    33  *
       
    34  * @param aIdentity The new heap allocated identity details will be
       
    35  * pointed at by this parameter upon successful completion.
       
    36  *
       
    37  * @param aDescription The identity's description text.
       
    38  *
       
    39  * @param aRequest This status object will be completed when this
       
    40  * asynchronous call finishes, the return values are described below. 
       
    41  *
       
    42  * @capability TrustedUI
       
    43  *
       
    44  * @return KErrServerTerminated, if the server no longer present
       
    45  * @return KErrServerBusy, if the request cannot be handled at this time. 
       
    46  * @return KErrNoMemory, if there is insufficient memory available.
       
    47  * @return KErrPermissionDenied, if the caller has insufficient capabilities.
       
    48  * @return KErrAuthServRegistrationFailed, if the all plugins failed to
       
    49  * successfully train for the identity.
       
    50  **/
       
    51 EXPORT_C void RAuthMgrClient::RegisterIdentityL(
       
    52     CIdentity*& aIdentity,
       
    53 	const TDesC& aDescription,  
       
    54     TRequestStatus& aRequest)
       
    55     {
       
    56     CheckAsyncDecoderL();
       
    57 	iAsyncResponseDecoder->RegisterIdentityL(aIdentity, aDescription, aRequest);
       
    58     }
       
    59 
       
    60 /** 
       
    61  * Remove an identity.
       
    62  *
       
    63  * @param aId The identity to remove.
       
    64  *
       
    65  * @capability WriteDeviceData
       
    66  *
       
    67  * @leave KErrServerTerminated, if the server no longer present
       
    68  * @leave KErrServerBusy, if the request cannot be handled at this time. 
       
    69  * @leave KErrNoMemory, if there is insufficient memory available.
       
    70  * @leave KErrPermissionDenied, if the caller has insufficient capabilities.
       
    71  * @leave KErrAuthServIdentityNotFound, if the id does not exist.
       
    72  **/
       
    73 EXPORT_C void RAuthMgrClient::RemoveIdentityL(
       
    74     TIdentityId aId)
       
    75     {
       
    76 	User::LeaveIfError(CallSessionFunction(ERemoveIdentity, TIpcArgs(aId)));
       
    77     }
       
    78 
       
    79 /**
       
    80  * Train an authentication plugin for the specified identity. The identity
       
    81  * to be trained must be authenticated prior to training. This is
       
    82  * necessary for the AuthServer to decrypt the protection key prior to
       
    83  * encrypting it with the new key generated through training.
       
    84  *
       
    85  * @param aId The identity for whom to train the plugin.
       
    86  *
       
    87  * @param aPlugin The id of the plugin to train.
       
    88  *
       
    89  * @param aRequest This status object will be completed when this
       
    90  * asynchronous call finishes.
       
    91  *
       
    92  * @capability WriteUserData
       
    93  *
       
    94  * @return KErrServerTerminated, if the server no longer present
       
    95  * @return KErrServerBusy, if the request cannot be handled at this time. 
       
    96  * @return KErrNoMemory, if there is insufficient memory available.
       
    97  * @return KErrPermissionDenied, if the caller has insufficient capabilities.
       
    98  * @return KErrAuthServIdentityNotFound, if the id does not exist.
       
    99  * @return KErrAuthServNoSuchPlugin, if the plugin does not exist.
       
   100  * @return KErrAuthServAuthenticationRequired, if the identity to be
       
   101  * trained is not currently authenticated.
       
   102  **/
       
   103 EXPORT_C void RAuthMgrClient::TrainPlugin(
       
   104     TIdentityId aId,
       
   105 	TPluginId aPlugin,
       
   106 	TRequestStatus& aRequest)
       
   107     {
       
   108     CallSessionFunction(ETrainPlugin, TIpcArgs(aId, aPlugin), aRequest);
       
   109     }
       
   110 
       
   111 
       
   112 /**
       
   113  * Remove the specified plugin as an authentication method for the
       
   114  * identity.
       
   115  *
       
   116  * @param aId The identity for whom to forget plugin training.
       
   117  *
       
   118  * @param aPlugin The id of the plugin to retrain.
       
   119  *
       
   120  * @capability WriteUserData
       
   121  *
       
   122  * @return KErrServerTerminated, if the server no longer present
       
   123  * @return KErrServerBusy, if the request cannot be handled at this time. 
       
   124  * @return KErrNoMemory, if there is insufficient memory available.
       
   125  * @return KErrPermissionDenied, if the caller has insufficient capabilities.
       
   126  * @return KErrAuthServIdentityNotFound, if the id does not exist.
       
   127  * @return KErrAuthServNoSuchPlugin, if the plugin does not exist.
       
   128  **/
       
   129 EXPORT_C void RAuthMgrClient::ForgetPluginL(
       
   130     TIdentityId aId,
       
   131 	TPluginId aPlugin)
       
   132     {
       
   133 	User::LeaveIfError(CallSessionFunction(EForgetPlugin, TIpcArgs(aId, aPlugin)));
       
   134     }
       
   135 
       
   136 
       
   137 /**
       
   138  * Specifies the preferred plugin for the named type.
       
   139  *
       
   140  * @param aType The type of plugin for which to define the preference.
       
   141  *
       
   142  * @param aPluginId The id of the preferred plugin for the specified type.
       
   143  *
       
   144  * @capability WriteDeviceData
       
   145  *
       
   146  * @return KErrServerTerminated, if the server no longer present
       
   147  * @return KErrServerBusy, if the request cannot be handled at this time. 
       
   148  * @return KErrNoMemory, if there is insufficient memory available.
       
   149  * @return KErrPermissionDenied, if the caller has insufficient capabilities.
       
   150  * @return KErrAuthServNoSuchPlugin, if the plugin does not exist.
       
   151  * @return KErrArgument, if aType does not match the plugin's type.
       
   152  **/
       
   153 EXPORT_C void RAuthMgrClient::SetPreferredTypePluginL(TAuthPluginType aType,
       
   154 													  TPluginId aPluginId)
       
   155 	{
       
   156 	User::LeaveIfError(CallSessionFunction(ESetAuthPreferences, TIpcArgs(aType, aPluginId)));
       
   157 	}
       
   158 
       
   159 /**
       
   160  * Reset the training data of a registered identity.
       
   161  *
       
   162  * @param aId The identity to reset.
       
   163  *
       
   164  * @param aRegistrationInformation The regisration information to be used for 
       
   165  * identifying the user. This data is meaningful for knowledge based  authentication 
       
   166  * server plugins (here the registration data could be the passphrase). 
       
   167  * Note that a plugin may choose to ignore the supplied registration data and simply 
       
   168  * remove the identity from its records.
       
   169  *
       
   170  * @capability WriteDeviceData
       
   171  *
       
   172  * @return KErrServerTerminated, if the server no longer present
       
   173  * @return KErrServerBusy, if the request cannot be handled at this time. 
       
   174  * @return KErrNoMemory, if there is insufficient memory available.
       
   175  * @return KErrPermissionDenied, if the caller has insufficient capabilities.
       
   176  * @return KErrAuthServIdentityNotFound, if the id cannot be found.
       
   177  * @return KErrAuthServResetMayLoseIdentity, if a reset can result in the loss of an identity. 
       
   178  * @see KErrAuthServResetMayLoseIdentity.
       
   179  * @return KErrArgument, if the supplied arguments are incorrect.
       
   180  * @return ... any of the system-wide error codes.
       
   181  **/
       
   182 EXPORT_C void RAuthMgrClient::ResetIdentityL(TIdentityId aId,
       
   183 							 const TDesC& aRegistrationInformation)
       
   184 	{
       
   185 	// Sanity check arguments
       
   186 	if (aId == 0)
       
   187 		{
       
   188 		User::Leave(KErrArgument);
       
   189 		}
       
   190 	User::LeaveIfError(CallSessionFunction(EResetIdentity, TIpcArgs(aId, &aRegistrationInformation)));
       
   191 	}
       
   192 
       
   193 /**
       
   194  * Reset the training data of a registered identity.
       
   195  *
       
   196  * @param aId The identity to reset.
       
   197  *
       
   198  * @param aPluginType The type of plugins for which to supply the registration data during the reset.
       
   199  * Note that currently only EAuthKnowledge type plugins is supported for this parameter.
       
   200  * 
       
   201  * @param aRegistrationInformation The regisration information to be used for 
       
   202  * identifying the user. This data is meaningful for knowledge based  authentication 
       
   203  * server plugins (here the registration data could be the passphrase). 
       
   204  * Note that a plugin may choose to ignore the supplied registration data and simply 
       
   205  * remove the identity from its records.
       
   206  *
       
   207  * @capability WriteDeviceData
       
   208  *
       
   209  * @return KErrServerTerminated, if the server no longer present
       
   210  * @return KErrServerBusy, if the request cannot be handled at this time. 
       
   211  * @return KErrNoMemory, if there is insufficient memory available.
       
   212  * @return KErrPermissionDenied, if the caller has insufficient capabilities.
       
   213  * @return KErrAuthServIdentityNotFound, if the id cannot be found.
       
   214  * @return KErrAuthServResetMayLooseIdentity, if a reset can result in the loss of an identity. 
       
   215  * @see KErrAuthServResetMayLooseIdentity.
       
   216  * @return KErrArgument, if the supplied arguments are incorrect.
       
   217  * @return ... any of the system-wide error codes.
       
   218  **/
       
   219 EXPORT_C void RAuthMgrClient::ResetIdentityL(TIdentityId aId,
       
   220 							 TAuthPluginType aPluginType,
       
   221 							 const TDesC& aRegistrationInformation)
       
   222 	{
       
   223 	// Sanity check arguments
       
   224 	if (aId == 0)
       
   225 		{
       
   226 		User::Leave(KErrArgument);
       
   227 		}
       
   228 	User::LeaveIfError(CallSessionFunction(EResetIdentityByType, TIpcArgs(aId, aPluginType, &aRegistrationInformation)));
       
   229 	}
       
   230 
       
   231 /**
       
   232  * Reset the training data of a registered identity.
       
   233  *
       
   234  * @param aId The identity to reset.
       
   235  *
       
   236  * @param aPluginIdList The list of plugin ids for which to supply the registration data during the reset.
       
   237  *
       
   238  * @param aRegistrationInformation An array of regisration information to be used for 
       
   239  * identifying the user. The order of elements in this array correspond to the order of plugin ids in 
       
   240  * aPluginIdList. This data is meaningful for knowledge based  authentication server 
       
   241  * plugins (here the registration data could be the passphrase). 
       
   242  * Note that a plugin may choose to ignore the supplied registration data and simply 
       
   243  * remove the identity from its records.
       
   244  *
       
   245  * @capability WriteDeviceData
       
   246  *
       
   247  * @return KErrServerTerminated, if the server no longer present
       
   248  * @return KErrServerBusy, if the request cannot be handled at this time. 
       
   249  * @return KErrNoMemory, if there is insufficient memory available.
       
   250  * @return KErrPermissionDenied, if the caller has insufficient capabilities.
       
   251  * @return KErrAuthServIdentityNotFound, if the id cannot be found.
       
   252  * @return KErrAuthServResetMayLooseIdentity, if a reset can result in the loss of an identity. 
       
   253  * @see KErrAuthServResetMayLooseIdentity.
       
   254  * @return KErrArgument, if the supplied arguments are incorrect.
       
   255  * @return ... any of the system-wide error codes.
       
   256  **/
       
   257 EXPORT_C void RAuthMgrClient::ResetIdentityL(TIdentityId aId,
       
   258 							 RArray<TPluginId>& aPluginIdList,
       
   259 							 RPointerArray<const HBufC>& aRegistrationInformation)
       
   260 	{
       
   261 	// Sanity check arguments
       
   262 	TInt count = aPluginIdList.Count();
       
   263 	if ((aId == 0) || (count < 1) || (count != aRegistrationInformation.Count()))
       
   264 		{
       
   265 		User::Leave(KErrArgument);
       
   266 		}
       
   267 
       
   268 	// Flatten aPluginIdList
       
   269 	HBufC8* bufPluginIds = AuthServerUtil::FlattenDataArrayLC(aPluginIdList);
       
   270 
       
   271 	// Flatten aRegistrationInformation
       
   272 	HBufC8* bufRegInfo = AuthServerUtil::FlattenDataPointerArrayLC(aRegistrationInformation);
       
   273 
       
   274 	User::LeaveIfError(CallSessionFunction(EResetIdentityByList, TIpcArgs(aId, bufPluginIds, bufRegInfo)));
       
   275 	CleanupStack::PopAndDestroy(2, bufPluginIds); // bufRegInfo
       
   276 	}