use of org.ovirt.engine.core.sso.utils.OAuthException in project ovirt-engine by oVirt.
the class OAuthTokenServlet method issueTokenForLoginOnBehalf.
private void issueTokenForLoginOnBehalf(HttpServletRequest request, HttpServletResponse response, String scope) throws Exception {
log.debug("Entered issueTokenForLoginOnBehalf");
String[] clientIdAndSecret = SsoUtils.getClientIdClientSecret(request);
String username = SsoUtils.getRequestParameter(request, "username");
log.debug("Attempting to issueTokenForLoginOnBehalf for client: {}, user: {}", clientIdAndSecret[0], username);
AuthenticationUtils.loginOnBehalf(ssoContext, request, username);
String token = (String) request.getAttribute(SsoConstants.HTTP_REQ_ATTR_ACCESS_TOKEN);
SsoUtils.validateRequestScope(request, token, scope);
SsoSession ssoSession = SsoUtils.getSsoSession(request, token, true);
if (ssoSession == null) {
throw new OAuthException(SsoConstants.ERR_CODE_INVALID_GRANT, ssoContext.getLocalizationUtils().localize(SsoConstants.APP_ERROR_AUTHORIZATION_GRANT_EXPIRED_FOR_USERNAME_PASSWORD, (Locale) request.getAttribute(SsoConstants.LOCALE)));
}
validateClientAcceptHeader(ssoSession, request);
log.debug("Sending json response");
SsoUtils.sendJsonData(response, buildResponse(ssoSession));
}
use of org.ovirt.engine.core.sso.utils.OAuthException in project ovirt-engine by oVirt.
the class OpenIdUserInfoServlet method service.
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
log.debug("Entered OpenIdUserInfoServlet Query String: {}, Parameters : {}", request.getQueryString(), SsoUtils.getRequestParameters(request));
String token = request.getParameter(SsoConstants.HTTP_REQ_ATTR_ACCESS_TOKEN);
if (token == null) {
token = getTokenFromHeader(request);
}
if (token == null) {
throw new OAuthException(SsoConstants.ERROR, SsoConstants.ERR_CODE_INVALID_REQUEST);
}
SsoSession ssoSession = SsoUtils.getSsoSessionFromRequest(request, token);
if (!ssoSession.isActive()) {
throw new OAuthException(SsoConstants.ERR_CODE_INVALID_TOKEN, SsoConstants.ERR_SESSION_EXPIRED_MSG);
}
SsoUtils.sendJsonData(response, buildResponse(request, ssoSession), "application/jwt");
} catch (OAuthException ex) {
SsoUtils.sendJsonDataWithMessage(request, response, ex);
} catch (AuthenticationException ex) {
SsoUtils.sendJsonDataWithMessage(request, response, SsoConstants.ERR_CODE_ACCESS_DENIED, ex);
} catch (Exception ex) {
SsoUtils.sendJsonDataWithMessage(request, response, SsoConstants.ERR_CODE_SERVER_ERROR, ex);
}
}
Aggregations