Skip to main content

Examples

You can find here various examples of how to create and use attributes in different programming languages.

Use V3 for new implementations

V2 is deprecated. New connector implementations should use V3 attribute classes exclusively. V2 examples are provided for reference when maintaining existing connectors.

Versioned classes

The attribute base classes (DataAttribute, InfoAttribute, MetadataAttribute, CustomAttribute) are abstract. Use the versioned implementations (DataAttributeV2/DataAttributeV3, etc.) when creating attribute instances. Each example below provides both V2 and V3 tabs. Key differences in V3: attribute content classes include contentType automatically (e.g., StringAttributeContentV3), and the attribute itself carries version and schemaVersion fields.

Create DataAttribute

This example shows how to create DataAttribute which is the attribute of type DATA.

// Create DataAttribute
DataAttribute dataAttribute = new DataAttributeV2();
dataAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120002");
dataAttribute.setName("myAttribute");
dataAttribute.setContentType(AttributeContentType.STRING);
dataAttribute.setType(AttributeType.DATA);
dataAttribute.setDescription("This is my attribute");

// Create DataAttributeProperties
DataAttributeProperties dataAttributeProperties = new DataAttributeProperties();
dataAttributeProperties.setRequired(true);
dataAttributeProperties.setReadOnly(false);
dataAttributeProperties.setVisible(true);
dataAttributeProperties.setLabel("My Attribute");
dataAttributeProperties.setMultiSelect(false);
dataAttributeProperties.setGroup("My Group");
dataAttributeProperties.setList(false);

// Add DataAttributeProperties to DataAttribute
dataAttribute.setProperties(dataAttributeProperties);

Create DataAttribute with AttributeCallback

This example shows how to create DataAttribute with AttributeCallback.

// Create DataAttribute
DataAttribute dataAttribute = new DataAttributeV2();
dataAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120002");
dataAttribute.setName("myAttribute");
dataAttribute.setType(AttributeType.DATA);
dataAttribute.setContentType(AttributeContentType.STRING);
dataAttribute.setDescription("This is my attribute");

// Create DataAttributeProperties
DataAttributeProperties dataAttributeProperties = new DataAttributeProperties();
dataAttributeProperties.setRequired(true);
dataAttributeProperties.setReadOnly(false);
dataAttributeProperties.setVisible(true);
dataAttributeProperties.setLabel("My Attribute");
dataAttributeProperties.setMultiSelect(false);
dataAttributeProperties.setGroup("My Group");
dataAttributeProperties.setList(false);

// Add DataAttributeProperties to DataAttribute
dataAttribute.setProperties(dataAttributeProperties);

// Create AttributeCallback
AttributeCallback attributeCallback = new AttributeCallback();
attributeCallback.setCallbackContext("/api/test");
attributeCallback.setCallbackMethod("GET");
Set<AttributeCallbackMapping> mappings = new HashSet<>();
mappings.add(new AttributeCallbackMapping(
"credentialKind",
AttributeValueTarget.PATH_VARIABLE,
"SoftKeyStore"));
attributeCallback.setMappings(mappings);

// Add AttributeCallback to DataAttribute
dataAttribute.setAttributeCallback(attributeCallback);

Create DataAttribute with STRING content

This example shows how to create DataAttribute with content of type STRING.

// Create DataAttribute
DataAttribute dataAttribute = new DataAttributeV2();
dataAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120002");
dataAttribute.setName("myAttribute");
dataAttribute.setType(AttributeType.DATA);
dataAttribute.setContentType(AttributeContentType.STRING);
dataAttribute.setDescription("This is my attribute");

// Create DataAttributeProperties
DataAttributeProperties dataAttributeProperties = new DataAttributeProperties();
dataAttributeProperties.setRequired(true);
dataAttributeProperties.setReadOnly(false);
dataAttributeProperties.setVisible(true);
dataAttributeProperties.setLabel("My Attribute");
dataAttributeProperties.setMultiSelect(false);
dataAttributeProperties.setGroup("My Group");
dataAttributeProperties.setList(true);

// Add DataAttributeProperties to DataAttribute
dataAttribute.setProperties(dataAttributeProperties);

// Create StringAttributeContent
List<StringAttributeContent> content = new ArrayList<>();
content.add(new StringAttributeContent("sampleReference1", "sampleData1"));
content.add(new StringAttributeContent("sampleReference2", "sampleData2"));
content.add(new StringAttributeContent("sampleReference3", "sampleData3"));

// Add StringAttributeContent to DataAttribute
dataAttribute.setContent(content);

Create DataAttribute with REGEXP constraint

This example shows how to create DataAttribute with the RegExpAttributeConstraint for validation of the content.

