@@ -60,8 +60,10 @@ public KeepassProxyAccess() {
6060 }
6161
6262 /**
63- * Loads the @see org.purejava.Credentials from disc, if available, to setup this library
63+ * Loads the {@link org.purejava.Credentials Credentials} from disc, if available, to setup this library
6464 * so that it can be used to send requests to and receive requests from a KeePassXC database.
65+ * @see org.purejava.Credentials
66+ *
6567 * @return An Optional of the Credentials read from disc in case they are available, an empty Optional otherwise.
6668 */
6769 private Optional <Credentials > loadCredentials () {
@@ -77,8 +79,10 @@ private Optional<Credentials> loadCredentials() {
7779
7880
7981 /**
80- * Saves @see org.purejava.Credentials in a delayed background thread to disc, as this is a time consuming
82+ * Saves {@link org.purejava.Credentials Credentials} in a delayed background thread to disc, as this is a time consuming
8183 * operation that might fail.
84+ * @see org.purejava.Credentials
85+ *
8286 * @param credentials An Optional of the Credentials to be saved.
8387 */
8488 private void scheduleSave (Optional <Credentials > credentials ) {
@@ -95,7 +99,9 @@ private void scheduleSave(Optional<Credentials> credentials) {
9599 }
96100
97101 /**
98- * Saves @see org.purejava.Credentials to disc.
102+ * Saves {@link org.purejava.Credentials Credentials} to disc.
103+ * @see org.purejava.Credentials
104+ *
99105 * @param credentials An Optional of the Credentials to be saved.
100106 */
101107 private void saveCredentials (Optional <Credentials > credentials ) {
@@ -118,15 +124,24 @@ private void saveCredentials(Optional<Credentials> credentials) {
118124 }
119125
120126 /**
121- * Convenience method to get the connection parameters that are required to identify the right KeePassXC database.
127+ * Convenience method to get the connection parameters that are required to identify the KeePassXC database.
122128 *
123- * @return The entered associateID and returned IDKeyPublicKey.
129+ * @return The entered associateID and returned IDKeyPublicKey stored on association .
124130 */
125131 public Map <String , String > exportConnection () {
126132 return Map .of ("id" , connection .getAssociateId (),
127133 "key" , connection .getIdKeyPairPublicKey ());
128134 }
129135
136+ /**
137+ * Establish a connection to the KeePassXC proxy. This is required for every session.
138+ * The closing of the connection is handled automatically.
139+ * @see org.keepassxc.LinuxMacConnection
140+ * @see org.keepassxc.WindowsConnection
141+ *
142+ * @return True, if connecting to the proxy was successful, false, if connecting failed due to technical reasons
143+ * or the proxy wasn't started.
144+ */
130145 public boolean connect () {
131146 try {
132147 connection .connect ();
@@ -136,6 +151,12 @@ public boolean connect() {
136151 }
137152 }
138153
154+ /**
155+ * Connects KeePassXC with a new client. This is required once, on connecting a new client to KeePassXC and
156+ * creates the public idKey and the public associateId.
157+ *
158+ * @return True, if it was possible to associate KeePassXC with a new client, false otherwise.
159+ */
139160 public boolean associate () {
140161 try {
141162 connection .associate ();
@@ -146,6 +167,15 @@ public boolean associate() {
146167 }
147168 }
148169
170+ /**
171+ * Checks, if this client has been associated with KeePassXC and if the association is still valid. To establish
172+ * a connection to KeePassXC, the public idKey and the public associateId are required. With these parameters,
173+ * {@link org.purejava.KeepassProxyAccess#testAssociate(String, String) testAssociate} is called to verify the
174+ * association. A valid association enables the client to send requests to and receive requests from KeePassXC.
175+ * @see org.purejava.KeepassProxyAccess#testAssociate(String, String)
176+ *
177+ * @return True, if a valid association with KeePassXC exists, false otherwise.
178+ */
149179 public boolean connectionAvailable () {
150180 return getIdKeyPairPublicKey () != null &&
151181 !getIdKeyPairPublicKey ().isEmpty () &&
@@ -154,6 +184,14 @@ public boolean connectionAvailable() {
154184 testAssociate (getAssociateId (), getIdKeyPairPublicKey ());
155185 }
156186
187+ /**
188+ * Request for testing if the public idKey and the public associateId are valid and enable this client
189+ * to talk to KeePassXC. With valid IDs, the client is considered associated with KeePassXC.
190+ *
191+ * @param id The identifier of the KeePassXC database connection to be tested.
192+ * @param key The public key of the idKeyPair to be tested.
193+ * @return True, if the id and the key are valid, false otherwise.
194+ */
157195 public boolean testAssociate (String id , String key ) {
158196 try {
159197 connection .testAssociate (id , key );
@@ -164,6 +202,14 @@ public boolean testAssociate(String id, String key) {
164202 }
165203 }
166204
205+ /**
206+ * Request for receiving the database hash (SHA256) of the current active KeePassXC database.
207+ * The request can be send in conjunction with an optional request to unlock the KeePassXC database.
208+ *
209+ * @param unlock When true, the KeePassXC application is brought to the front and unlock is requested from the user.
210+ * @return The database hash of the current active KeePassXC database in case the hash could be retrieved,
211+ * an empty String otherwise.
212+ */
167213 public String getDatabasehash (boolean ... unlock ) {
168214 try {
169215 if (unlock .length > 1 ) {
@@ -180,6 +226,16 @@ public String getDatabasehash(boolean... unlock) {
180226 }
181227 }
182228
229+ /**
230+ * Request credentials from KeePassXC databases for a given URL.
231+ *
232+ * @param url The URL credentials are looked up for.
233+ * @param submitUrl URL that can be passed along amd gets added to entry properties.
234+ * @param httpAuth Include database entries into search that are restricted to HTTP Basic Auth.
235+ * @param list Id / key combinations identifying and granting access to KeePassXC databases.
236+ * @return A Map that contains all found credentials together with additional information, in case credentials
237+ * were found, an empty Map otherwise.
238+ */
183239 public Map <String , Object > getLogins (String url , String submitUrl , boolean httpAuth , List <Map <String , String >> list ) {
184240 try {
185241 return connection .getLogins (url , submitUrl , httpAuth , list ).toMap ();
@@ -189,6 +245,19 @@ public Map<String, Object> getLogins(String url, String submitUrl, boolean httpA
189245 }
190246 }
191247
248+ /**
249+ * Checks, if a password is stored in the KeePassXC databases. This method calls
250+ * {@link org.purejava.KeepassProxyAccess#getLogins(String, String, boolean, List) getLogins} to search
251+ * the KeePassXC databases.
252+ * @see org.purejava.KeepassProxyAccess#getLogins(String, String, boolean, List)
253+ *
254+ * @param url The URL credentials are looked up for.
255+ * @param submitUrl URL that can be passed along amd gets added to entry properties.
256+ * @param httpAuth Include database entries into search that are restricted to HTTP Basic Auth.
257+ * @param list Id / key combinations identifying and granting access to KeePassXC databases.
258+ * @param password Password to check.
259+ * @return True, if the password was found in a KeePassXC database, false otherwise.
260+ */
192261 public boolean loginExists (String url , String submitUrl , boolean httpAuth , List <Map <String , String >> list , String password ) {
193262 var response = getLogins (url , submitUrl , httpAuth , list );
194263 if (response .isEmpty ()) {
@@ -202,6 +271,23 @@ public boolean loginExists(String url, String submitUrl, boolean httpAuth, List<
202271 return false ;
203272 }
204273
274+ /**
275+ * Request to store a new entry or update an existing entry in the current KeePassXC database.
276+ *
277+ * @param url The URL to be saved. The title of the new entry is the hostname of the URL.
278+ * @param submitUrl URL that can be passed along amd gets added to entry properties.
279+ * @param id An identifier for the KeePassXC database connection - ignored at the moment.
280+ * @param login The username to be saved.
281+ * @param password The password to be saved.
282+ * @param group The group name to be used for new entries. Must contain something to use an existing group, but
283+ * the content is ignored, as a group is identified by the groupUuid. In case there is no group with
284+ * the given groupUuid, the standard group is used to store the entry.
285+ * @param groupUuid Identifier to decide, where to store the entry. For an existing group, the groupUuid must be
286+ * given, otherwise the standard group is used to store the entry.
287+ * @param uuid Identifier whether an existing entry is updated or a new one is created. To update an existing entry,
288+ * its current uuid is required. If empty, a new entry is stored in the given groupUuid.
289+ * @return True, if the entry could be stored/updated, false otherwise.
290+ */
205291 public boolean setLogin (String url , String submitUrl , String id , String login , String password , String group , String groupUuid , String uuid ) {
206292 try {
207293 var response = connection .setLogin (url , submitUrl , id , login , password , group , groupUuid , uuid );
@@ -212,6 +298,11 @@ public boolean setLogin(String url, String submitUrl, String id, String login, S
212298 }
213299 }
214300
301+ /**
302+ * Request to retrieve all database groups together with their groupUuids.
303+ *
304+ * @return An object that contains the database groups and groupUuids in case the request was successful, an empty object otherwise.
305+ */
215306 public JSONObject getDatabaseGroups () {
216307 try {
217308 return connection .getDatabaseGroups ();
@@ -221,6 +312,11 @@ public JSONObject getDatabaseGroups() {
221312 }
222313 }
223314
315+ /**
316+ * Request to generate a password according to the password generator settings.
317+ *
318+ * @return The newly generated password in case the generation was successful, an empty String otherwise.
319+ */
224320 public String generatePassword () {
225321 try {
226322 var response = connection .generatePassword ().getJSONArray ("entries" );
@@ -231,6 +327,11 @@ public String generatePassword() {
231327 }
232328 }
233329
330+ /**
331+ * Request for locking the database from client.
332+ *
333+ * @return True, if the database could not locked, false if something went wrong.
334+ */
234335 public boolean lockDatabase () {
235336 try {
236337 connection .lockDatabase ();
@@ -241,6 +342,15 @@ public boolean lockDatabase() {
241342 }
242343 }
243344
345+ /**
346+ * Request to create a new group for the given name or path. If the group already exists, its contents and
347+ * groupUuid stay untouched.
348+ *
349+ * @param path Name or path. A path of the format level1/level2 creates a group level1 on the root level and a
350+ * group level2 as a child of level1.
351+ * @return A Map containing the last part of the path name of the group (key: "name") that was created with its according groupUuid (key: "uuid")
352+ * in case the group could be created, an empty Map otherwise.
353+ */
244354 public Map <String , String > createNewGroup (String path ) {
245355 try {
246356 return getNewGroupId (connection .createNewGroup (path ));
@@ -250,6 +360,13 @@ public Map<String, String> createNewGroup(String path) {
250360 }
251361 }
252362
363+ /**
364+ * Request the actual TOTP for the given entry, identified by its uuid. If TOTP is not configured for the entry,
365+ * an empty String is returned.
366+ *
367+ * @param uuid The uuid of the entry.
368+ * @return The TOTP for the entry or an empty String in case TOTP is not configured for that entry or an error occurred.
369+ */
253370 public String getTotp (String uuid ) {
254371 try {
255372 return connection .getTotp (uuid ).getString ("totp" );
@@ -319,5 +436,10 @@ public String getAssociateId() {
319436 return connection .getAssociateId ();
320437 }
321438
439+ /**
440+ * Getter for the ScheduledExecutorService in case the service needs to be shutdown from outside this library.
441+ *
442+ * @return A reference to the ScheduledExecutorService.
443+ */
322444 public ScheduledExecutorService getScheduler () { return scheduler ; }
323445}
0 commit comments