Search in sources :

Example 96 with ActionParametersBase

use of org.ovirt.engine.core.common.action.ActionParametersBase in project ovirt-engine by oVirt.

the class SequentialMultipleActionsRunner method execute.

@Override
public ArrayList<ActionReturnValue> execute() {
    for (ActionParametersBase parameter : parameters) {
        if (!isInternal) {
            logExecution(log, sessionDataContainer, parameter.getSessionId(), String.format("command %s", actionType));
        }
        CommandBase<?> command = commandFactory.createWrappedCommand(commandContext, actionType, parameter, isInternal);
        commandFactory.prepareCommandForMonitoring(commandContext, command);
        returnValues.add(command.executeAction());
    }
    return returnValues;
}
Also used : ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 97 with ActionParametersBase

use of org.ovirt.engine.core.common.action.ActionParametersBase in project ovirt-engine by oVirt.

the class PrevalidatingMultipleActionsRunner method initCommandsAndReturnValues.

private void initCommandsAndReturnValues(List<ActionReturnValue> returnValues) {
    ActionReturnValue returnValue;
    for (ActionParametersBase parameter : getParameters()) {
        parameter.setMultipleAction(true);
        returnValue = ExecutionHandler.evaluateCorrelationId(parameter);
        if (returnValue == null) {
            getCommands().add(commandFactory.createWrappedCommand(commandContext, actionType, parameter, isInternal));
        } else {
            returnValues.add(returnValue);
        }
    }
}
Also used : ActionReturnValue(org.ovirt.engine.core.common.action.ActionReturnValue) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 98 with ActionParametersBase

use of org.ovirt.engine.core.common.action.ActionParametersBase in project ovirt-engine by oVirt.

the class RestApiSessionMgmtFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    try {
        HttpServletRequest req = (HttpServletRequest) request;
        String engineSessionId = (String) request.getAttribute(SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY);
        if (engineSessionId == null) {
            HttpSession session = req.getSession(false);
            if (session != null) {
                engineSessionId = (String) session.getAttribute(SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY);
                if (engineSessionId != null) {
                    request.setAttribute(SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY, engineSessionId);
                }
            }
        }
        if (engineSessionId == null) {
            throw new ServletException("No engine session");
        }
        int prefer = FiltersHelper.getPrefer(req);
        if ((prefer & FiltersHelper.PREFER_PERSISTENCE_AUTH) != 0) {
            HttpSession session = req.getSession(true);
            session.setAttribute(SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY, engineSessionId);
            try {
                int ttlMinutes = Integer.parseInt(req.getHeader("Session-TTL"));
                if (ttlMinutes >= MINIMAL_SESSION_TTL) {
                    // For new sessions:
                    if (isNewSession(req)) {
                        // Save Session-TTL on the HTTP session (in seconds).
                        session.setMaxInactiveInterval((int) TimeUnit.MINUTES.toSeconds(ttlMinutes));
                        // Save Session-TTL in the Engine.
                        setEngineSessionSoftLimit(engineSessionId, ttlMinutes);
                    }
                }
            } catch (NumberFormatException ex) {
            // ignore error
            }
        }
        chain.doFilter(request, response);
        if (FiltersHelper.isAuthenticated(req)) {
            String headerValue = req.getHeader(FiltersHelper.Constants.HEADER_AUTHORIZATION);
            if ((headerValue == null || !headerValue.startsWith(BEARER)) && (prefer & FiltersHelper.PREFER_PERSISTENCE_AUTH) == 0) {
                InitialContext ctx = new InitialContext();
                try {
                    FiltersHelper.getBackend(ctx).runAction(ActionType.LogoutSession, new ActionParametersBase(engineSessionId));
                    HttpSession session = req.getSession(false);
                    if (session != null) {
                        try {
                            session.invalidate();
                        } catch (IllegalStateException e) {
                        // ignore
                        }
                    }
                } finally {
                    ctx.close();
                }
            }
        }
    } catch (NamingException e) {
        log.error("REST-API session failed: {}", e.getMessage());
        log.debug("Exception", e);
        throw new ServletException(e);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) HttpSession(javax.servlet.http.HttpSession) NamingException(javax.naming.NamingException) InitialContext(javax.naming.InitialContext) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Example 99 with ActionParametersBase

use of org.ovirt.engine.core.common.action.ActionParametersBase in project ovirt-engine by oVirt.

the class SsoLogoutServlet method service.

