Top Fields Constructors Methods
org.freedesktop.secret.simple

public final Class SimpleCollection

extends SimpleCollection
Class Inheritance
Imports
org.freedesktop.dbus.DBusPath, .ObjectPath, org.freedesktop.dbus.connections.impl.DBusConnection, .DBusConnectionBuilder, org.freedesktop.dbus.exceptions.DBusException, org.freedesktop.dbus.interfaces.DBus, org.freedesktop.dbus.types.Variant, org.freedesktop.secret.*, org.freedesktop.secret.interfaces.Prompt.Completed, org.gnome.keyring.InternalUnsupportedGuiltRiddenInterface, org.slf4j.Logger, .LoggerFactory, javax.crypto.BadPaddingException, .IllegalBlockSizeException, .NoSuchPaddingException, java.io.IOException, java.security.AccessControlException, .InvalidAlgorithmParameterException, .InvalidKeyException, .NoSuchAlgorithmException, java.security.spec.InvalidKeySpecException, java.time.Duration, java.util.Arrays, .HashMap, .List, .Map, java.util.concurrent.RejectedExecutionException

Field Summary

Modifier and TypeField and Description
private Collection
private static DBusConnection
private Secret
private Boolean
private static final Logger
private Prompt
private Service
private Session
private static Thread
private Duration
private TransportEncryption
private InternalUnsupportedGuiltRiddenInterface

Constructor Summary

AccessConstructor and Description
public
SimpleCollection()

The default collection.

public
SimpleCollection(String
The displayable label of the collection

Note

The label of a collection may differ from the id of a collection. The id is 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 id is inferred by the given label.

label
,
CharSequence
Password of the collection
password
)

A user specified collection.

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.clear.

Clears the private key of the transport encryption and the passphrase of the collection.

public void
close()

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.close.

Implements java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources.

public String

Returns:

DBus object path or null
createItem
(String
The displayable label of the new item
label
,
CharSequence
The password of the new item
password
,
Map<String, String>
The attributes of the new item
attributes
)

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.createItem.

Creates an item with the provided properties in this collection.

public String

Returns:

DBus object path
createItem
(String
The displayable label of the new item
label
,
CharSequence
The password of the new item
password
)

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.createItem.

Creates an item with the provided properties in this collection.

public void
delete()

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.delete.

Delete this collection.

public void
deleteItem(String
The DBus object path of the item
objectPath
)

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.deleteItem.

Delete an item from this collection.

public void
deleteItems(List<String>
The DBus object paths of the items
objectPaths
)

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.deleteItems.

Delete specified items from this collection.

public static synchronized boolean
private boolean
exists(String label)

public Map<String, String>

Returns:

item attributes or null
getAttributes
(String
The DBus object path of the item
objectPath
)

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.getAttributes.

Get the user specified attributes of an item.

private ObjectPath
getCollectionPath(String label)
References Deprecated ObjectPath is deprecated or references (maybe indirectly) at least one deprecated element.

private static DBusConnection

Returns:

a new DBusConnection or null
getConnection
()

Try to get a new DBus connection.

private Item
public List<String>

Returns:

object paths or null
getItems
(Map<String, String>
The attributes of the secret
attributes
)

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.getItems.

Get the object paths of items with given attributes.

public String

Returns:

label or null
getLabel
(String
The DBus object path of the item
objectPath
)

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.getLabel.

Get the displayable label of an item.

private Map<ObjectPath, String>
public char[]

Returns:

plain chars or null
getSecret
(String
The DBus object path of the item
objectPath
)

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.getSecret.

Get the secret of the item.

public Map<String, char[]>

Returns:

Mapping of DBus object paths and plain chars or null
getSecrets
()

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.getSecrets.

Get the secrets from this collection.

public Duration
private void
init()

public static boolean

Returns:

true if the secret service is available, otherwise false and will log an error message.
isAvailable
()

Hides org.freedesktop.secret.simple.interfaces.SimpleCollection.isAvailable.

Checks if all services are provided by the system: org.freedesktop.DBus org.freedesktop.secrets org.gnome.keyring

public static boolean

Returns:

true if connected to the D-Bus, otherwise false
isConnected
()

Hides org.freedesktop.secret.simple.interfaces.SimpleCollection.isConnected.

Checks the D-Bus connection status.

private boolean
public static boolean

Returns:

