Search in sources :

Example 1 with UserSessionManagementListType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementListType 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 UserSessionManagementListType

use of com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementListType 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

UserSessionManagementListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementListType)2 UserSessionManagementType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.UserSessionManagementType)2 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 ClusterExecutionOptions (com.evolveum.midpoint.task.api.ClusterExecutionOptions)1 Task (com.evolveum.midpoint.task.api.Task)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Response (javax.ws.rs.core.Response)1 NotNull (org.jetbrains.annotations.NotNull)1