Product SiteDocumentation Site

6.4. Managed attributes

Managed attributes are a special type of ad-hoc attributes where they are also mapped to a specific property of an AttributedType (eg.: identity types, partitions and relationships). They are stored in the same way as ad-hoc attributes. However, instead of having to handle these attributes using the getAttribute , setAttribute and removeAttribute methods, you just use the getter an setter of a property, in a more type-safe manner.
Another important thing about managed attributes is that they don't require changes to the identity store schema if you want to support custom attributes. For instance, suppose you have the following custom identity type representing applications in your identity model:
public class Application extends AbstractIdentityType {

    @AttributeProperty(managed = true)
    private String name;
}
If you are using the JPA identity store, you will probably need a specific entity mapping in order to store this type and its properties. Let's suppose you already have an entity that maps this type with the name property. Now, if you want to add another property to this type you need to store it somewhere. In this case, you can map the property in the corresponding entity or use managed attributes to store it as an ad-hoc attribute and still access it in a type-safe manner.
public class Application extends AbstractIdentityType {
    @AttributeProperty(managed = true)
    private String name;
    @AttributeProperty(managed = true)
    private String url;
}
From the code above, you can now manage the url property as follows:
Application application = // obtain from IdentityManager

application.setUrl("http://mydomain.com/app")

identityManager.update(application);
When storing this property, PicketLink will actually store it as an ad-hoc attribute. What means you can also have access to its value as follows:
Application application = // obtain from IdentityManager

Attribute<String> url application.getAttribute("url");
If you are using the JPA Identity Store and the Default Database Schema(Section 8.1.1, “Default Database Schema”), managed attributes can help you to create your custom types very easily. The default schema is flexible enough to support most requirements when creating custom types.