use of org.ovirt.engine.core.uutils.net.URLBuilder in project ovirt-engine by oVirt.
the class SsoLoginServlet method service.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.debug("Entered SsoLoginServlet");
String scope = String.format("ovirt-app-admin ovirt-app-portal ovirt-ext=auth:sequence-priority=%s", EngineLocalConfig.getInstance().getProperty(authSequencePriorityPropertyName));
String redirectUri = String.format("%s://%s:%s%s", request.getScheme(), FiltersHelper.getRedirectUriServerName(request.getServerName()), request.getServerPort(), postActionUrl);
URLBuilder urlBuilder = new URLBuilder(FiltersHelper.getEngineSsoUrl(request), "/oauth/authorize").addParameter("client_id", EngineLocalConfig.getInstance().getProperty("ENGINE_SSO_CLIENT_ID")).addParameter("response_type", "code").addParameter("app_url", request.getParameter("app_url")).addParameter("engine_url", FiltersHelper.getEngineUrl(request)).addParameter("redirect_uri", redirectUri).addParameter("scope", scope).addParameter("source_addr", request.getRemoteAddr());
if (StringUtils.isNotEmpty(request.getParameter("sso_token"))) {
urlBuilder.addParameter("sso_token", request.getParameter("sso_token"));
}
String url = urlBuilder.build();
log.debug("Redirecting to '{}'", url);
response.sendRedirect(url);
}
use of org.ovirt.engine.core.uutils.net.URLBuilder 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.uutils.net.URLBuilder in project ovirt-engine by oVirt.
the class LoginServlet method service.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Map<String, Object> deployedResponse = SsoOAuthServiceUtils.isSsoDeployed();
if (deployedResponse.containsKey(WelcomeUtils.ERROR_DESCRIPTION)) {
request.getSession(true).setAttribute(WelcomeUtils.ERROR_DESCRIPTION, deployedResponse.get(WelcomeUtils.ERROR_DESCRIPTION));
request.getSession(true).setAttribute(WelcomeUtils.ERROR, deployedResponse.get(WelcomeUtils.ERROR));
response.sendRedirect(EngineLocalConfig.getInstance().getProperty(WelcomeUtils.ENGINE_URI));
} else {
response.sendRedirect(new URLBuilder(FiltersHelper.getEngineSsoUrl(request), WelcomeUtils.OAUTH_AUTHORIZE_URI).addParameter(WelcomeUtils.HTTP_PARAM_CLIENT_ID, EngineLocalConfig.getInstance().getProperty(WelcomeUtils.ENGINE_SSO_CLIENT_ID)).addParameter(WelcomeUtils.HTTP_PARAM_RESPONSE_TYPE, WelcomeUtils.CODE).addParameter(WelcomeUtils.HTTP_PARAM_ENGINE_URL, FiltersHelper.getEngineUrl(request)).addParameter(WelcomeUtils.HTTP_PARAM_REDIRECT_URI, WelcomeUtils.getOauth2CallbackUrl(request)).addParameter(WelcomeUtils.HTTP_PARAM_SCOPE, request.getParameter(WelcomeUtils.SCOPE)).addParameter(WelcomeUtils.HTTP_PARAM_LOCALE, request.getAttribute(WelcomeUtils.LOCALE).toString()).addParameter(WelcomeUtils.HTTP_PARAM_SOURCE_ADDR, request.getRemoteAddr()).build());
}
}
use of org.ovirt.engine.core.uutils.net.URLBuilder in project ovirt-engine by oVirt.
the class LogoutServlet method service.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String errorDescription = null;
String error = null;
try {
Map<String, Object> revokeResponse = SsoOAuthServiceUtils.revoke((String) request.getSession(true).getAttribute(WelcomeUtils.TOKEN));
errorDescription = (String) revokeResponse.get(WelcomeUtils.ERROR_DESCRIPTION);
error = (String) revokeResponse.get(WelcomeUtils.ERROR);
HttpSession session = request.getSession();
if (session != null) {
session.invalidate();
}
} catch (Exception ex) {
log.error("Unable to logout user: {}", ex.getMessage());
}
response.sendRedirect(new URLBuilder(WelcomeUtils.getOauth2CallbackUrl(request)).addParameter(WelcomeUtils.ERROR_DESCRIPTION, StringUtils.defaultIfEmpty(errorDescription, "")).addParameter(WelcomeUtils.ERROR, StringUtils.defaultIfEmpty(error, "")).build());
}
use of org.ovirt.engine.core.uutils.net.URLBuilder in project ovirt-engine by oVirt.
the class SsoUtils method redirectToModule.
public static void redirectToModule(HttpServletRequest request, HttpServletResponse response) throws IOException {
log.debug("Entered redirectToModule");
try {
SsoSession ssoSession = getSsoSession(request);
URLBuilder redirectUrl = new URLBuilder(getRedirectUrl(request)).addParameter("code", ssoSession.getAuthorizationCode());
String appUrl = ssoSession.getAppUrl();
if (StringUtils.isNotEmpty(appUrl)) {
redirectUrl.addParameter("app_url", appUrl);
}
String state = ssoSession.getState();
if (StringUtils.isNotEmpty(state)) {
redirectUrl.addParameter("state", state);
}
String url = redirectUrl.build();
response.sendRedirect(url);
log.debug("Redirecting back to module: {}", url);
} catch (Exception ex) {
log.error("Error redirecting back to module: {}", ex.getMessage());
log.debug("Exception", ex);
throw new RuntimeException(ex);
} finally {
getSsoSession(request).cleanup();
}
}
Aggregations