Class SimpleCollection
- All Implemented Interfaces:
AutoCloseable
public final class SimpleCollection extends Object implements AutoCloseable
-
Constructor Summary
Constructors Constructor Description SimpleCollection()The default collection.SimpleCollection(String label, CharSequence password)A user specified collection. -
Method Summary
Modifier and Type Method Description voidclear()Clears the private key of the transport encryption and the passphrase of the collection.voidclose()StringcreateItem(String label, CharSequence password)Creates an item with the provided properties in this collection.StringcreateItem(String label, CharSequence password, Map<String,String> attributes)Creates an item with the provided properties in this collection.voiddelete()Delete this collection.voiddeleteItem(String objectPath)Delete an item from this collection.voiddeleteItems(List<String> objectPaths)Delete specified items from this collection.Map<String,String>getAttributes(String objectPath)Get the user specified attributes of an item.List<String>getItems(Map<String,String> attributes)Get the object paths of items with given attributes.StringgetLabel(String objectPath)Get the displayable label of an item.char[]getSecret(String objectPath)Get the secret of the item.Map<String,char[]>getSecrets()Get the secrets from this collection.DurationgetTimeout()static booleanisAvailable()Checks if `org.freedesktop.secrets` is provided as D-Bus service.voidlock()voidsetTimeout(Duration timeout)voidunlockWithUserPermission()Locks and unlocks the default collection explicitly.voidupdateItem(String objectPath, String label, CharSequence password, Map<String,String> attributes)Updates an item with the provided properties.
-
Constructor Details
-
SimpleCollection
The default collection.- Throws:
IOException- Could not communicate properly with the D-Bus. Check the logs.
-
SimpleCollection
A user specified collection.- Parameters:
label- The displayable label of the collectionNOTE: The
labelof a collection may differ from theidof a collection. Theidis assigned by the Secret Service and used in the DBus object path of a collection or item.The SimpleCollection can't handle collections with the same label, but different ids correctly, as the
idis inferred by the given label.password- Password of the collection- Throws:
IOException- Could not communicate properly with the D-Bus. Check the logs.
-
-
Method Details
-
isAvailable
public static boolean isAvailable()Checks if `org.freedesktop.secrets` is provided as D-Bus service.- Returns:
- true if the secret service is available, otherwise false and will log an error message.
-
lock
public void lock() -
unlockWithUserPermission
Locks and unlocks the default collection explicitly.The default collection gets only locked on the first call of a session.
Once the default collection is unlocked the user will not be prompted again as long as the default collection stays unlocked.
This method is used to enforce user interaction for:
- Throws:
AccessControlException- if the user does not provide the correct credentials.
-
clear
public void clear()Clears the private key of the transport encryption and the passphrase of the collection. -
close
public void close()- Specified by:
closein interfaceAutoCloseable
-
delete
Delete this collection.- Throws:
AccessControlException
-
createItem
public String createItem(String label, CharSequence password, Map<String,String> attributes) throws IllegalArgumentExceptionCreates an item with the provided properties in this collection.- Parameters:
label- The displayable label of the new itempassword- The password of the new itemattributes- The attributes of the new item- Returns:
- DBus object path or null
- Throws:
IllegalArgumentException- The label and password are non nullable.
-
createItem
Creates an item with the provided properties in this collection.- Parameters:
label- The displayable label of the new itempassword- The password of the new item- Returns:
- DBus object path
- Throws:
IllegalArgumentException- The label and password are non nullable.
-
updateItem
public void updateItem(String objectPath, String label, CharSequence password, Map<String,String> attributes) throws IllegalArgumentExceptionUpdates an item with the provided properties.- Parameters:
objectPath- The DBus object path of the itemlabel- The displayable label of the new itempassword- The password of the new itemattributes- The attributes of the new item- Throws:
IllegalArgumentException- The object path, label and password are non nullable.
-
getLabel
Get the displayable label of an item.- Parameters:
objectPath- The DBus object path of the item- Returns:
- label
-
getAttributes
Get the user specified attributes of an item.The attributes can contain an additional
xdg:schemakey-value pair.- Parameters:
objectPath- The DBus object path of the item- Returns:
- item attributes
-
getItems
Get the object paths of items with given attributes.- Parameters:
attributes- The attributes of the secret- Returns:
- object paths
-
getSecret
Get the secret of the item.- Parameters:
objectPath- The DBus object path of the item- Returns:
- plain chars
-
getSecrets
Get the secrets from this collection.Retrieving all passwords form the default collection requires user permission.
- Returns:
- Mapping of DBus object paths and plain chars
- Throws:
AccessControlException
-
deleteItem
Delete an item from this collection.Deleting a password form the default collection requires user permission.
- Parameters:
objectPath- The DBus object path of the item- Throws:
AccessControlException
-
deleteItems
Delete specified items from this collection.Deleting passwords form the default collection requires user permission.
- Parameters:
objectPaths- The DBus object paths of the items- Throws:
AccessControlException
-
getTimeout
-
setTimeout
-