Search in sources :

Example 6 with OAuthException

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));
}
Also used : Locale(java.util.Locale) OAuthException(org.ovirt.engine.core.sso.utils.OAuthException) SsoSession(org.ovirt.engine.core.sso.utils.SsoSession)

Example 7 with OAuthException

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);
    }
}
Also used : AuthenticationException(org.ovirt.engine.core.sso.utils.AuthenticationException) OAuthException(org.ovirt.engine.core.sso.utils.OAuthException) SsoSession(org.ovirt.engine.core.sso.utils.SsoSession) ServletException(javax.servlet.ServletException) OAuthException(org.ovirt.engine.core.sso.utils.OAuthException) IOException(java.io.IOException) AuthenticationException(org.ovirt.engine.core.sso.utils.AuthenticationException)

Aggregations

OAuthException (org.ovirt.engine.core.sso.utils.OAuthException)7 SsoSession (org.ovirt.engine.core.sso.utils.SsoSession)5 IOException (java.io.IOException)3 Locale (java.util.Locale)3 ServletException (javax.servlet.ServletException)3 AuthenticationException (org.ovirt.engine.core.sso.utils.AuthenticationException)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 AuthResult (org.ovirt.engine.core.sso.utils.AuthResult)1 Credentials (org.ovirt.engine.core.sso.utils.Credentials)1 InteractiveAuth (org.ovirt.engine.core.sso.utils.InteractiveAuth)1 NonInteractiveAuth (org.ovirt.engine.core.sso.utils.NonInteractiveAuth)1 URLBuilder (org.ovirt.engine.core.uutils.net.URLBuilder)1