use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.
the class CUserManager method containsUserName.
/**
* Checks the stored user names against a provided user name.
*
* @param userName The user name to be checked.
*
* @return true if the user names already contain the given user name.
*/
public synchronized boolean containsUserName(final String userName) {
Preconditions.checkNotNull(userName, "IE02720: userName argument can not be null");
syncUsers();
for (final IUser storedUser : users) {
if (storedUser.getUserName().equalsIgnoreCase(userName)) {
return true;
}
}
return false;
}
use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.
the class CUserManager method editUserName.
/**
* Edits a users user name to something else.
*
* @param user The user where the name should be changed.
* @param userName The user name to change the name of the user to.
*
* @return The new user.
* @throws CouldntSaveDataException
*/
public synchronized IUser editUserName(final IUser user, final String userName) throws CouldntSaveDataException {
Preconditions.checkNotNull(user, "IE02723: user argument can not be null");
Preconditions.checkNotNull(userName, "IE02724: userName argument can not be null");
if (!users.contains(user)) {
throw new IllegalStateException("IE02725: User is not known to the user management.");
}
if (containsUserName(userName)) {
throw new IllegalStateException("IE02726: User name is already in use by another user.");
}
final IUser newUser = provider.editUserName(user, userName);
for (final IUserManagerListener listener : listeners) {
try {
listener.editedUser(newUser);
} catch (final Exception exception) {
CUtilityFunctions.logException(exception);
}
}
return newUser;
}
use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.
the class PostgreSQLGroupNodeCommentTests method appendGroupNodeComment4.
@Test
public void appendGroupNodeComment4() throws CouldntLoadDataException, LoadCancelledException, MaybeNullException, CPartialLoadException, CouldntSaveDataException {
final INaviGroupNode groupNode = setupGroupNode();
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final String firstCommentString = " APPEND GROUP NODE COMMENT WITHOUT PARENT ID ";
final Integer firstCommentId = getProvider().appendGroupNodeComment(groupNode, firstCommentString, user.getUserId());
final IComment firstComment = new CComment(firstCommentId, user, null, firstCommentString);
final String secondCommentString = " APPEND GROUP NODE COMMENT WITH PARENT ID ";
final Integer secondCommentId = getProvider().appendGroupNodeComment(groupNode, secondCommentString, user.getUserId());
final IComment secondComment = new CComment(secondCommentId, user, firstComment, secondCommentString);
final ArrayList<IComment> commentsFromDatabase = getProvider().loadCommentById(secondCommentId);
assertNotNull(commentsFromDatabase);
assertEquals(2, commentsFromDatabase.size());
assertTrue(commentsFromDatabase.contains(firstComment));
assertTrue(commentsFromDatabase.contains(secondComment));
// TODO (timkornau): check if the association to the group node did also work and not just the
// appending under the comment id.
}
use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.
the class PostgreSQLGroupNodeCommentTests method deleteGroupNodeComment6.
/**
* This test checks if the delete of a comment in a series of comments works if the comment is the
* last comment.
*
* <pre>
*Comment 1: Comment 1:
*Comment 2: -> Comment 2:
*Comment 3:
*</pre>
*/
@Test
public void deleteGroupNodeComment6() throws CouldntLoadDataException, LoadCancelledException, MaybeNullException, CPartialLoadException, CouldntSaveDataException, CouldntDeleteException {
final INaviGroupNode groupNode = setupGroupNode();
final List<IComment> storedComments = groupNode.getComments() == null ? new ArrayList<IComment>() : groupNode.getComments();
final IComment lastComment = storedComments.size() == 0 ? null : Iterables.getLast(storedComments);
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final String comment1String = " Comment 1: ";
final int comment1Id = getProvider().appendGroupNodeComment(groupNode, comment1String, user.getUserId());
final IComment comment1 = new CComment(comment1Id, user, lastComment, comment1String);
final String comment2String = " Comment 2: ";
final int comment2Id = getProvider().appendGroupNodeComment(groupNode, comment2String, user.getUserId());
final IComment comment2 = new CComment(comment2Id, user, comment1, comment2String);
final String comment3String = " Comment 3: ";
final int comment3Id = getProvider().appendGroupNodeComment(groupNode, comment3String, user.getUserId());
final IComment comment3 = new CComment(comment3Id, user, comment2, comment3String);
final ArrayList<IComment> commentsBeforeDelete = getProvider().loadCommentById(comment3Id);
assertNotNull(commentsBeforeDelete);
assertEquals(storedComments.size() + 3, commentsBeforeDelete.size());
assertTrue(commentsBeforeDelete.contains(comment1));
assertTrue(commentsBeforeDelete.contains(comment2));
assertTrue(commentsBeforeDelete.contains(comment3));
assertEquals(comment3, Iterables.getLast(commentsBeforeDelete));
assertEquals(comment2, commentsBeforeDelete.get(commentsBeforeDelete.size() - 2));
assertEquals(comment1, commentsBeforeDelete.get(commentsBeforeDelete.size() - 3));
getProvider().deleteGroupNodeComment(groupNode, comment3Id, user.getUserId());
final ArrayList<IComment> commentsAfterDelete1 = getProvider().loadCommentById(comment3Id);
assertNotNull(commentsAfterDelete1);
assertTrue(commentsAfterDelete1.isEmpty());
final ArrayList<IComment> commentsAfterDelete2 = getProvider().loadCommentById(comment2Id);
assertNotNull(commentsAfterDelete2);
assertEquals(storedComments.size() + 2, commentsAfterDelete2.size());
assertTrue(commentsAfterDelete2.contains(comment2));
assertTrue(commentsAfterDelete2.contains(comment1));
assertEquals(comment2, Iterables.getLast(commentsAfterDelete2));
assertEquals(comment1, commentsAfterDelete2.get(commentsAfterDelete2.size() - 2));
}
use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.
the class PostgreSQLGroupNodeCommentTests method deleteGroupNodeComment7.
/**
* This test checks if the delete of a comment in a series of comments works if the comment is a
* comment in the middle.
*
* <pre>
*Comment 1: Comment 1:
*Comment 2: ->
*Comment 3: Comment 3:
*</pre>
*/
@Test
public void deleteGroupNodeComment7() throws CouldntLoadDataException, LoadCancelledException, MaybeNullException, CPartialLoadException, CouldntSaveDataException, CouldntDeleteException {
final INaviGroupNode groupNode = setupGroupNode();
final List<IComment> storedComments = groupNode.getComments() == null ? new ArrayList<IComment>() : groupNode.getComments();
final IComment lastComment = storedComments.size() == 0 ? null : Iterables.getLast(storedComments);
final IUser user = new UniqueTestUserGenerator(getProvider()).nextActiveUser();
final String comment1String = " Comment 1: ";
final int comment1Id = getProvider().appendGroupNodeComment(groupNode, comment1String, user.getUserId());
final IComment comment1 = new CComment(comment1Id, user, lastComment, comment1String);
final String comment2String = " Comment 2: ";
final int comment2Id = getProvider().appendGroupNodeComment(groupNode, comment2String, user.getUserId());
final IComment comment2 = new CComment(comment2Id, user, comment1, comment2String);
final String comment3String = " Comment 3: ";
final int comment3Id = getProvider().appendGroupNodeComment(groupNode, comment3String, user.getUserId());
final IComment comment3 = new CComment(comment3Id, user, comment2, comment3String);
final ArrayList<IComment> commentsBeforeDelete = getProvider().loadCommentById(comment3Id);
assertNotNull(commentsBeforeDelete);
assertEquals(storedComments.size() + 3, commentsBeforeDelete.size());
assertTrue(commentsBeforeDelete.contains(comment1));
assertTrue(commentsBeforeDelete.contains(comment2));
assertTrue(commentsBeforeDelete.contains(comment3));
assertEquals(comment3, Iterables.getLast(commentsBeforeDelete));
assertEquals(comment2, commentsBeforeDelete.get(commentsBeforeDelete.size() - 2));
assertEquals(comment1, commentsBeforeDelete.get(commentsBeforeDelete.size() - 3));
getProvider().deleteGroupNodeComment(groupNode, comment2Id, user.getUserId());
final ArrayList<IComment> commentsAfterDelete1 = getProvider().loadCommentById(comment2Id);
assertNotNull(commentsAfterDelete1);
assertTrue(commentsAfterDelete1.isEmpty());
final ArrayList<IComment> commentsAfterDelete2 = getProvider().loadCommentById(comment3Id);
assertNotNull(commentsAfterDelete2);
assertEquals(storedComments.size() + 2, commentsAfterDelete2.size());
final IComment comment3AfterDelete = new CComment(comment3Id, user, comment1, comment3String);
assertTrue(commentsAfterDelete2.contains(comment3AfterDelete));
assertTrue(commentsAfterDelete2.contains(comment1));
assertEquals(comment3AfterDelete, Iterables.getLast(commentsAfterDelete2));
assertEquals(comment1, commentsAfterDelete2.get(commentsAfterDelete2.size() - 2));
}
Aggregations