Search in sources :

Example 1 with UserSessionManagementType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementType in project midpoint by Evolveum.

the class ClusterwideUserSessionManagerImpl method getLoggedInPrincipals.

@Override
@NotNull
public List<UserSessionManagementType> getLoggedInPrincipals(Task task, OperationResult result) {
    List<UserSessionManagementType> loggedUsers = guiProfiledPrincipalManager.getLocalLoggedInPrincipals();
    Map<String, UserSessionManagementType> usersMap = new HashMap<>();
    // fix for mid-6328
    loggedUsers.forEach(loggedUser -> {
        UserSessionManagementType addedUser = usersMap.get(loggedUser.getFocus().getOid());
        if (addedUser != null) {
            addedUser.setActiveSessions(addedUser.getActiveSessions() + loggedUser.getActiveSessions());
            addedUser.getNode().addAll(loggedUser.getNode());
        } else {
            usersMap.put(loggedUser.getFocus().getOid(), loggedUser);
        }
    });
    // We try to invoke this call also on nodes that are in transition. We want to get
    // information as complete as realistically possible.
    clusterExecutionHelper.execute((client, node, result1) -> {
        client.path(ClusterServiceConsts.EVENT_LIST_USER_SESSION);
        Response response = client.get();
        LOGGER.debug("Remote-node retrieval of user sessions finished on {} with status {}, {}", node.getNodeIdentifier(), response.getStatusInfo().getStatusCode(), response.getStatusInfo().getReasonPhrase());
        if (response.hasEntity()) {
            UserSessionManagementListType remoteSessionsWrapper = response.readEntity(UserSessionManagementListType.class);
            List<UserSessionManagementType> remoteSessions = remoteSessionsWrapper.getSession();
            for (UserSessionManagementType remoteSession : MiscUtil.emptyIfNull(remoteSessions)) {
                UserSessionManagementType existingUser = usersMap.get(remoteSession.getFocus().getOid());
                if (existingUser != null) {
                    existingUser.setActiveSessions(existingUser.getActiveSessions() + remoteSession.getActiveSessions());
                    existingUser.getNode().addAll(remoteSession.getNode());
                } else {
                    usersMap.put(remoteSession.getFocus().getOid(), remoteSession);
                }
            }
        }
        response.close();
    }, new ClusterExecutionOptions().tryNodesInTransition(), " list principals from remote nodes ", result);
    return new ArrayList<>(usersMap.values());
}
Also used : Response(javax.ws.rs.core.Response) UserSessionManagementType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) UserSessionManagementListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementListType) ClusterExecutionOptions(com.evolveum.midpoint.task.api.ClusterExecutionOptions) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with UserSessionManagementType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementType in project midpoint by Evolveum.

the class InternalsLoggedInUsersPanel method initLayout.

private void initLayout() {
    MainObjectListPanel<F> table = new MainObjectListPanel(ID_TABLE, FocusType.class, null) {

        @Override
        protected void objectDetailsPerformed(AjaxRequestTarget target, ObjectType object) {
            if (WebComponentUtil.hasDetailsPage(object.getClass())) {
                PageParameters parameters = new PageParameters();
                parameters.add(OnePageParameterEncoder.PARAMETER, object.getOid());
                getPageBase().navigateToNext(WebComponentUtil.getObjectDetailsPage(object.getClass()), parameters);
            }
        }

        @Override
        protected List<IColumn<SelectableBean<F>, String>> createDefaultColumns() {
            return InternalsLoggedInUsersPanel.this.initColumns();
        }

        @Override
        protected List<InlineMenuItem> createInlineMenu() {
            return initInlineMenu();
        }

        @Override
        protected UserProfileStorage.TableId getTableId() {
            return null;
        }

        @Override
        protected ISelectableDataProvider<UserSessionManagementType, SelectableBean<F>> createProvider() {
            LoadableModel<List<UserSessionManagementType>> principals = new LoadableModel<List<UserSessionManagementType>>(true) {

                @Override
                protected List<UserSessionManagementType> load() {
                    return loadLoggedInPrincipals();
                }
            };
            return new SelectableListDataProvider<SelectableBean<F>, UserSessionManagementType>(InternalsLoggedInUsersPanel.this, principals) {

                @Override
                protected SelectableBean<F> createObjectWrapper(UserSessionManagementType principal) {
                    SelectableBeanImpl<F> user = new SelectableBeanImpl<>((F) principal.getFocus());
                    user.setActiveSessions(principal.getActiveSessions());
                    user.setNodes(principal.getNode());
                    return user;
                }
            };
        }

        @Override
        protected boolean isCreateNewObjectEnabled() {
            return false;
        }

        @Override
        protected List<Component> createToolbarButtonsList(String buttonId) {
            return new ArrayList<>();
        }

        @Override
        protected boolean enableSavePageSize() {
            return false;
        }
    };
    add(table);
}
Also used : MainObjectListPanel(com.evolveum.midpoint.gui.api.component.MainObjectListPanel) UserSessionManagementType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementType) SelectableBeanImpl(com.evolveum.midpoint.web.component.util.SelectableBeanImpl) ArrayList(java.util.ArrayList) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) UserProfileStorage(com.evolveum.midpoint.web.session.UserProfileStorage) IColumn(org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn) SelectableListDataProvider(com.evolveum.midpoint.web.component.util.SelectableListDataProvider) SelectableBean(com.evolveum.midpoint.web.component.util.SelectableBean) LoadableModel(com.evolveum.midpoint.gui.api.model.LoadableModel) InlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem) ButtonInlineMenuItem(com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem) ArrayList(java.util.ArrayList) List(java.util.List) Component(org.apache.wicket.Component)

