Search in sources :

Example 1 with ContextUserAuthManager

use of org.zaproxy.zap.extension.users.ContextUserAuthManager in project zaproxy by zaproxy.

the class PopupUserMenuItemHolder method resetMenu.

private void resetMenu() {
    final List<JMenuItem> mainPopupMenuItems = View.getSingleton().getPopupList();
    // Remove existing popup menu items
    if (visibleItself)
        this.removeAll();
    else {
        for (ExtensionPopupMenuItem menu : getSubmenuItems()) {
            mainPopupMenuItems.remove(menu);
        }
        subMenuItems.clear();
    }
    // Add a popup menu item for each existing users
    Session session = Model.getSingleton().getSession();
    List<Context> contexts = session.getContexts();
    for (Context context : contexts) {
        ContextUserAuthManager manager = extensionUserAuth.getContextUserAuthManager(context.getId());
        for (User user : manager.getUsers()) {
            ExtensionPopupMenuItem piicm;
            if (visibleItself) {
                piicm = getPopupUserMenu(context, user, this.getText());
                this.add(piicm);
            } else {
                piicm = getPopupUserMenu(context, user, this.parentName);
                piicm.setMenuIndex(this.getMenuIndex());
                mainPopupMenuItems.add(piicm);
                subMenuItems.add(piicm);
            }
        }
    }
}
Also used : Context(org.zaproxy.zap.model.Context) ExtensionPopupMenuItem(org.parosproxy.paros.extension.ExtensionPopupMenuItem) User(org.zaproxy.zap.users.User) ContextUserAuthManager(org.zaproxy.zap.extension.users.ContextUserAuthManager) JMenuItem(javax.swing.JMenuItem) Session(org.parosproxy.paros.model.Session)

Example 2 with ContextUserAuthManager

use of org.zaproxy.zap.extension.users.ContextUserAuthManager in project zaproxy by zaproxy.

the class PassiveScanDataUnitTest method shouldUseUsersOfFirstMatchedContextIfMessageApplicableToMultiple.

@Test
void shouldUseUsersOfFirstMatchedContextIfMessageApplicableToMultiple() {
    // Given
    HttpMessage msg = createMessage();
    int contextId = 3;
    Context matchCtxOne = mock(Context.class);
    given(matchCtxOne.getId()).willReturn(contextId);
    ExtensionUserManagement extUserMgmt = mock(ExtensionUserManagement.class);
    List<User> expectedUsers = asList(mock(User.class), mock(User.class));
    ContextUserAuthManager contextUserAuthManager = mock(ContextUserAuthManager.class);
    given(extUserMgmt.getContextUserAuthManager(contextId)).willReturn(contextUserAuthManager);
    given(contextUserAuthManager.getUsers()).willReturn(expectedUsers);
    PassiveScanData.setExtUserMgmt(extUserMgmt);
    Context matchCtxTwo = mock(Context.class);
    given(session.getContextsForUrl(msg.getRequestHeader().getURI().toString())).willReturn(asList(matchCtxOne, matchCtxTwo));
    // When
    PassiveScanData psd = new PassiveScanData(msg);
    // Then
    assertThat(psd.getUsers(), is(equalTo(expectedUsers)));
}
Also used : Context(org.zaproxy.zap.model.Context) ExtensionUserManagement(org.zaproxy.zap.extension.users.ExtensionUserManagement) User(org.zaproxy.zap.users.User) ContextUserAuthManager(org.zaproxy.zap.extension.users.ContextUserAuthManager) HttpMessage(org.parosproxy.paros.network.HttpMessage) Test(org.junit.jupiter.api.Test) WithConfigsTest(org.zaproxy.zap.WithConfigsTest)

Aggregations

ContextUserAuthManager (org.zaproxy.zap.extension.users.ContextUserAuthManager)2 Context (org.zaproxy.zap.model.Context)2 User (org.zaproxy.zap.users.User)2 JMenuItem (javax.swing.JMenuItem)1 Test (org.junit.jupiter.api.Test)1 ExtensionPopupMenuItem (org.parosproxy.paros.extension.ExtensionPopupMenuItem)1 Session (org.parosproxy.paros.model.Session)1 HttpMessage (org.parosproxy.paros.network.HttpMessage)1 WithConfigsTest (org.zaproxy.zap.WithConfigsTest)1 ExtensionUserManagement (org.zaproxy.zap.extension.users.ExtensionUserManagement)1