Identity manager hooks. #209

This commit is contained in:
akwizgran
2016-01-20 12:03:15 +00:00
parent 82cf12040f
commit c4692a7007
16 changed files with 258 additions and 53 deletions

View File

@@ -61,7 +61,6 @@ public class Contact {
@Override
public boolean equals(Object o) {
if (o instanceof Contact) return id.equals(((Contact) o).id);
return false;
return o instanceof Contact && id.equals(((Contact) o).id);
}
}

View File

@@ -23,7 +23,6 @@ public class ContactId {
@Override
public boolean equals(Object o) {
if (o instanceof ContactId) return id == ((ContactId) o).id;
return false;
return o instanceof ContactId && id == ((ContactId) o).id;
}
}

View File

@@ -152,6 +152,9 @@ public interface DatabaseComponent {
/** Returns all contacts. */
Collection<Contact> getContacts() throws DbException;
/** Returns all contacts associated with the given local pseudonym. */
Collection<ContactId> getContacts(AuthorId a) throws DbException;
/** Returns the group with the given ID, if the user subscribes to it. */
Group getGroup(GroupId g) throws DbException;
@@ -300,6 +303,10 @@ public interface DatabaseComponent {
/** Sets the status of the given contact. */
void setContactStatus(ContactId c, Contact.Status s) throws DbException;
/** Sets the status of the given local pseudonym. */
void setLocalAuthorStatus(AuthorId a, LocalAuthor.Status s)
throws DbException;
/** Marks the given message as valid or invalid. */
void setMessageValidity(Message m, ClientId c, boolean valid)
throws DbException;

View File

@@ -6,6 +6,12 @@ import java.util.Collection;
public interface IdentityManager {
/** Registers a hook to be called whenever a local pseudonym is added. */
void registerIdentityAddedHook(IdentityAddedHook hook);
/** Registers a hook to be called whenever a local pseudonym is removed. */
void registerIdentityRemovedHook(IdentityRemovedHook hook);
/** Stores a local pseudonym. */
void addLocalAuthor(LocalAuthor a) throws DbException;
@@ -17,4 +23,12 @@ public interface IdentityManager {
/** Removes a local pseudonym and all associated state. */
void removeLocalAuthor(AuthorId a) throws DbException;
interface IdentityAddedHook {
void identityAdded(AuthorId a);
}
interface IdentityRemovedHook {
void identityRemoved(AuthorId a);
}
}

View File

@@ -3,14 +3,36 @@ package org.briarproject.api.identity;
/** A pseudonym for the local user. */
public class LocalAuthor extends Author {
public enum Status {
ADDING(0), ACTIVE(1), REMOVING(2);
private final int value;
Status(int value) {
this.value = value;
}
public int getValue() {
return value;
}
public static Status fromValue(int value) {
for (Status s : values()) if (s.value == value) return s;
throw new IllegalArgumentException();
}
}
private final byte[] privateKey;
private final long created;
private final Status status;
public LocalAuthor(AuthorId id, String name, byte[] publicKey,
byte[] privateKey, long created) {
byte[] privateKey, long created, Status status) {
super(id, name, publicKey);
this.privateKey = privateKey;
this.created = created;
this.status = status;
}
/** Returns the private key used to generate the pseudonym's signatures. */
@@ -18,7 +40,16 @@ public class LocalAuthor extends Author {
return privateKey;
}
/**
* Returns the time the pseudonym was created, in milliseconds since the
* Unix epoch.
*/
public long getTimeCreated() {
return created;
}
/** Returns the status of the pseudonym. */
public Status getStatus() {
return status;
}
}