Example 3 with UserSessionManagementType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementType in project midpoint by Evolveum.

the class GuiProfiledPrincipalManagerImpl method getLocalLoggedInPrincipals.

@Override
public List<UserSessionManagementType> getLocalLoggedInPrincipals() {
    String currentNodeId = taskManager.getNodeId();
    if (sessionRegistry != null) {
        List<Object> loggedInUsers = sessionRegistry.getAllPrincipals();
        List<UserSessionManagementType> loggedPrincipals = new ArrayList<>();
        for (Object principal : loggedInUsers) {
            if (!(principal instanceof GuiProfiledPrincipal)) {
                continue;
            }
            List<SessionInformation> sessionInfos = sessionRegistry.getAllSessions(principal, false);
            if (sessionInfos == null || sessionInfos.isEmpty()) {
                continue;
            }
            GuiProfiledPrincipal midPointPrincipal = (GuiProfiledPrincipal) principal;
            UserSessionManagementType userSessionManagementType = new UserSessionManagementType();
            userSessionManagementType.setFocus(midPointPrincipal.getFocus());
            userSessionManagementType.setActiveSessions(sessionInfos.size());
            userSessionManagementType.getNode().add(currentNodeId);
            loggedPrincipals.add(userSessionManagementType);
        }
        return loggedPrincipals;
    } else {
        return emptyList();
    }
}
Also used : SessionInformation(org.springframework.security.core.session.SessionInformation) UserSessionManagementType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementType) GuiProfiledPrincipal(com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal) ArrayList(java.util.ArrayList) PrismObject(com.evolveum.midpoint.prism.PrismObject) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 4 with UserSessionManagementType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementType in project midpoint by Evolveum.

the class ClusterRestController method listUserSession.

@GetMapping(ClusterServiceConsts.EVENT_LIST_USER_SESSION)
public ResponseEntity<?> listUserSession() {
    Task task = initRequest();
    OperationResult result = createSubresult(task, OPERATION_GET_LOCAL_SCHEDULER_INFORMATION);
    ResponseEntity<?> response;
    try {
        checkNodeAuthentication();
        List<UserSessionManagementType> principals = focusProfileService.getLocalLoggedInPrincipals();
        UserSessionManagementListType list = new UserSessionManagementListType();
        list.getSession().addAll(principals);
        response = createResponse(HttpStatus.OK, list, result);
    } catch (Throwable t) {
        response = handleException(result, t);
    }
    result.computeStatus();
    finishRequest(task, result);
    return response;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) UserSessionManagementType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserSessionManagementListType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementListType)

Aggregations

UserSessionManagementType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementType)4 ArrayList (java.util.ArrayList)3 UserSessionManagementListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementListType)2 MainObjectListPanel (com.evolveum.midpoint.gui.api.component.MainObjectListPanel)1 LoadableModel (com.evolveum.midpoint.gui.api.model.LoadableModel)1 GuiProfiledPrincipal (com.evolveum.midpoint.model.api.authentication.GuiProfiledPrincipal)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 ClusterExecutionOptions (com.evolveum.midpoint.task.api.ClusterExecutionOptions)1 Task (com.evolveum.midpoint.task.api.Task)1 ButtonInlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.ButtonInlineMenuItem)1 InlineMenuItem (com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem)1 SelectableBean (com.evolveum.midpoint.web.component.util.SelectableBean)1 SelectableBeanImpl (com.evolveum.midpoint.web.component.util.SelectableBeanImpl)1 SelectableListDataProvider (com.evolveum.midpoint.web.component.util.SelectableListDataProvider)1 UserProfileStorage (com.evolveum.midpoint.web.session.UserProfileStorage)1 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)1 HashMap (java.util.HashMap)1 List (java.util.List)1