Search in sources :

Example 1 with IUser

use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.

the class CommentManager method appendComment.

/**
 * This function provides the append comment functionality for any given Implementation of a
 * {@link CommentingStrategy}. It uses the methods of the interface to only have one algorithm
 * with different objects that can be commented.
 *
 * @param strategy The {@link CommentingStrategy} which holds the function forwarders.
 * @param commentText The commenting text to append.
 *
 * @return The generated comment.
 *
 * @throws CouldntSaveDataException if the comment could not be stored in the database.
 * @throws CouldntLoadDataException if the list of comments now associated with the commented
 *         object could not be loaded from the database.
 */
private synchronized List<IComment> appendComment(final CommentingStrategy strategy, final String commentText) throws CouldntSaveDataException, CouldntLoadDataException {
    final IUser user = CUserManager.get(provider).getCurrentActiveUser();
    final List<IComment> currentComments = new ArrayList<IComment>();
    if (strategy.isStored()) {
        currentComments.addAll(strategy.appendComment(commentText, user.getUserId()));
    } else {
        currentComments.addAll(strategy.getComments() == null ? new ArrayList<IComment>() : Lists.newArrayList(strategy.getComments()));
        final IComment parent = currentComments.isEmpty() ? null : Iterables.getLast(currentComments);
        final IComment newComment = new CComment(null, user, parent, commentText);
        currentComments.add(newComment);
    }
    strategy.saveComments(currentComments);
    for (final IComment comment : currentComments) {
        commentIdToComment.put(comment.getId(), comment);
    }
    for (final CommentListener listener : listeners) {
        try {
            strategy.sendAppendedCommentNotifcation(listener, Iterables.getLast(currentComments));
        } catch (final Exception exception) {
            CUtilityFunctions.logException(exception);
        }
    }
    return currentComments;
}
Also used : CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) ArrayList(java.util.ArrayList) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)

Example 2 with IUser

use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.

the class CViewInserterTest method test.

@Test
public void test() throws CouldntLoadDataException, CPartialLoadException, LoadCancelledException, FileReadException, CouldntSaveDataException {
    ConfigManager.instance().read();
    final INaviModule mockModule = new MockModule();
    final MockSqlProvider mockProvider = new MockSqlProvider();
    final CUserManager userManager = CUserManager.get(mockProvider);
    final IUser user = userManager.addUser(" VIEW INSERTER USER ");
    userManager.setCurrentActiveUser(user);
    final CModuleViewGenerator generator = new CModuleViewGenerator(mockProvider, mockModule);
    final CView view = generator.generate(1, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    view.load();
    final MockFunction mockFunction = new MockFunction(mockProvider);
    final CFunctionNode fnode1 = view.getContent().createFunctionNode(mockFunction);
    final CFunctionNode fnode2 = view.getContent().createFunctionNode(mockFunction);
    @SuppressWarnings("unused") final CNaviViewEdge edge1 = view.getContent().createEdge(fnode1, fnode2, EdgeType.JUMP_UNCONDITIONAL);
    final MockInstruction instruction1 = new MockInstruction();
    final CCodeNode cnode1 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
    final CCodeNode cnode2 = view.getContent().createCodeNode(mockFunction, Lists.newArrayList(instruction1));
    @SuppressWarnings("unused") final CNaviViewEdge edge2 = view.getContent().createEdge(cnode1, cnode2, EdgeType.JUMP_UNCONDITIONAL);
    final ArrayList<IComment> comments = Lists.<IComment>newArrayList(new CComment(null, CommonTestObjects.TEST_USER_1, null, "Foo"));
    final CTextNode tnode1 = view.getContent().createTextNode(comments);
    @SuppressWarnings("unused") final CNaviViewEdge edge3 = view.getContent().createEdge(cnode1, tnode1, EdgeType.JUMP_UNCONDITIONAL);
    final CGroupNode gnode1 = view.getContent().createGroupNode(Lists.newArrayList((INaviViewNode) fnode1, (INaviViewNode) fnode2));
    gnode1.appendComment("TEST GROUP NODE COMMENT 1");
    final CView view2 = generator.generate(2, "", "", ViewType.NonNative, GraphType.MIXED_GRAPH, new Date(), new Date(), 0, 0, new HashSet<CTag>(), new HashSet<CTag>(), false);
    view2.load();
    CViewInserter.insertView(view, view2);
    final List<INaviViewNode> nodes = view2.getGraph().getNodes();
    assertEquals(view2.getNodeCount(), 6);
    assertEquals(mockFunction, ((INaviFunctionNode) nodes.get(0)).getFunction());
    assertEquals(nodes.get(5), ((INaviFunctionNode) nodes.get(0)).getParentGroup());
}
Also used : MockFunction(com.google.security.zynamics.binnavi.disassembly.MockFunction) CFunctionNode(com.google.security.zynamics.binnavi.disassembly.CFunctionNode) CModuleViewGenerator(com.google.security.zynamics.binnavi.Database.CModuleViewGenerator) IComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment) CTag(com.google.security.zynamics.binnavi.Tagging.CTag) CUserManager(com.google.security.zynamics.binnavi.Gui.Users.CUserManager) Date(java.util.Date) CView(com.google.security.zynamics.binnavi.disassembly.views.CView) CComment(com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment) CNaviViewEdge(com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge) MockInstruction(com.google.security.zynamics.binnavi.disassembly.MockInstruction) INaviModule(com.google.security.zynamics.binnavi.disassembly.INaviModule) MockModule(com.google.security.zynamics.binnavi.disassembly.Modules.MockModule) MockSqlProvider(com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider) CCodeNode(com.google.security.zynamics.binnavi.disassembly.CCodeNode) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) INaviViewNode(com.google.security.zynamics.binnavi.disassembly.INaviViewNode) CTextNode(com.google.security.zynamics.binnavi.disassembly.CTextNode) CGroupNode(com.google.security.zynamics.binnavi.disassembly.CGroupNode) Test(org.junit.Test)