// Create DataAttribute
DataAttribute dataAttribute = new DataAttributeV2();
dataAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120002");
dataAttribute.setName("myAttribute");
dataAttribute.setType(AttributeType.DATA);
dataAttribute.setContentType(AttributeContentType.STRING);
dataAttribute.setDescription("This is my attribute");

// Create DataAttributeProperties
DataAttributeProperties dataAttributeProperties = new DataAttributeProperties();
dataAttributeProperties.setRequired(true);
dataAttributeProperties.setReadOnly(false);
dataAttributeProperties.setVisible(true);
dataAttributeProperties.setLabel("My Attribute");
dataAttributeProperties.setMultiSelect(false);
dataAttributeProperties.setGroup("My Group");
dataAttributeProperties.setList(false);

// Add DataAttributeProperties to DataAttribute
dataAttribute.setProperties(dataAttributeProperties);

// Create RegExpAttributeConstraint
RegExpAttributeConstraint regExpAttributeConstraint = new RegExpAttributeConstraint();
regExpAttributeConstraint.setDescription("This is a regular expression constraint");
regExpAttributeConstraint.setErrorMessage("This is a sample error message");
regExpAttributeConstraint.setType(AttributeConstraintType.REGEXP);
regExpAttributeConstraint.setData("^[a-zA-Z0-9]*$");

// Add RegExpAttributeConstraint to DataAttribute
dataAttribute.setConstraint(List.of(regExpAttributeConstraint));

Create InfoAttribute with TEXT content

This example shows how to create InfoAttribute which is attribute of type INFO.

// Create InfoAttribute
InfoAttributeV2 infoAttribute = new InfoAttributeV2();
infoAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120002");
infoAttribute.setName("myAttribute");
infoAttribute.setType(AttributeType.INFO);
infoAttribute.setContentType(AttributeContentType.TEXT);
infoAttribute.setDescription("This is my attribute");

// Create InfoAttributeProperties
InfoAttributeProperties infoAttributeProperties = new InfoAttributeProperties();
infoAttributeProperties.setLabel("My Attribute");
infoAttributeProperties.setGroup("My Group");
infoAttributeProperties.setVisible(true);

// Add InfoAttributeProperties to InfoAttribute
infoAttribute.setProperties(infoAttributeProperties);

// Create TextAttributeContent
TextAttributeContent textAttributeContent = new TextAttributeContent();
textAttributeContent.setReference("Sample Reference Data");
textAttributeContent.setData("This is a sample text that has to be displayed in the user interface. This attribute data contains additional information that helps the user to understand the context of the request.");

// Add TextAttributeContent to InfoAttribute
infoAttribute.setContent(List.of(textAttributeContent));

Create GroupAttribute with INFO and DATA attributes

This example shows how to create GroupAttribute that is of type GROUP with DataAttribute and InfoAtrribute.

// Create DataAttribute
DataAttribute dataAttribute = new DataAttributeV2();
dataAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120002");
dataAttribute.setName("myAttribute");
dataAttribute.setType(AttributeType.DATA);
dataAttribute.setContentType(AttributeContentType.STRING);
dataAttribute.setDescription("This is my attribute");

// Create DataAttributeProperties
DataAttributeProperties dataAttributeProperties = new DataAttributeProperties();
dataAttributeProperties.setRequired(true);
dataAttributeProperties.setReadOnly(false);
dataAttributeProperties.setVisible(true);
dataAttributeProperties.setLabel("My Attribute");
dataAttributeProperties.setMultiSelect(false);
dataAttributeProperties.setGroup("My Group");
dataAttributeProperties.setList(false);

// Add DataAttributeProperties to DataAttribute
dataAttribute.setProperties(dataAttributeProperties);

// Create InfoAttribute
InfoAttributeV2 infoAttribute = new InfoAttributeV2();
infoAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120003");
infoAttribute.setName("myAttribute1");
infoAttribute.setType(AttributeType.INFO);
infoAttribute.setContentType(AttributeContentType.TEXT);
infoAttribute.setDescription("This is my attribute 1");

// Create InfoAttributeProperties
InfoAttributeProperties infoAttributeProperties = new InfoAttributeProperties();
infoAttributeProperties.setLabel("My Attribute");
infoAttributeProperties.setGroup("My Group");
infoAttributeProperties.setVisible(true);

// Add InfoAttributeProperties to InfoAttribute
infoAttribute.setProperties(infoAttributeProperties);

// Create TextAttributeContent
TextAttributeContent textAttributeContent = new TextAttributeContent();
textAttributeContent.setReference("Sample Reference Data");
textAttributeContent.setData("Reference data for info attribute");

