Setting a Security Question Answer
To set the security answer, complete the following steps:
-
Establish the wallet and credential manager clients.
CopyCredentialManager cm = ...; WalletId walletId = ...;
Note: The application ID is not necessary for setting up criteria based on security questions and answers. -
Set up search criteria based on security questions and credential type answers (the constant is CRED_ELEMENT_TYPE_SQ) and walletId:
CopyCriteria[] criteria = {
new Criteria(CCMConstants.CRITERIA_CRED_TYPE, CCMConstants.CRITERIA_COMPARISON_EQUAL, CCMConstants.CRED_ID_TYPE_SQ),
new Criteria(CCMConstants. CRITERIA_CRED_PARENT_WALLET, CCMConstants.CRITERIA_COMPARISON_EQUAL,
walletId.getId())
};Note: If more than one credential is returned, then an error has occurred. -
Get credential IDs based on supplied search criteria.
CopyCredentialId[] credIds = cm.findCredentialIds(criteria, maxItem);
-
At this point, there are two possibilities:
-
Either the security question answers have been provisioned (and can therefore be updated), or
-
The required security question answers required must be imported.
If the security question answers have already been provisioned (and can be updated), then make sure that the following conditions are met:
-
Get credentials based on credential IDs:
Copyif (credIds.length == 1){
Credential[] creds = cm.getCredentials(credIds);
-
Using the profile ID, get the Input Requirements for the update.
CopyEntryTemplate[] entries = cm.getProfileDynamicEntries(
creds[0].getProfileId());
-
For each entry, set the security question answer:
Copyfor (int i = 0; i < entries.length; i++) {
// Display the question
System.out.println(entries[i].getLabel()");
// Get the answer from the standard input or in another way
String answer = .........;
//Set the security question answer entries[i].setValue(answer);
}
-
Once all necessary entries have been set, submit the change by invoking updateCredential:
Copycm.updateCredential (credIds[0], CCMConstants.ACTION_ID_CRED_REPLACE, entries);
If security question answers are not already provisioned, then the required answers must be imported. To do this, make sure that the following conditions are met:
-
Create a new array of CredentialElements. For each CredentialElement set the ID to the key corresponding to that Entry. For each CredentialElement, assign the security question answer as its value:
Copyfor (int i = 0; i < entries.length; i++) {
// Display the question
System.out.println(entries[i].getLabel()");
// Get theanswer from the standard input or other ways
String answer = .........;
System.out.println(entries[i].getLabel() + " : " +
answer);
CredentialElement credEl = new CredentialElement(); credEl.setId(entries[i].getKey()); credEl.setIsReference(false); credEl.setValue(answer);
credElList.add(credEl);
}
-
Once the CredentialElement array has been populated with the necessary entries, instantiate a new Credential object, assign it to the CredentialElements, and invoke the Import method:
CopyCredential[] creds = { new Credential() }; creds[0].setProfileId(credProfIds[0]); creds[0].setCredentialElements(credElList.toArray(
new CredentialElement[credElList.size()]));
cm.importCredentials(walletId, creds);
-