Skip to main content

Examples

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

Create DataAttribute

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

// Create DataAttribute
DataAttribute dataAttribute = new DataAttribute();
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 DataAttribute();
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"));
listCredentialCallback.setMappings(mappings);

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

Create DataAttribute with STRING content

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

// Cretae DataAttribute
DataAttribute dataAttribute = new DataAttribute();
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 DataAttribute();
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
InfoAttribute infoAttribute = new InfoAttribute();
infoAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120002");
infoAttribute.setName("myAttribute");
infoAttribute.setType(AttributeType.INFO);
infoAttribute.setContentType(AttributeContentType.STRING);
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.

// Cretae DataAttribute
DataAttribute dataAttribute = new DataAttribute();
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
InfoAttribute infoAttribute = new InfoAttribute();
infoAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120003");
infoAttribute.setName("myAttribute1");
infoAttribute.setType(AttributeType.INFO);
infoAttribute.setContentType(AttributeContentType.STRING);
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
GroupAttribute groupAttribute = new GroupAttribute();
groupAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120004");
groupAttribute.setName("groupAttribute");
groupAttribute.setType(AttributeType.GROUP);
groupAttribute.setContentType(AttributeContentType.STRING);
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 MetadataAttribute();
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 CustomAttribute();
customAttribute.setUuid("42323bd4-7ac6-11ed-a1eb-0242ac120002");
customAttribute.setName("myAttribute");
customAttribute.setType(AttributeType.DATA);
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);