Chapter 27. API

API contains Credential and CredentialType interfaces. CredentialType defines type of credential object. Default implementation supports two types:

Two basic implementations are provided:

Because credentials values are stored as hash or in other encoded form both SPI and API only enables to update and validate credential value and not to read it from persistence store. API enables to only protect Identity objects with credentials. All related management operations are exposed in AttributesManager interface.



User anotherOne = session.getPersistenceManager().createUser("blah1");

session.getAttributesManager().updatePassword(anotherOne, "Password2000");
assertTrue(session.getAttributesManager().validatePassword(anotherOne, "Password2000"));

Credential password = new PasswordCredential("SuperPassword2345");
session.getAttributesManager().updateCredential(anotherOne, password);
assertTrue(session.getAttributesManager().validateCredentials(anotherOne, new Credential[]{password}));

// binary credential
byte[] cert = new byte[512000];
random.nextBytes(cert);
Credential binaryCredential = new BinaryCredential(cert);
session.getAttributesManager().updateCredential(anotherOne, binaryCredential);
assertTrue(session.getAttributesManager().validateCredentials(anotherOne, new Credential[]{binaryCredential}));