true if the secret service provider is gnome keyring, otherwise false and will log a warning message.
isGnomeKeyringAvailable
()

Checks if private/unsupported services are provided by the system: org.gnome.keyring

public boolean
public void
private List<ObjectPath>
private void
performPrompt(ObjectPath path)
References Deprecated ObjectPath is deprecated or references (maybe indirectly) at least one deprecated element.

public void
private static Thread
setupShutdownHook()

Sets up a shutdown hook to close the global D-Bus connection eventually at the end of the static lifetime.

private void
public void
unlockWithUserPermission()

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.unlockWithUserPermission.

Locks and unlocks the default collection explicitly.

public void
updateItem(String
The DBus object path of the item
objectPath
,
String
The displayable label of the new item
label
,
CharSequence
The password of the new item
password
,
Map<String, String>
The attributes of the new item
attributes
)

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.updateItem.

Updates an item with the provided properties.

Field Detail

collectionback to summary
private Collection collection
connectionback to summary
private static DBusConnection connection
encryptedback to summary
private Secret encrypted
isUnlockedOnceWithUserPermissionback to summary
private Boolean isUnlockedOnceWithUserPermission
logback to summary
private static final Logger log

Hides org.freedesktop.secret.simple.interfaces.SimpleCollection.log.

promptback to summary
private Prompt prompt
serviceback to summary
private Service service
sessionback to summary
private Session session
shutdownHookback to summary
private static Thread shutdownHook
timeoutback to summary
private Duration timeout
transportback to summary
private TransportEncryption transport
withoutPromptback to summary
private InternalUnsupportedGuiltRiddenInterface withoutPrompt

Constructor Detail

SimpleCollectionback to summary
public SimpleCollection() throws IOException

The default collection.

Exceptions
IOException:
Could not communicate properly with the DBus. Check the logs.
SimpleCollectionback to summary
public SimpleCollection(String label, CharSequence password) throws IOException

A user specified collection.

Parameters
label:String

The displayable label of the collection

Note

The label of a collection may differ from the id of a collection. The id is 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 id is inferred by the given label.

password:CharSequence

Password of the collection

Exceptions
IOException:
Could not communicate properly with the DBus. Check the logs.

Method Detail

clearback to summary
public void clear()

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.clear.

Clears the private key of the transport encryption and the passphrase of the collection.

Annotations
@Override
closeback to summary
public void close()

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.close.

Implements java.lang.AutoCloseable.close.

Doc from java.lang.AutoCloseable.close.

Closes this resource, relinquishing any underlying resources. This method is invoked automatically on objects managed by the try-with-resources statement.

Annotations
@Override
createItemback to summary
public String createItem(String label, CharSequence password, Map<String, String> attributes) throws IllegalArgumentException

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.createItem.

Creates an item with the provided properties in this collection.

Parameters
label:String

The displayable label of the new item

password:CharSequence

The password of the new item

attributes:Map<String, String>

The attributes of the new item

Returns:String

DBus object path or null

Annotations
@Override
Exceptions
IllegalArgumentException:
The label and password are non-nullable.
createItemback to summary
public String createItem(String label, CharSequence password) throws IllegalArgumentException

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.createItem.

Creates an item with the provided properties in this collection.

Parameters
label:String

The displayable label of the new item

password:CharSequence

The password of the new item

Returns:String

DBus object path

Annotations
@Override
Exceptions
IllegalArgumentException:
The label and password are non-nullable.
deleteback to summary
public void delete() throws AccessControlException

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.delete.

Delete this collection.

Annotations
@Override
deleteItemback to summary
public void deleteItem(String objectPath) throws AccessControlException

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.deleteItem.

Delete an item from this collection.

Deleting a password form the default collection requires user permission.

see: SimpleCollection#unlockWithUserPermission()

Parameters
objectPath:String

The DBus object path of the item

Annotations
@Override
deleteItemsback to summary
public void deleteItems(List<String> objectPaths) throws AccessControlException

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.deleteItems.

Delete specified items from this collection.

Deleting passwords form the default collection requires user permission.

see: SimpleCollection#unlockWithUserPermission()

Parameters
objectPaths:List<String>

The DBus object paths of the items

Annotations
@Override
disconnectback to summary
public static synchronized boolean disconnect()

Hides org.freedesktop.secret.simple.interfaces.SimpleCollection.disconnect.

Close the DBus connection immediately. Waits for the DBus connection to close within 2 seconds.

