Class Item

All Implemented Interfaces:
AsyncInitable, DBusInterface, Initable, Retrievable, Proxy

@Generated("org.javagi.JavaGI") public class Item extends DBusProxy implements AsyncInitable, DBusInterface, Initable, Retrievable

A secret item

SecretItem represents a secret item stored in the Secret Service.

Each item has a value, represented by a Value, which can be retrieved by getSecret() or set by setSecret(Value, Cancellable, AsyncReadyCallback). The item is only available when the item is not locked.

Items can be locked or unlocked using the Service.lock(List, Cancellable, AsyncReadyCallback) or Service.unlock(List, Cancellable, AsyncReadyCallback) functions. The Secret Service may not be able to unlock individual items, and may unlock an entire collection when a single item is unlocked.

Each item has a set of attributes, which are used to locate the item later. These are not stored or transferred in a secure manner. Each attribute has a string name and a string value. Use Service.search(Schema, HashTable, Set, Cancellable, AsyncReadyCallback) to search for items based on their attributes, and setAttributes(Schema, HashTable, Cancellable, AsyncReadyCallback) to change the attributes associated with an item.

Items can be created with create(Collection, Schema, HashTable, String, Value, Set, Cancellable, AsyncReadyCallback) or Service.store(Schema, HashTable, String, String, Value, Cancellable, AsyncReadyCallback).

  • Constructor Details

    • Item

      public Item(MemorySegment address)
      Create a Item instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • Item

      public Item()
      Create a new Item.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the Item class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected Item asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class DBusProxy
      Returns:
      the instance as if it were its parent type
    • forDbusPathFinish

      public static Item forDbusPathFinish(AsyncResult result) throws GErrorException
      Finish asynchronous operation to get a new item proxy for a secret item in the secret service.
      Parameters:
      result - the asynchronous result passed to the callback
      Returns:
      the new item, which should be unreferenced with GObject#unref
      Throws:
      GErrorException - see GError
    • forDbusPathSync

      public static Item forDbusPathSync(@Nullable Service service, String itemPath, Set<ItemFlags> flags, @Nullable Cancellable cancellable) throws GErrorException

      Get a new item proxy for a secret item in the secret service.

      If service is null, then Service.getSync(Set, Cancellable) will be called to get the default Service proxy.

      This method may block indefinitely and should not be used in user interface threads.

      Parameters:
      service - a secret service object
      itemPath - the D-Bus path of the item
      flags - initialization flags for the new item
      cancellable - optional cancellation object
      Returns:
      the new item, which should be unreferenced with GObject#unref
      Throws:
      GErrorException - see GError
    • forDbusPathSync

      public static Item forDbusPathSync(@Nullable Service service, String itemPath, ItemFlags flags, @Nullable Cancellable cancellable) throws GErrorException

      Get a new item proxy for a secret item in the secret service.

      If service is null, then Service.getSync(Set, Cancellable) will be called to get the default Service proxy.

      This method may block indefinitely and should not be used in user interface threads.

      Parameters:
      service - a secret service object
      itemPath - the D-Bus path of the item
      flags - initialization flags for the new item
      cancellable - optional cancellation object
      Returns:
      the new item, which should be unreferenced with GObject#unref
      Throws:
      GErrorException - see GError
    • create

      public static void create(Collection collection, @Nullable Schema schema, HashTable<String,String> attributes, String label, Value value, Set<ItemCreateFlags> flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Create a new item in the secret service.

      If the flags contains ItemCreateFlags.REPLACE, then the secret service will search for an item matching the attributes, and update that item instead of creating a new one.

      This method may block indefinitely and should not be used in user interface threads. The secret service may prompt the user. Service.prompt(Prompt, VariantType, Cancellable, AsyncReadyCallback) will be used to handle any prompts that are required.

      Parameters:
      collection - a secret collection to create this item in
      schema - the schema for the attributes
      attributes - attributes for the new item
      label - label for the new item
      value - secret value for the new item
      flags - flags for the creation of the new item
      cancellable - optional cancellation object
      callback - called when the operation completes
    • create

      public static void create(Collection collection, @Nullable Schema schema, HashTable<String,String> attributes, String label, Value value, ItemCreateFlags flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Create a new item in the secret service.

      If the flags contains ItemCreateFlags.REPLACE, then the secret service will search for an item matching the attributes, and update that item instead of creating a new one.

      This method may block indefinitely and should not be used in user interface threads. The secret service may prompt the user. Service.prompt(Prompt, VariantType, Cancellable, AsyncReadyCallback) will be used to handle any prompts that are required.

      Parameters:
      collection - a secret collection to create this item in
      schema - the schema for the attributes
      attributes - attributes for the new item
      label - label for the new item
      value - secret value for the new item
      flags - flags for the creation of the new item
      cancellable - optional cancellation object
      callback - called when the operation completes
    • createFinish

      public static Item createFinish(AsyncResult result) throws GErrorException
      Finish operation to create a new item in the secret service.
      Parameters:
      result - the asynchronous result passed to the callback
      Returns:
      the new item, which should be unreferenced with GObject#unref
      Throws:
      GErrorException - see GError
    • createSync

      public static Item createSync(Collection collection, @Nullable Schema schema, HashTable<String,String> attributes, String label, Value value, Set<ItemCreateFlags> flags, @Nullable Cancellable cancellable) throws GErrorException

      Create a new item in the secret service.

      If the flags contains ItemCreateFlags.REPLACE, then the secret service will search for an item matching the attributes, and update that item instead of creating a new one.

      This method may block indefinitely and should not be used in user interface threads. The secret service may prompt the user. Service.prompt(Prompt, VariantType, Cancellable, AsyncReadyCallback) will be used to handle any prompts that are required.

      Parameters:
      collection - a secret collection to create this item in
      schema - the schema for the attributes
      attributes - attributes for the new item
      label - label for the new item
      value - secret value for the new item
      flags - flags for the creation of the new item
      cancellable - optional cancellation object
      Returns:
      the new item, which should be unreferenced with GObject#unref
      Throws:
      GErrorException - see GError
    • createSync

      public static Item createSync(Collection collection, @Nullable Schema schema, HashTable<String,String> attributes, String label, Value value, ItemCreateFlags flags, @Nullable Cancellable cancellable) throws GErrorException

      Create a new item in the secret service.

      If the flags contains ItemCreateFlags.REPLACE, then the secret service will search for an item matching the attributes, and update that item instead of creating a new one.

      This method may block indefinitely and should not be used in user interface threads. The secret service may prompt the user. Service.prompt(Prompt, VariantType, Cancellable, AsyncReadyCallback) will be used to handle any prompts that are required.

      Parameters:
      collection - a secret collection to create this item in
      schema - the schema for the attributes
      attributes - attributes for the new item
      label - label for the new item
      value - secret value for the new item
      flags - flags for the creation of the new item
      cancellable - optional cancellation object
      Returns:
      the new item, which should be unreferenced with GObject#unref
      Throws:
      GErrorException - see GError
    • loadSecrets

      public static void loadSecrets(List<Item> items, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Load the secret values for a secret item stored in the service.

      The items must all have the same Item:service property.

      This function returns immediately and completes asynchronously.

      Parameters:
      items - the items to retrieve secrets for
      cancellable - optional cancellation object
      callback - called when the operation completes
    • loadSecretsFinish

      public static boolean loadSecretsFinish(AsyncResult result) throws GErrorException

      Complete asynchronous operation to load the secret values for secret items stored in the service.

      Items that are locked will not have their secrets loaded.

      Parameters:
      result - asynchronous result passed to callback
      Returns:
      whether the operation succeeded or not
      Throws:
      GErrorException - see GError
    • loadSecretsSync

      public static boolean loadSecretsSync(List<Item> items, @Nullable Cancellable cancellable) throws GErrorException

      Load the secret values for a secret item stored in the service.

      The items must all have the same Item:service property.

      This method may block indefinitely and should not be used in user interface threads.

      Items that are locked will not have their secrets loaded.

      Parameters:
      items - the items to retrieve secrets for
      cancellable - optional cancellation object
      Returns:
      whether the operation succeeded or not
      Throws:
      GErrorException - see GError
    • newForDbusPath

      public static void newForDbusPath(@Nullable Service service, String itemPath, Set<ItemFlags> flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Get a new item proxy for a secret item in the secret service.

      If service is null, then Service.get(Set, Cancellable, AsyncReadyCallback) will be called to get the default Service proxy.

      This method will return immediately and complete asynchronously.

      Parameters:
      service - a secret service object
      itemPath - the D-Bus path of the collection
      flags - initialization flags for the new item
      cancellable - optional cancellation object
      callback - called when the operation completes
    • newForDbusPath

      public static void newForDbusPath(@Nullable Service service, String itemPath, ItemFlags flags, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Get a new item proxy for a secret item in the secret service.

      If service is null, then Service.get(Set, Cancellable, AsyncReadyCallback) will be called to get the default Service proxy.

      This method will return immediately and complete asynchronously.

      Parameters:
      service - a secret service object
      itemPath - the D-Bus path of the collection
      flags - initialization flags for the new item
      cancellable - optional cancellation object
      callback - called when the operation completes
    • delete

      public void delete(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Delete this item.

      This method returns immediately and completes asynchronously. The secret service may prompt the user. Service.prompt(Prompt, VariantType, Cancellable, AsyncReadyCallback) will be used to handle any prompts that show up.

      Parameters:
      cancellable - optional cancellation object
      callback - called when the operation completes
    • deleteFinish

      public boolean deleteFinish(AsyncResult result) throws GErrorException
      Complete asynchronous operation to delete the secret item.
      Parameters:
      result - asynchronous result passed to the callback
      Returns:
      whether the item was successfully deleted or not
      Throws:
      GErrorException - see GError
    • deleteSync

      public boolean deleteSync(@Nullable Cancellable cancellable) throws GErrorException

      Delete this secret item.

      This method may block indefinitely and should not be used in user interface threads. The secret service may prompt the user. Service.prompt(Prompt, VariantType, Cancellable, AsyncReadyCallback) will be used to handle any prompts that show up.

      Parameters:
      cancellable - optional cancellation object
      Returns:
      whether the item was successfully deleted or not
      Throws:
      GErrorException - see GError
    • getAttributes

      public HashTable<String,String> getAttributes()

      Set the attributes of this item.

      The attributes are a mapping of string keys to string values. Attributes are used to search for items. Attributes are not stored or transferred securely by the secret service.

      Do not modify the attributes returned by this method. Use setAttributes(Schema, HashTable, Cancellable, AsyncReadyCallback) instead.

      Specified by:
      getAttributes in interface Retrievable
      Returns:
      a new reference to the attributes, which should not be modified, and released with HashTable#unref
    • getCreated

      public long getCreated()

      Get the created date and time of the item.

      The return value is the number of seconds since the unix epoch, January 1st 1970.

      Specified by:
      getCreated in interface Retrievable
      Returns:
      the created date and time
    • getItemFlags

      public Set<ItemFlags> getItemFlags()

      Get the flags representing what features of the SecretItem proxy have been initialized.

      Use loadSecret(Cancellable, AsyncReadyCallback) to initialize further features and change the flags.

      Returns:
      the flags for features initialized
    • getLabel

      public String getLabel()
      Get the label of this item.
      Specified by:
      getLabel in interface Retrievable
      Returns:
      the label, which should be freed with GLib#free
    • getLocked

      public boolean getLocked()

      Get whether the item is locked or not.

      Depending on the secret service an item may not be able to be locked independently from the collection that it is in.

      Returns:
      whether the item is locked or not
    • getModified

      public long getModified()

      Get the modified date and time of the item.

      The return value is the number of seconds since the unix epoch, January 1st 1970.

      Specified by:
      getModified in interface Retrievable
      Returns:
      the modified date and time
    • getSchemaName

      public @Nullable String getSchemaName()
      Gets the name of the schema that this item was stored with. This is also available at the xdg:schema attribute.
      Returns:
      the schema name
    • getSecret

      public @Nullable Value getSecret()

      Get the secret value of this item.

      If this item is locked or the secret has not yet been loaded then this will return null.

      To load the secret call the loadSecret(Cancellable, AsyncReadyCallback) method.

      Returns:
      the secret value which should be released with Value.unref(), or null
    • getService

      public Service getService()
      Get the Secret Service object that this item was created with.
      Returns:
      the Secret Service object
    • loadSecret

      public void loadSecret(@Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Load the secret value of this item.

      Each item has a single secret which might be a password or some other secret binary value.

      This function will fail if the secret item is locked.

      This function returns immediately and completes asynchronously.

      Parameters:
      cancellable - optional cancellation object
      callback - called when the operation completes
    • loadSecretFinish

      public boolean loadSecretFinish(AsyncResult result) throws GErrorException

      Complete asynchronous operation to load the secret value of this item.

      The newly loaded secret value can be accessed by calling getSecret().

      Parameters:
      result - asynchronous result passed to callback
      Returns:
      whether the secret item successfully loaded or not
      Throws:
      GErrorException - see GError
    • loadSecretSync

      public boolean loadSecretSync(@Nullable Cancellable cancellable) throws GErrorException

      Load the secret value of this item.

      Each item has a single secret which might be a password or some other secret binary value.

      This function may block indefinitely. Use the asynchronous version in user interface threads.

      Parameters:
      cancellable - optional cancellation object
      Returns:
      whether the secret item successfully loaded or not
      Throws:
      GErrorException - see GError
    • refresh

      public void refresh()

      Refresh the properties on this item.

      This fires off a request to refresh, and the properties will be updated later.

      Calling this method is not normally necessary, as the secret service will notify the client when properties change.

    • setAttributes

      public void setAttributes(@Nullable Schema schema, HashTable<String,String> attributes, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Set the attributes of this item.

      The attributes are a mapping of string keys to string values. Attributes are used to search for items. Attributes are not stored or transferred securely by the secret service.

      This function returns immediately and completes asynchronously.

      Parameters:
      schema - the schema for the attributes
      attributes - a new set of attributes
      cancellable - optional cancellation object
      callback - called when the asynchronous operation completes
    • setAttributesFinish

      public boolean setAttributesFinish(AsyncResult result) throws GErrorException
      Complete operation to set the attributes of this item.
      Parameters:
      result - asynchronous result passed to the callback
      Returns:
      whether the change was successful or not
      Throws:
      GErrorException - see GError
    • setAttributesSync

      public boolean setAttributesSync(@Nullable Schema schema, HashTable<String,String> attributes, @Nullable Cancellable cancellable) throws GErrorException

      Set the attributes of this item.

      The attributes are a mapping of string keys to string values. Attributes are used to search for items. Attributes are not stored or transferred securely by the secret service.

      This function may block indefinitely. Use the asynchronous version in user interface threads.

      Parameters:
      schema - the schema for the attributes
      attributes - a new set of attributes
      cancellable - optional cancellation object
      Returns:
      whether the change was successful or not
      Throws:
      GErrorException - see GError
    • setLabel

      public void setLabel(String label, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Set the label of this item.

      This function returns immediately and completes asynchronously.

      Parameters:
      label - a new label
      cancellable - optional cancellation object
      callback - called when the operation completes
    • setLabelFinish

      public boolean setLabelFinish(AsyncResult result) throws GErrorException
      Complete asynchronous operation to set the label of this collection.
      Parameters:
      result - asynchronous result passed to callback
      Returns:
      whether the change was successful or not
      Throws:
      GErrorException - see GError
    • setLabelSync

      public boolean setLabelSync(String label, @Nullable Cancellable cancellable) throws GErrorException

      Set the label of this item.

      This function may block indefinitely. Use the asynchronous version in user interface threads.

      Parameters:
      label - a new label
      cancellable - optional cancellation object
      Returns:
      whether the change was successful or not
      Throws:
      GErrorException - see GError
    • setSecret

      public void setSecret(Value value, @Nullable Cancellable cancellable, @Nullable AsyncReadyCallback callback)

      Set the secret value of this item.

      Each item has a single secret which might be a password or some other secret binary value.

      This function returns immediately and completes asynchronously.

      Parameters:
      value - a new secret value
      cancellable - optional cancellation object
      callback - called when the operation completes
    • setSecretFinish

      public boolean setSecretFinish(AsyncResult result) throws GErrorException
      Complete asynchronous operation to set the secret value of this item.
      Parameters:
      result - asynchronous result passed to callback
      Returns:
      whether the change was successful or not
      Throws:
      GErrorException - see GError
    • setSecretSync

      public boolean setSecretSync(Value value, @Nullable Cancellable cancellable) throws GErrorException

      Set the secret value of this item.

      Each item has a single secret which might be a password or some other secret binary value.

      This function may block indefinitely. Use the asynchronous version in user interface threads.

      Parameters:
      value - a new secret value
      cancellable - optional cancellation object
      Returns:
      whether the change was successful or not
      Throws:
      GErrorException - see GError
    • builder

      public static Item.Builder<? extends Item.Builder> builder()
      A Item.Builder object constructs a Item with the specified properties. Use the various set...() methods to set properties, and finish construction with Item.Builder.build().
      Returns:
      the builder object