public AuthenticationFailureHandler failureLogin(){ AuthenticationFailureHandler handler = new AuthenticationFailureHandler() { @Override public void onAuthenticationFailure(HttpServletRequest arg0, HttpServletResponse arg1, AuthenticationException arg2) throws IOException, ServletException { System.out.println("SecurityConfig.failureLogin()#httpservletrequest\n" + ReflectionToStringBuilder.toString(arg0, ToStringStyle.SIMPLE_STYLE) + "\n----------------" + "\ngetQueryString: " + arg0.getQueryString() + "\ngetRequestURI: " + arg0.getRequestURI() + "\ngetServletPath: " + arg0.getServletPath() + "\ngetRequestURL: " + arg0.getRequestURL() + "\n\n" ); arg1.setStatus(HttpServletResponse.SC_UNAUTHORIZED); arg1.sendRedirect("login"); } }; return handler; }
public JwtTokenAuthenticationProcessingFilter( AuthenticationFailureHandler failureHandler, TokenExtractor tokenExtractor, RequestMatcher matcher) { super(matcher); this.failureHandler = failureHandler; this.tokenExtractor = tokenExtractor; }
@Bean public AuthenticationFailureHandler authenticationFailureHandler() { ExceptionMappingAuthenticationFailureHandler failureHandler = new ExceptionMappingAuthenticationFailureHandler(); Map<String, String> failureUrlMap = new HashMap<>(); failureUrlMap.put(BadCredentialsException.class.getName(), LoginAuthenticationFailureHandler.PASS_ERROR_URL); failureUrlMap.put(CaptchaException.class.getName(), LoginAuthenticationFailureHandler.CODE_ERROR_URL); failureUrlMap.put(AccountExpiredException.class.getName(), LoginAuthenticationFailureHandler.EXPIRED_URL); failureUrlMap.put(LockedException.class.getName(), LoginAuthenticationFailureHandler.LOCKED_URL); failureUrlMap.put(DisabledException.class.getName(), LoginAuthenticationFailureHandler.DISABLED_URL); failureHandler.setExceptionMappings(failureUrlMap); return failureHandler; }
public AgentLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler, AuthenticationFailureHandler failureHandler, ObjectMapper mapper) { super(defaultProcessUrl); this.successHandler = successHandler; this.failureHandler = failureHandler; this.objectMapper = mapper; }
@Autowired public JwtTokenAuthenticationProcessingFilter(RequestMatcher matcher, AuthenticationFailureHandler failureHandler, JwtTokenUtil jwtTokenUtil) { super(matcher); this.failureHandler = failureHandler; this.jwtTokenUtil = jwtTokenUtil; }
protected AuthenticationFailureHandler failureHandler() { return new AuthenticationFailureHandler() { @Override public void onAuthenticationFailure(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, AuthenticationException e) throws IOException, ServletException { httpServletResponse.getWriter().append("Authentication failure"); httpServletResponse.setStatus(401); } }; }
public AjaxLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler, AuthenticationFailureHandler failureHandler, ObjectMapper mapper) { super(defaultProcessUrl); this.successHandler = successHandler; this.failureHandler = failureHandler; this.objectMapper = mapper; }
@Autowired public JwtTokenAuthenticationProcessingFilter(AuthenticationFailureHandler failureHandler, TokenExtractor tokenExtractor, RequestMatcher matcher) { super(matcher); this.failureHandler = failureHandler; this.tokenExtractor = tokenExtractor; }
public AdminUserProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler, AuthenticationFailureHandler failureHandler, ObjectMapper mapper) { super(defaultProcessUrl); this.successHandler = successHandler; this.failureHandler = failureHandler; this.objectMapper = mapper; }
public RefreshTokenProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler, AuthenticationFailureHandler failureHandler, ObjectMapper mapper) { super(defaultProcessUrl); this.successHandler = successHandler; this.failureHandler = failureHandler; this.objectMapper = mapper; }
public RestPublicLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler, AuthenticationFailureHandler failureHandler, ObjectMapper mapper) { super(defaultProcessUrl); this.successHandler = successHandler; this.failureHandler = failureHandler; this.objectMapper = mapper; }
public RestLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler, AuthenticationFailureHandler failureHandler, ObjectMapper mapper) { super(defaultProcessUrl); this.successHandler = successHandler; this.failureHandler = failureHandler; this.objectMapper = mapper; }
public OneTimePasswordFilterConfigurer(final String loginProcessingUrl, AuthenticationSuccessHandler successHandler, AuthenticationFailureHandler failureHandler, AuthenticationEntryPoint entryPoint) { this.authFilter = new OneTimePasswordAuthenticationFilter(loginProcessingUrl); this.authFilter.setRequiresAuthenticationRequestMatcher(new AntPathRequestMatcher(loginProcessingUrl, "POST")); this.authFilter.setAuthenticationSuccessHandler(successHandler); this.authFilter.setAuthenticationFailureHandler(failureHandler); this.authFilter.setAllowSessionCreation(true); this.authenticationEntryPoint = entryPoint; }
/** * Failed login handler, returning a 401 code instead of a login page * * @return */ @Bean public AuthenticationFailureHandler failureHandler() { return new SimpleUrlAuthenticationFailureHandler() { @Override public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { LOG.warn("LOGIN >>> authentication failure"); response.sendError(HttpServletResponse.SC_UNAUTHORIZED, exception.getMessage()); } }; }
@Bean public AuthenticationFailureHandler failureHandler() { final CustomAuthenticationFailureHandler authFailureHandler = new CustomAuthenticationFailureHandler(); authFailureHandler.setDefaultFailureUrl("/welcome?error"); return authFailureHandler; }
@Override public void setAuthenticationFailureHandler(AuthenticationFailureHandler failureHandler) { if (!LoginFailuresCountingHandler.class.isAssignableFrom(failureHandler.getClass())) { throw new IllegalArgumentException("Invalid login failure handler. Handler must be an instance of " + LoginFailuresCountingHandler.class.getName() + " but is " + failureHandler); } super.setAuthenticationFailureHandler(failureHandler); }
@Before public void setUp() throws Exception { mockRequest = new MockHttpServletRequest(); mockRequest.addHeader("X-Requested-With", "XMLHttpRequest"); mockResponse = new MockHttpServletResponse(); delegateFailureHandler = mock(AuthenticationFailureHandler.class); ajaxAuthenticationFailureHandler = new AjaxAuthenticationFailureHandler(delegateFailureHandler); }
@Before public void setUp() throws Exception { mockAuthenticationManager = mock(AuthenticationManager.class); mockFailureHandler = mock(AuthenticationFailureHandler.class); mockVistaAccountDao = mock(IVistaAccountDao.class); f = new CprsSsoVistaAuthenticationFilter(); f.setFilterProcessesUrl("/welcome.jsp"); f.setAuthenticationFailureHandler(mockFailureHandler); f.setAuthenticationManager(mockAuthenticationManager); f.setVistaAccountDao(mockVistaAccountDao); f.afterPropertiesSet(); }
@Override public void afterPropertiesSet() throws Exception { try{ Map<String,AuthenticationFailureHandler> beans = applicationContext.getBeansOfType(AuthenticationFailureHandler.class); for(AuthenticationFailureHandler h : beans.values()){ if(! ClassUtils.isAssignableValue(getClass(), h)){ this.handler = h; break; } } }catch(Exception e){ logger.debug("", e); } }
@Override public void afterPropertiesSet() { super.afterPropertiesSet(); ((SavedRequestAwareAuthenticationSuccessHandler) getSuccessHandler()).setAlwaysUseDefaultTargetUrl(false); setAuthenticationFailureHandler(new AuthenticationFailureHandler() { public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException { requestCache.saveRequest(request, response); authenticationEntryPoint.commence(request, response, exception); } }); }
@Test public void filterUsesConfiguredFailureHandler() throws Exception { final Field failureHandlerField = AbstractAuthenticationProcessingFilter.class.getDeclaredField("failureHandler"); ReflectionUtils.makeAccessible(failureHandlerField); AuthenticationFailureHandler failureHandler = (AuthenticationFailureHandler) ReflectionUtils.getField(failureHandlerField, filter); assertTrue("failure handler should be a simpleUrlFailureHandler", failureHandler instanceof SimpleUrlAuthenticationFailureHandler); final Field failureUrlField = SimpleUrlAuthenticationFailureHandler.class.getDeclaredField("defaultFailureUrl"); ReflectionUtils.makeAccessible(failureUrlField); String failureUrl = (String) ReflectionUtils.getField(failureUrlField, failureHandler); assertEquals("failure URL should be the configured url", "/oauth/confirm_access", failureUrl); }
@Bean public AuthenticationFailureHandler authenticationFailureHandler() { return new AuthenticationFailureHandlerImpl(); }
@Bean public AuthenticationFailureHandler authenticationFailureHandler() { return new SimpleUrlAuthenticationFailureHandler(); }
@Bean public AuthenticationFailureHandler authenticationFailureHandler() { return (req, res, arg2) -> res.sendError(HttpServletResponse.SC_FORBIDDEN, "Access Denied"); }
@Bean public AuthenticationFailureHandler authenticationFailureHandlerImpl() { return new AuthenticationFailureHandlerRestImpl(); }
@Bean public AuthenticationFailureHandler authenticationFailureHandler(ObjectMapper objectMapper) { return new DefaultAuthenticationFailureHandler(objectMapper); }
public AuthenticationFailureHandler getFailureHandler() { return failureHandler; }
public void setFailureHandler(AuthenticationFailureHandler failureHandler) { this.failureHandler = failureHandler; }
@Bean public AuthenticationFailureHandler authenticationFailureHandler() { return new CustomAuthenticationFailureHandler(); }
private AuthenticationFailureHandler failureHandler() { final String defaultFailureUrl = "/login?error"; RedirectStrategy redirectStrategy = new FailureRedirectStrategy(); return (request, response, exception) -> redirectStrategy.sendRedirect(request, response, defaultFailureUrl); }
@Bean public AuthenticationFailureHandler authenticationFailureHandler() { return new ClientAwareAuthenticationFailureHandler("/login?error"); }
@Bean public AuthenticationFailureHandler authenticationFailureHandler() { return new UserNameCachingAuthenticationFailureHandler(); }
@Bean public AuthenticationFailureHandler loginFailureHandler() { return new LoginFailureHandler(); }