de.swiesend.secretservice.Service Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of secret-service Show documentation
Show all versions of secret-service Show documentation
A Java library for storing secrets in the gnome-keyring over the DBus.
Simply set and get passwords in a gnome linux system.
The newest version!
package de.swiesend.secretservice;
import org.freedesktop.dbus.ObjectPath;
import org.freedesktop.dbus.connections.impl.DBusConnection;
import org.freedesktop.dbus.messages.DBusSignal;
import org.freedesktop.dbus.types.Variant;
import de.swiesend.secretservice.handlers.Messaging;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class Service extends Messaging implements de.swiesend.secretservice.interfaces.Service {
public static final List> signals = Arrays.asList(
CollectionCreated.class, CollectionChanged.class, CollectionDeleted.class);
private Session session = null;
public Service(DBusConnection connection) {
super(connection, signals,
Static.Service.SECRETS,
Static.ObjectPaths.SECRETS,
Static.Interfaces.SERVICE);
}
@Override
public Pair, ObjectPath> openSession(String algorithm, Variant input) {
Object[] params = send("OpenSession", "sv", algorithm, input);
if (params == null) return null;
session = new Session((ObjectPath) params[1], this);
return new Pair(params[0], params[1]);
}
@Override
public Pair createCollection(Map properties, String alias) {
String a;
if (alias == null) {
a = "";
} else {
a = alias;
}
Object[] params = send("CreateCollection", "a{sv}s", properties, a);
if (params == null) return null;
return new Pair(params[0], params[1]);
}
@Override
public Pair createCollection(Map properties) {
return createCollection(properties, "");
}
@Override
public Pair, List> searchItems(Map attributes) {
Object[] params = send("SearchItems", "a{ss}", attributes);
if (params == null) return null;
return new Pair(params[0], params[1]);
}
@Override
public Pair, ObjectPath> unlock(List objects) {
Object[] params = send("Unlock", "ao", objects);
if (params == null) return null;
return new Pair(params[0], params[1]);
}
@Override
public Pair, ObjectPath> lock(List objects) {
Object[] params = send("Lock", "ao", objects);
if (params == null) return null;
return new Pair(params[0], params[1]);
}
@Override
public void lockService() {
send("LockService", "");
}
@Override
public ObjectPath changeLock(ObjectPath collection) {
Object[] params = send("ChangeLock", "o", collection);
if (params == null) return null;
return (ObjectPath) params[0];
}
@Override
public Map getSecrets(List items, ObjectPath session) {
Object[] params = send("GetSecrets", "aoo", items, session);
if (params == null) return null;
return (Map) params[0];
}
@Override
public ObjectPath readAlias(String name) {
Object[] params = send("ReadAlias", "s", name);
if (params == null) return null;
return (ObjectPath) params[0];
}
@Override
public void setAlias(String name, ObjectPath collection) {
send("SetAlias", "so", name, collection);
}
@Override
public List getCollections() {
Variant response = getProperty("Collections");
if (response == null) return null;
return (ArrayList) response.getValue();
}
@Override
public boolean isRemote() {
return false;
}
@Override
public String getObjectPath() {
return Static.ObjectPaths.SECRETS;
}
public Session getSession() {
return session;
}
}