@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    log.debug("Entered SsoLogoutServlet");
    String token = null;
    try {
        String engineSessionId = (String) request.getAttribute(SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY);
        if (StringUtils.isEmpty(engineSessionId) && request.getSession(false) != null) {
            engineSessionId = (String) request.getSession(false).getAttribute(SessionConstants.HTTP_SESSION_ENGINE_SESSION_ID_KEY);
        }
        if (StringUtils.isNotEmpty(engineSessionId)) {
            InitialContext ctx = new InitialContext();
            try {
                QueryParametersBase params = new QueryParametersBase(engineSessionId);
                params.setFiltered(true);
                QueryReturnValue retValue = FiltersHelper.getBackend(ctx).runQuery(QueryType.GetEngineSessionIdToken, params);
                token = retValue.getReturnValue();
                FiltersHelper.getBackend(ctx).runAction(ActionType.LogoutSession, new ActionParametersBase(engineSessionId));
            } finally {
                ctx.close();
            }
        }
    } catch (Exception ex) {
        log.error("Unable to clear user session {}", ex.getMessage());
    }
    HttpSession session = request.getSession(false);
    if (session != null) {
        log.debug("Setting session attribute {}", FiltersHelper.Constants.LOGOUT_INPROGRESS);
        session.setAttribute(FiltersHelper.Constants.LOGOUT_INPROGRESS, true);
    }
    Map<String, Object> revokeResponse = SsoOAuthServiceUtils.revoke(token);
    String error_description = (String) revokeResponse.get("error_description");
    String error = (String) revokeResponse.get("error");
    if (StringUtils.isNotEmpty(error_description)) {
        log.error("Unable to logout user: {}", error_description);
    }
    String url = String.format("%s://%s:%s%s/oauth2-callback", request.getScheme(), FiltersHelper.getRedirectUriServerName(request.getServerName()), request.getServerPort(), EngineLocalConfig.getInstance().getProperty("ENGINE_URI"));
    String redirectUri = new URLBuilder(url).addParameter("error_description", StringUtils.defaultIfEmpty(error_description, "")).addParameter("error", StringUtils.defaultIfEmpty(error, "")).build();
    if (session != null) {
        log.debug("Invalidating existing session");
        session.invalidate();
    }
    log.debug("Redirecting to {}", redirectUri);
    response.sendRedirect(redirectUri);
    log.debug("Exiting SsoLogoutServlet");
}
Also used : QueryReturnValue(org.ovirt.engine.core.common.queries.QueryReturnValue) HttpSession(javax.servlet.http.HttpSession) QueryParametersBase(org.ovirt.engine.core.common.queries.QueryParametersBase) InitialContext(javax.naming.InitialContext) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) URLBuilder(org.ovirt.engine.core.uutils.net.URLBuilder)

Example 100 with ActionParametersBase

use of org.ovirt.engine.core.common.action.ActionParametersBase in project ovirt-engine by oVirt.

the class AttachStorageDomainsMultipleActionRunner method execute.

@Override
public List<ActionReturnValue> execute() {
    Iterator<?> iterator = getParameters() == null ? null : getParameters().iterator();
    Object parameter = iterator != null && iterator.hasNext() ? iterator.next() : null;
    if (parameter instanceof StorageDomainPoolParametersBase) {
        StorageDomainPoolParametersBase storagePoolParameter = (StorageDomainPoolParametersBase) parameter;
        StoragePool pool = storagePoolDao.get(storagePoolParameter.getStoragePoolId());
        if (pool.getStatus() == StoragePoolStatus.Uninitialized) {
            List<Guid> storageDomainIds = new ArrayList<>();
            for (ActionParametersBase param : getParameters()) {
                storageDomainIds.add(((StorageDomainPoolParametersBase) param).getStorageDomainId());
            }
            List<ActionParametersBase> parameters = new ArrayList<>();
            parameters.add(new StoragePoolWithStoragesParameter(pool, storageDomainIds, storagePoolParameter.getSessionId()));
            if (isInternal) {
                return backend.runInternalMultipleActions(ActionType.AddStoragePoolWithStorages, parameters);
            } else {
                return backend.runMultipleActions(ActionType.AddStoragePoolWithStorages, parameters, false);
            }
        } else {
            return super.execute();
        }
    } else {
        return super.execute();
    }
}
Also used : StoragePool(org.ovirt.engine.core.common.businessentities.StoragePool) StorageDomainPoolParametersBase(org.ovirt.engine.core.common.action.StorageDomainPoolParametersBase) StoragePoolWithStoragesParameter(org.ovirt.engine.core.common.action.StoragePoolWithStoragesParameter) ArrayList(java.util.ArrayList) Guid(org.ovirt.engine.core.compat.Guid) ActionParametersBase(org.ovirt.engine.core.common.action.ActionParametersBase)

Aggregations

ActionParametersBase (org.ovirt.engine.core.common.action.ActionParametersBase)204 ArrayList (java.util.ArrayList)149 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)53 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)52 ActionType (org.ovirt.engine.core.common.action.ActionType)45 Test (org.junit.Test)44 Guid (org.ovirt.engine.core.compat.Guid)35 VDS (org.ovirt.engine.core.common.businessentities.VDS)26 List (java.util.List)23 EntityModel (org.ovirt.engine.ui.uicommonweb.models.EntityModel)23 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)20 VM (org.ovirt.engine.core.common.businessentities.VM)19 QueryType (org.ovirt.engine.core.common.queries.QueryType)18 Frontend (org.ovirt.engine.ui.frontend.Frontend)18 ConstantsManager (org.ovirt.engine.ui.uicompat.ConstantsManager)18 IFrontendActionAsyncCallback (org.ovirt.engine.ui.uicompat.IFrontendActionAsyncCallback)18 StoragePool (org.ovirt.engine.core.common.businessentities.StoragePool)16 AsyncDataProvider (org.ovirt.engine.ui.uicommonweb.dataprovider.AsyncDataProvider)16 HelpTag (org.ovirt.engine.ui.uicommonweb.help.HelpTag)16 StorageDomain (org.ovirt.engine.core.common.businessentities.StorageDomain)15