private boolean authenticationNotAttempted(HttpServletRequest request, HttpServletResponse response) { authenticationListener.authenticationNotAttempted(request, response); return true; }
private void fail(HttpServletRequest request, HttpServletResponse response, String externallyVisibleMessage, int httpResponseCode) { sendErrorResponse(response, httpResponseCode, externallyVisibleMessage); authenticationListener.authenticationFailure(new Authenticator.Result.Failure(createMessage("")), request, response); }
private boolean mayProceed(HttpServletRequest request, HttpServletResponse response, OAuthRequestVerifier verifier) { if (!authenticationController.shouldAttemptAuthentication(request)) { authenticationListener.authenticationNotAttempted(request, response); return true; authenticationListener.authenticationNotAttempted(request, response); return true; final Authenticator.Result result = authenticator.authenticate(request, response); if (result.getStatus() == Authenticator.Result.Status.FAILED) { authenticationListener.authenticationFailure(result, request, response); OAuthProblemUtils.logOAuthRequest(request, "OAuth authentication FAILED.", LOG); return false; if (result.getStatus() == Authenticator.Result.Status.ERROR) { authenticationListener.authenticationError(result, request, response); OAuthProblemUtils.logOAuthRequest(request, "OAuth authentication ERRORED.", LOG); return false; authenticationListener.authenticationSuccess(result, request, response); verifier.setVerified(true); OAuthProblemUtils.logOAuthRequest(request, "OAuth authentication successful. Thread marked as Verified.", LOG);
private void actAsAddonUser(FilterChain filterChain, HttpServletRequest request, HttpServletResponse response, String addonKey) throws IOException, ServletException { try { final Principal principal = getPrincipal(addonKey); final Authenticator.Result authenticationResult = new Authenticator.Result.Success(createMessage("Successful two-legged-auth"), principal); authenticationListener.authenticationSuccess(authenticationResult, request, response); filterChain.doFilter(request, response); } catch (InvalidSubjectException e) { createAndSendFailure(e, response, HttpServletResponse.SC_UNAUTHORIZED, badCredentialsMessage); } }
private Result getUserLoginResult(HttpServletRequest request, HttpServletResponse response, OAuthMessage message, Consumer consumer, Principal user) { // if a user is provided, they must exist and be able to login if (user != null && !authenticationController.canLogin(user, request)) { LOG.info("Access denied because user:'{}' cannot login", user.getName()); sendError(response, HttpServletResponse.SC_UNAUTHORIZED, message); return new Result.Failure(new OAuthProblem.PermissionDenied(user.getName())); } LOG.info("Authenticated app '{}' as user '{}' successfully", consumer.getKey(), user == null ? "null" : user.getName()); return new Result.Success(user); }
@Override public Result success(String message, Principal principal, Jwt authenticatedJwt) { return new Result.Success(createMessage(message), principal); }
private static Authenticator.Result.Failure createAndSendFailure(Exception e, HttpServletResponse response, int httpResponseCode, String externallyVisibleMessage) { log.debug("Failure during JWT authentication: ", e); sendErrorResponse(response, httpResponseCode, externallyVisibleMessage); return new Authenticator.Result.Failure(createMessage(e.getLocalizedMessage())); }
private static Result.Error createAndSendError(Exception e, HttpServletResponse response, int httpResponseCode, String externallyVisibleMessage) { log.debug("Error during JWT authentication: ", e); sendErrorResponse(response, httpResponseCode, externallyVisibleMessage); return new Result.Error(createMessage(e.getLocalizedMessage())); }
public void authenticationSuccess(Authenticator.Result result, HttpServletRequest request, HttpServletResponse response) { String name = result.getPrincipal().getName(); uma.loginUserForThisRequest(name, request); }
private static void sendErrorResponse(HttpServletResponse response, int httpResponseCode, Result result) { String externallyVisibleMessage = result.getMessage(); response.reset(); try { response.sendError(httpResponseCode, externallyVisibleMessage); } catch (IOException doubleFacePalm) { log.error("Encountered IOException while trying to report an authentication failure.", doubleFacePalm); response.reset(); response.setStatus(httpResponseCode); // no error message, but hopefully the response code will still be useful } }
private boolean mayProceed(HttpServletRequest request, HttpServletResponse response) if (!authenticationController.shouldAttemptAuthentication(request)) final Authenticator.Result result = authenticator.authenticate(request, response); if (result.getStatus() == Authenticator.Result.Status.FAILED) authenticationListener.authenticationFailure(result, request, response); return false; if (result.getStatus() == Authenticator.Result.Status.ERROR) authenticationListener.authenticationError(result, request, response); return false; authenticationListener.authenticationNotAttempted(request, response); return true;
private void impersonateSubject(FilterChain filterChain, HttpServletRequest request, HttpServletResponse response, UserProfile userProfile) throws IOException, ServletException { // Products use the username to set the authentication context. SimplePrincipal principal = new SimplePrincipal(userProfile.getUsername()); final Authenticator.Result authenticationResult = new Authenticator.Result.Success(createMessage("Successful three-legged-auth"), principal); authenticationListener.authenticationSuccess(authenticationResult, request, response); filterChain.doFilter(request, response); }
private void fail(HttpServletRequest request, HttpServletResponse response, String externallyVisibleMessage, int httpResponseCode) { sendErrorResponse(response, httpResponseCode, externallyVisibleMessage); authenticationListener.authenticationFailure(new Authenticator.Result.Failure(createMessage("")), request, response); }
private boolean authenticationNotAttempted(HttpServletRequest request, HttpServletResponse response) { authenticationListener.authenticationNotAttempted(request, response); return true; }
private Result handleException(HttpServletResponse response, OAuthMessage message, Exception e) { // this isn't likely to happen, it would result from some unknown error with the request that the OAuth.net // library couldn't handle appropriately LOG.error("Failed to validate OAuth message", e); sendError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, message); return new Result.Error(new OAuthProblem.System(e)); }
public void authenticationSuccess(Authenticator.Result result, HttpServletRequest request, HttpServletResponse response) { String name = result.getPrincipal().getName(); loginUserForThisRequest(name, request); }
if (!authenticationController.shouldAttemptAuthentication(request)) { return authenticationNotAttempted(request, response); final Result result = authenticator.authenticate(request, response); switch (result.getStatus()) { case SUCCESS: authenticationListener.authenticationSuccess(result, request, response); return true; case NO_ATTEMPT: authenticationListener.authenticationNotAttempted(request, response); return true; case FAILED: authenticationListener.authenticationFailure(result, request, response); setFailureResponse(result, response); return false; case ERROR: default: authenticationListener.authenticationError(result, request, response); setErrorResponse(result, response); return false;
private void impersonateSubject(FilterChain filterChain, HttpServletRequest request, HttpServletResponse response, UserProfile userProfile) throws IOException, ServletException { // Products use the username to set the authentication context. SimplePrincipal principal = new SimplePrincipal(userProfile.getUsername()); final Authenticator.Result authenticationResult = new Authenticator.Result.Success(createMessage("Successful three-legged-auth"), principal); authenticationListener.authenticationSuccess(authenticationResult, request, response); filterChain.doFilter(request, response); }
private boolean authenticationNotAttempted(HttpServletRequest request, HttpServletResponse response) { authenticationListener.authenticationNotAttempted(request, response); return true; }
private void actAsAddonUser(FilterChain filterChain, HttpServletRequest request, HttpServletResponse response, String addonKey) throws IOException, ServletException { try { final Principal principal = getPrincipal(addonKey); final Authenticator.Result authenticationResult = new Authenticator.Result.Success(createMessage("Successful two-legged-auth"), principal); authenticationListener.authenticationSuccess(authenticationResult, request, response); filterChain.doFilter(request, response); } catch (InvalidSubjectException e) { createAndSendFailure(e, response, HttpServletResponse.SC_UNAUTHORIZED, i18nResolver.getText(BAD_CREDENTIALS_KEY)); } }