Source:
private void doAuth(HttpServletRequest req, HttpServletResponse rsp, FilterChain chain) throws IOException, ServletException { HttpSession session = req.getSession(false); if (session != null) { if (!FiltersHelper.isAuthenticated(req) && req.getAttribute(FiltersHelper.Constants.REQUEST_AUTH_RECORD_KEY) == null) { @SuppressWarnings("unchecked") Deque<String> stack = (Deque<String>) session.getAttribute(STACK_ATTR); if (stack == null) { stack = new ArrayDeque<String>(); for (AuthenticationProfile profile : profiles) { stack.push(profile.getName()); } session.setAttribute(STACK_ATTR, stack); } while (!stack.isEmpty()) { AuthenticationProfile profile = AuthenticationProfileRepository.getInstance().getProfile(stack.peek()); if (profile == null) { continue; } ExtMap output = profile.getAuthn().invoke( new ExtMap().mput( Base.InvokeKeys.COMMAND, Authn.InvokeCommands.AUTHENTICATE_NEGOTIATE ).mput( Authn.InvokeKeys.HTTP_SERVLET_REQUEST, req ).mput( Authn.InvokeKeys.HTTP_SERVLET_RESPONSE, rsp ) ); switch (output.<Integer> get(Authn.InvokeKeys.RESULT)) { case Authn.AuthResult.SUCCESS: ExtMap authRecord = output.<ExtMap> get(Authn.InvokeKeys.AUTH_RECORD); req.setAttribute(FiltersHelper.Constants.REQUEST_AUTH_RECORD_KEY, authRecord); req.setAttribute(FiltersHelper.Constants.REQUEST_PROFILE_KEY, profile); session.removeAttribute(STACK_ATTR); stack.clear(); break; case Authn.AuthResult.NEGOTIATION_UNAUTHORIZED: moveToNextProfile(session, stack); break; case Authn.AuthResult.NEGOTIATION_INCOMPLETE: break; default: log.error(String.format("Unexpected authentication result. AuthResult code is %1$s", output.<Integer> get(Authn.InvokeKeys.RESULT))); moveToNextProfile(session, stack); } } } } }

Target:
private void doAuth(HttpServletRequest req, HttpServletResponse rsp, FilterChain chain) throws IOException, ServletException { HttpSession session = req.getSession(false); if (session != null) { if (!FiltersHelper.isAuthenticated(req) && req.getAttribute(FiltersHelper.Constants.REQUEST_AUTH_RECORD_KEY) == null) { @SuppressWarnings("unchecked") Deque<String> stack = (Deque<String>) session.getAttribute(STACK_ATTR); if (stack == null) { stack = new ArrayDeque<String>(); for (AuthenticationProfile profile : profiles) { stack.push(profile.getName()); } session.setAttribute(STACK_ATTR, stack); } while (!stack.isEmpty()) { AuthenticationProfile profile = AuthenticationProfileRepository.getInstance().getProfile(stack.peek()); if (profile == null) { continue; } ExtMap output = profile.getAuthn().invoke( new ExtMap().mput( Base.InvokeKeys.COMMAND, Authn.InvokeCommands.AUTHENTICATE_NEGOTIATE ).mput( Authn.InvokeKeys.HTTP_SERVLET_REQUEST, req ).mput( Authn.InvokeKeys.HTTP_SERVLET_RESPONSE, rsp ) ); switch (output.<Integer> get(Authn.InvokeKeys.RESULT)) { case Authn.AuthResult.SUCCESS: ExtMap authRecord = output.<ExtMap> get(Authn.InvokeKeys.AUTH_RECORD); req.setAttribute(FiltersHelper.Constants.REQUEST_AUTH_RECORD_KEY, authRecord); req.setAttribute(FiltersHelper.Constants.REQUEST_PROFILE_KEY, profile); session.removeAttribute(STACK_ATTR); stack.clear(); break; case Authn.AuthResult.NEGOTIATION_UNAUTHORIZED: moveToNextProfile(session, stack); break; case Authn.AuthResult.NEGOTIATION_INCOMPLETE: break; default: log.error("Unexpected authentication result. AuthResult code is {}", output.<Integer> get(Authn.InvokeKeys.RESULT)); moveToNextProfile(session, stack); } } } } }