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;
}
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);
}
}
}
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);
}
}
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");
}
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();
}
}
Aggregations