// Add TextAttributeContent to InfoAttribute
infoAttribute.setContent(List.of(textAttributeContent));

// Create GroupAttribute (content is a list of other attributes)
GroupAttributeV2 groupAttribute = new GroupAttributeV2();
groupAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120004");
groupAttribute.setName("groupAttribute");
groupAttribute.setType(AttributeType.GROUP);
groupAttribute.setDescription("Sample Group Attribute");

// Add DataAttribute and InfoAttribute to GroupAttribute
groupAttribute.setContent(List.of(dataAttribute, infoAttribute));

Create MetadataAttribute with STRING content

This example shows how to create MetadataAttribute that is of type META.

// Create MetadataAttribute
MetadataAttribute metadataAttribute = new MetadataAttributeV2();
metadataAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120002");
metadataAttribute.setName("discoverySource");
metadataAttribute.setType(AttributeType.METADATA);
metadataAttribute.setContentType(AttributeContentType.STRING);
metadataAttribute.setDescription("Metadata describing the source of the certificate discovered");

// Create MetadataAttributeProperties
MetadataAttributeProperties metadataAttributeProperties = new MetadataAttributeProperties();
metadataAttributeProperties.setLabel("Discovery Source");
metadataAttributeProperties.setGroup("Discovery");
metadataAttributeProperties.setVisible(true);
//Setting the metadata as global metadata
metadataAttributeProperties.setGlobal(true);

// Add MetadataAttributeProperties to MetadataAttribute
metadataAttribute.setProperties(metadataAttributeProperties);

// Create StringAttributeContent
StringAttributeContent stringAttributeContent = new StringAttributeContent();
stringAttributeContent.setReference("google.com");
stringAttributeContent.setData("google.com");

// Add StringAttributeContent to MetadataAttribute
metadataAttribute.setContent(List.of(stringAttributeContent));

Create CustomAttribute

This example shows how to create CustomAttribute of attribute type CUSTOM.

// Create CustomAttribute
CustomAttribute customAttribute = new CustomAttributeV2();
customAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120002");
customAttribute.setName("myAttribute");
customAttribute.setType(AttributeType.CUSTOM);
customAttribute.setContentType(AttributeContentType.STRING);
customAttribute.setDescription("This is my attribute");

// Create CustomAttributeProperties
CustomAttributeProperties customAttributeProperties = new CustomAttributeProperties();
customAttributeProperties.setRequired(true);
customAttributeProperties.setReadOnly(false);
customAttributeProperties.setVisible(true);
customAttributeProperties.setLabel("My Attribute");
customAttributeProperties.setMultiSelect(false);
customAttributeProperties.setGroup("My Group");
customAttributeProperties.setList(false);

// Add CustomAttributeProperties to CustomAttribute
customAttribute.setProperties(customAttributeProperties);

Create DataAttribute with RESOURCE OBJECT content

This example shows how to create a DataAttribute with RESOURCE OBJECT content type. This content type is V3-only and is used for referencing platform resources (e.g., Certificate, Credential, Authority). It replaces the V2-only SECRET and CREDENTIAL content types.

The resource property in DataAttributeProperties must be set to indicate which resource type the attribute references. A Resource Callback can optionally be defined to filter the available resource objects.

// Create DataAttribute with RESOURCE OBJECT content
DataAttribute dataAttribute = new DataAttributeV3();
dataAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120002");
dataAttribute.setName("credentialAttribute");
dataAttribute.setType(AttributeType.DATA);
dataAttribute.setContentType(AttributeContentType.RESOURCE);
dataAttribute.setDescription("Select a credential to use");

// Create DataAttributeProperties with resource type
DataAttributeProperties dataAttributeProperties = new DataAttributeProperties();
dataAttributeProperties.setRequired(true);
dataAttributeProperties.setReadOnly(false);
dataAttributeProperties.setVisible(true);
dataAttributeProperties.setLabel("Credential");
dataAttributeProperties.setList(true);
dataAttributeProperties.setMultiSelect(false);
dataAttributeProperties.setGroup("Authentication");
dataAttributeProperties.setResource(AttributeResource.CREDENTIAL);

// Add DataAttributeProperties to DataAttribute
dataAttribute.setProperties(dataAttributeProperties);

// Create ResourceObjectContent with ResourceSimpleContentData
ResourceSimpleContentData resourceData = new ResourceSimpleContentData(
AttributeResource.CREDENTIAL,
"a1b2c3d4-5678-90ab-cdef-1234567890ab",
"My Credential",
null
);
ResourceObjectContent resourceContent = new ResourceObjectContent(
"My Credential",
resourceData
);

// Add ResourceObjectContent to DataAttribute
dataAttribute.setContent(List.of(resourceContent));