Skip to content

Commit ab0a132

Browse files
committed
Implement a first set of DBus interfaces
1 parent 7d98000 commit ab0a132

7 files changed

Lines changed: 375 additions & 12 deletions

File tree

src/main/java/module-info.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
module org.purejava.secretservice {
1+
module org.purejava.secret {
22
requires java.desktop;
33
requires org.freedesktop.dbus;
44
requires org.slf4j;
55

6-
exports org.purejava.secretservice;
7-
exports org.purejava.secretservice.freedesktop.dbus.handlers;
6+
exports org.purejava.secret;
7+
exports org.purejava.secret.freedesktop.dbus.handlers;
8+
exports org.purejava.secret.interfaces;
89
}

src/main/java/org/purejava/secretservice/freedesktop/dbus/handlers/MessageHandler.java renamed to src/main/java/org/purejava/secret/freedesktop/dbus/handlers/MessageHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.purejava.secretservice.freedesktop.dbus.handlers;
1+
package org.purejava.secret.freedesktop.dbus.handlers;
22

33
import org.freedesktop.dbus.connections.impl.DBusConnection;
44
import org.freedesktop.dbus.exceptions.DBusException;

src/main/java/org/purejava/secretservice/freedesktop/dbus/handlers/Messaging.java renamed to src/main/java/org/purejava/secret/freedesktop/dbus/handlers/Messaging.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
package org.purejava.secretservice.freedesktop.dbus.handlers;
1+
package org.purejava.secret.freedesktop.dbus.handlers;
22

33
import org.freedesktop.dbus.DBusPath;
44
import org.freedesktop.dbus.connections.impl.DBusConnection;
55
import org.freedesktop.dbus.types.Variant;
6-
import org.slf4j.Logger;
7-
import org.slf4j.LoggerFactory;
86

97
abstract public class Messaging {
108

11-
private static final Logger LOG = LoggerFactory.getLogger(Messaging.class);
129
private final DBusConnection connection;
1310
private final MessageHandler msg;
1411
private final String serviceName;
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
package org.purejava.secret.interfaces;
2+
3+
import org.freedesktop.dbus.DBusPath;
4+
import org.freedesktop.dbus.annotations.DBusInterfaceName;
5+
import org.freedesktop.dbus.exceptions.DBusException;
6+
import org.freedesktop.dbus.interfaces.DBusInterface;
7+
import org.freedesktop.dbus.messages.DBusSignal;
8+
import org.freedesktop.dbus.types.UInt64;
9+
import org.freedesktop.dbus.types.Variant;
10+
11+
import java.util.List;
12+
import java.util.Map;
13+
14+
@DBusInterfaceName("org.freedesktop.Secret.Collection")
15+
public interface Collection extends DBusInterface {
16+
17+
class ItemCreated extends DBusSignal {
18+
public final DBusPath item;
19+
20+
/**
21+
* A new item in this collection was created.
22+
*
23+
* @param path The path to the object this is emitted from.
24+
* @param item The item that was created.
25+
* @throws DBusException Could not communicate properly with the D-Bus.
26+
*/
27+
public ItemCreated(String path, DBusPath item) throws DBusException {
28+
super(path, item);
29+
this.item = item;
30+
}
31+
}
32+
33+
class ItemDeleted extends DBusSignal {
34+
public final DBusPath item;
35+
36+
/**
37+
* An item in this collection was deleted.
38+
*
39+
* @param path The path to the object this is emitted from.
40+
* @param item The item that was deleted.
41+
* @throws DBusException Could not communicate properly with the D-Bus.
42+
*/
43+
public ItemDeleted(String path, DBusPath item) throws DBusException {
44+
super(path, item);
45+
this.item = item;
46+
}
47+
}
48+
49+
class ItemChanged extends DBusSignal {
50+
public final DBusPath item;
51+
52+
/**
53+
* An item in this collection changed.
54+
*
55+
* @param path The path to the object this is emitted from.
56+
* @param item The item that was changed.
57+
* @throws DBusException Could not communicate properly with the D-Bus.
58+
*/
59+
public ItemChanged(String path, DBusPath item) throws DBusException {
60+
super(path, item);
61+
this.item = item;
62+
}
63+
}
64+
65+
/**
66+
* Delete this collection.
67+
*
68+
* @return prompt — A prompt to delete the collection, or the special value '/' when no prompt is necessary.
69+
* @see DBusPath
70+
*/
71+
DBusPath delete();
72+
73+
/**
74+
* Search for items in this collection matching the lookup attributes.
75+
*
76+
* @param attributes Attributes to match.
77+
* @return results — Items that matched the attributes.
78+
* @see DBusPath
79+
*/
80+
List<DBusPath> searchItems(Map<String, String> attributes);
81+
82+
/**
83+
* Create an item with the given attributes, secret and label. If replace is set, then it replaces an item already
84+
* present with the same values for the attributes.
85+
*
86+
* @param properties The properties for the new item.
87+
*
88+
* <p>This allows setting the new item's properties upon its creation. All READWRITE properties
89+
* are useable. Specify the property names in full <code>interface.Property</code> form.</p>
90+
*
91+
* <p>
92+
* <b>Example 13.2. Example for properties of an item:</b><br>
93+
* <code>
94+
* properties = {<br>
95+
* &nbsp;&nbsp;"org.freedesktop.Secret.Item.Label": "MyItem",<br>
96+
* &nbsp;&nbsp;"org.freedesktop.Secret.Item.Attributes": {<br>
97+
* &nbsp;&nbsp;&nbsp;&nbsp;"Attribute1": "Value1",<br>
98+
* &nbsp;&nbsp;&nbsp;&nbsp;"Attribute2": "Value2"<br>
99+
* &nbsp;&nbsp;}<br>
100+
* }<br>
101+
* </code></p>
102+
*
103+
* <p>
104+
* <b>Note:</b>
105+
* Please note that there is a distinction between the terms <i>Property</i>, which refers
106+
* to D-Bus properties of an object, and <i>Attribute</i>, which refers to one of a
107+
* secret item's string-valued attributes.
108+
* </p>
109+
*
110+
* @param secret The secret to store in the item, encoded with the included session.
111+
* @param replace Whether to replace an item with the same attributes or not.
112+
* @return Pair&lt;item, prompt&gt;<br>
113+
* <br>
114+
* item &mdash; The item created, or the special value '/' if a prompt is necessary.<br>
115+
* <br>
116+
* prompt &mdash; A prompt object, or the special value '/' if no prompt is necessary.<br>
117+
* @see DBusPath
118+
*/
119+
Pair<DBusPath, DBusPath> createItem(Map<String, Variant<?>> properties, Secret secret, boolean replace);
120+
121+
/**
122+
* <p>It is accessed using the <code>org.freedesktop.DBus.Properties</code> interface.</p>
123+
* @return Items in this collection.
124+
*/
125+
List<DBusPath> items();
126+
127+
/**
128+
* <p>It is accessed using the <code>org.freedesktop.DBus.Properties</code> interface.</p>
129+
* @return The displayable label of this collection.
130+
*/
131+
String label();
132+
133+
/**
134+
* <p>It is accessed using the <code>org.freedesktop.DBus.Properties</code> interface.</p>
135+
* @return Whether the collection is locked and must be authenticated by the client application.
136+
*/
137+
boolean locked();
138+
139+
/**
140+
* <p>It is accessed using the <code>org.freedesktop.DBus.Properties</code> interface.</p>
141+
* @return The unix time when the collection was created.
142+
*/
143+
UInt64 created();
144+
145+
/**
146+
* <p>It is accessed using the <code>org.freedesktop.DBus.Properties</code> interface.</p>
147+
* @return The unix time when the collection was last modified.
148+
*/
149+
UInt64 modified();
150+
151+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.purejava.secret.interfaces;
2+
3+
import org.freedesktop.dbus.Tuple;
4+
import org.freedesktop.dbus.annotations.Position;
5+
6+
/**
7+
* Just a typed container class
8+
*/
9+
public final class Pair<A, B> extends Tuple {
10+
@Position(0)
11+
public final A a;
12+
@Position(1)
13+
public final B b;
14+
15+
public Pair(A a, B b) {
16+
this.a = a;
17+
this.b = b;
18+
}
19+
}

0 commit comments

Comments
 (0)