Example 3 with IUser

use of com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser in project binnavi by google.

the class CUserManager method getUserByUserName.

/**
 * Returns a user by reference of name.
 *
 * @param userName The user name of the user to search for.
 *
 * @return The user if found null otherwise.
 */
public synchronized IUser getUserByUserName(final String userName) {
    Preconditions.checkNotNull(userName, "IE02728: userName argument can not be null");
    for (final IUser storedUser : users) {
        if (storedUser.getUserName().equalsIgnoreCase(userName)) {
            return storedUser;
        }
    }
    // if it is not found locally it might be present in the database therefore sync after the local
    // users have been checked.
    syncUsers();
    for (final IUser storedUser : users) {
        if (storedUser.getUserName().equalsIgnoreCase(userName)) {
            return storedUser;
        }
    }
    return null;
}
Also used : IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)

Example 4 with IUser

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;
}
Also used : IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)

Example 5 with IUser

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;
}
Also used : IUserManagerListener(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUserManagerListener) IUser(com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser) CouldntSaveDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException) CouldntLoadDataException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException) CouldntDeleteException(com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)

Aggregations

IUser (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUser)120 Test (org.junit.Test)109 ExpensiveBaseTest (com.google.security.zynamics.binnavi.disassembly.types.ExpensiveBaseTest)99 IComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.Interfaces.IComment)97 CComment (com.google.security.zynamics.binnavi.Gui.GraphWindows.CommentDialogs.CComment)96 UniqueTestUserGenerator (com.google.security.zynamics.binnavi.Database.PostgreSQL.UniqueTestUserGenerator)95 CUserManager (com.google.security.zynamics.binnavi.Gui.Users.CUserManager)11 INaviGroupNode (com.google.security.zynamics.binnavi.disassembly.INaviGroupNode)9 INaviTextNode (com.google.security.zynamics.binnavi.disassembly.INaviTextNode)8 CouldntLoadDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntLoadDataException)6 CouldntSaveDataException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntSaveDataException)4 CouldntDeleteException (com.google.security.zynamics.binnavi.Database.Exceptions.CouldntDeleteException)3 MockSqlProvider (com.google.security.zynamics.binnavi.Database.MockClasses.MockSqlProvider)3 CTag (com.google.security.zynamics.binnavi.Tagging.CTag)3 CNaviViewEdge (com.google.security.zynamics.binnavi.disassembly.CNaviViewEdge)3 INaviModule (com.google.security.zynamics.binnavi.disassembly.INaviModule)3 INaviViewNode (com.google.security.zynamics.binnavi.disassembly.INaviViewNode)3 ArrayList (java.util.ArrayList)3 CUser (com.google.security.zynamics.binnavi.Gui.Users.CUser)2 IUserManagerListener (com.google.security.zynamics.binnavi.Gui.Users.Interfaces.IUserManagerListener)2