use of org.ovirt.engine.core.sso.utils.AuthResult in project ovirt-engine by oVirt.
the class OAuthTokenServlet method issueTokenUsingHttpHeaders.
private void issueTokenUsingHttpHeaders(HttpServletRequest request, HttpServletResponse response) throws Exception {
log.debug("Entered issueTokenUsingHttpHeaders");
try {
AuthResult authResult = null;
for (NonInteractiveAuth auth : getAuthSeq()) {
authResult = auth.doAuth(request, response);
if (authResult.getStatus() == Authn.AuthResult.SUCCESS || authResult.getStatus() == Authn.AuthResult.NEGOTIATION_INCOMPLETE) {
break;
}
}
if (authResult != null && authResult.getStatus() != Authn.AuthResult.SUCCESS) {
log.debug("Authentication failed using http headers");
List<String> schemes = (List<String>) request.getAttribute(NegotiateAuthUtils.REQUEST_SCHEMES_KEY);
for (String scheme : new HashSet<>(schemes == null ? Collections.emptyList() : schemes)) {
response.setHeader("WWW-Authenticate", scheme);
}
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
} else if (authResult != null && StringUtils.isNotEmpty(authResult.getToken())) {
SsoSession ssoSession = SsoUtils.getSsoSessionFromRequest(request, authResult.getToken());
if (ssoSession == null) {
throw new OAuthException(SsoConstants.ERR_CODE_INVALID_GRANT, ssoContext.getLocalizationUtils().localize(SsoConstants.APP_ERROR_AUTHORIZATION_GRANT_EXPIRED, (Locale) request.getAttribute(SsoConstants.LOCALE)));
}
validateClientAcceptHeader(ssoSession, request);
log.debug("Sending json response");
SsoUtils.sendJsonData(response, buildResponse(ssoSession));
} else {
throw new AuthenticationException(ssoContext.getLocalizationUtils().localize(SsoConstants.APP_ERROR_AUTHENTICATION_FAILED, (Locale) request.getAttribute(SsoConstants.LOCALE)));
}
} catch (Exception ex) {
throw new AuthenticationException(String.format(ssoContext.getLocalizationUtils().localize(SsoConstants.APP_ERROR_CANNOT_AUTHENTICATE_USER, (Locale) request.getAttribute(SsoConstants.LOCALE)), ex.getMessage()));
}
}
Aggregations