JBoss.orgCommunity Documentation

Chapter 27. API

27.1. Sample operations

On the API level each IdentityType object (Identity and Group) can have associated Attribute objects. All operations are exposed by AttributesManager interface. Each attribute is described with AttributeDescription that contains its properties such as:

Default implementation provides two attribute types:

Identity user = session.getPersistenceManager().
createIdentity("sampleUser");

// Check that binary attribute 'picture' is mapped

AttributeDescription attributeDescription =
session.getAttributesManager().
getAttributeDescription(user, "picture");
assertNotNull(attributeDescription);
assertEquals("binary", attributeDescription.getType());


// Generate random binary data for binary attribute

Random random = new Random();
byte[] picture = new byte[5120];
random.nextBytes(picture);


// User attributes
Attribute[] userInfo = new Attribute[]
{
new SimpleAttribute(P3PConstants.INFO_USER_NAME_GIVEN,
new String[]{"John"}),
new SimpleAttribute(P3PConstants.INFO_USER_NAME_FAMILY,
new String[]{"Doe"}),
new SimpleAttribute("picture", new byte[][]{picture})
};

session.getAttributesManager().
addAttributes(user, userInfo);

....

AttributesManager attrMgr = session.getAttributesManager();

attrMgr.addAttribute(anneUser,
P3PConstants.INFO_USER_NAME_GIVEN, "Anne");
attrMgr.addAttribute(anneUser,
P3PConstants.INFO_USER_NAME_FAMILY, "Smith");
attrMgr.addAttribute(anneUser,
P3PConstants.INFO_USER_JOB_TITLE, "Senior Software Developer");
attrMgr.addAttribute(anneUser,
P3PConstants.INFO_USER_BUSINESS_INFO_ONLINE_EMAIL, "anne.smith@acme.com");
attrMgr.addAttribute(anneUser,
P3PConstants.INFO_USER_BUSINESS_INFO_TELECOM_MOBILE_NUMBER, "777 777 777 7 77");