existsback to summary
private boolean exists(String label)
getAttributesback to summary
public Map<String, String> getAttributes(String objectPath)

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.getAttributes.

Get the user specified attributes of an item.

The attributes can contain an additional xdg:schema key-value pair.

Parameters
objectPath:String

The DBus object path of the item

Returns:Map<String, String>

item attributes or null

Annotations
@Override
getCollectionPathback to summary
private ObjectPath getCollectionPath(String label)

References Deprecated

ObjectPath is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

getConnectionback to summary
private static DBusConnection getConnection()

Try to get a new DBus connection.

Returns:DBusConnection

a new DBusConnection or null

getItemback to summary
private Item getItem(String path)
getItemsback to summary
public List<String> getItems(Map<String, String> attributes)

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.getItems.

Get the object paths of items with given attributes.

Parameters
attributes:Map<String, String>

The attributes of the secret

Returns:List<String>

object paths or null

Annotations
@Override
getLabelback to summary
public String getLabel(String objectPath)

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.getLabel.

Get the displayable label of an item.

Parameters
objectPath:String

The DBus object path of the item

Returns:String

label or null

Annotations
@Override
getLabelsback to summary
private Map<ObjectPath, String> getLabels()
getSecretback to summary
public char[] getSecret(String objectPath)

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.getSecret.

Get the secret of the item.

Parameters
objectPath:String

The DBus object path of the item

Returns:char[]

plain chars or null

Annotations
@Override
getSecretsback to summary
public Map<String, char[]> getSecrets() throws AccessControlException

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.getSecrets.

Get the secrets from this collection.

Retrieving all passwords form the default collection requires user permission.

see: SimpleCollection#unlockWithUserPermission()

Returns:Map<String, char[]>

Mapping of DBus object paths and plain chars or null

Annotations
@Override
getTimeoutback to summary
public Duration getTimeout()

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.getTimeout.

Annotations
@Override
initback to summary
private void init() throws IOException
isAvailableback to summary
public static boolean isAvailable()

Hides org.freedesktop.secret.simple.interfaces.SimpleCollection.isAvailable.

Checks if all services are provided by the system:
org.freedesktop.DBus
org.freedesktop.secrets
org.gnome.keyring

Returns:boolean

true if the secret service is available, otherwise false and will log an error message.

isConnectedback to summary
public static boolean isConnected()

Hides org.freedesktop.secret.simple.interfaces.SimpleCollection.isConnected.

Checks the D-Bus connection status.

Returns:boolean

true if connected to the D-Bus, otherwise false

isDefaultback to summary
private boolean isDefault()
isGnomeKeyringAvailableback to summary
public static boolean isGnomeKeyringAvailable()

Checks if private/unsupported services are provided by the system:
org.gnome.keyring

Returns:boolean

true if the secret service provider is gnome keyring, otherwise false and will log a warning message.

isLockedback to summary
public boolean isLocked()

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.isLocked.

Annotations
@Override
lockback to summary
public void lock()

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.lock.

Annotations
@Override
lockableback to summary
private List<ObjectPath> lockable()
performPromptback to summary
private void performPrompt(ObjectPath path)

References Deprecated

ObjectPath is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

setTimeoutback to summary
public void setTimeout(Duration timeout)

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.setTimeout.

Annotations
@Override
setupShutdownHookback to summary
private static Thread setupShutdownHook()

Sets up a shutdown hook to close the global D-Bus connection eventually at the end of the static lifetime.

unlockback to summary
private void unlock()
unlockWithUserPermissionback to summary
public void unlockWithUserPermission() throws AccessControlException

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.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:

SimpleCollection#getSecrets()

SimpleCollection#deleteItem(String)

SimpleCollection#deleteItems(List)

Annotations
@Override
Exceptions
AccessControlException:
if the user does not provide the correct credentials.
updateItemback to summary
public void updateItem(String objectPath, String label, CharSequence password, Map<String, String> attributes) throws IllegalArgumentException

Implements abstract org.freedesktop.secret.simple.interfaces.SimpleCollection.updateItem.

Updates an item with the provided properties.

Parameters
objectPath:String

The DBus object path of the item

label:String

The displayable label of the new item

password:CharSequence

The password of the new item

attributes:Map<String, String>

The attributes of the new item

Annotations
@Override
Exceptions
IllegalArgumentException:
The object path, label and password are non-nullable.