@Test public void Can_wrap_a_success_handler() { final UsernamePasswordAuthenticationFilter filter = mock(UsernamePasswordAuthenticationFilter.class); final AuthenticationSuccessHandler oldSuccessHandler = mock(AuthenticationSuccessHandler.class); final JwtAuthenticationSuccessHandler newSuccessHandler = mock(JwtAuthenticationSuccessHandler.class); // Given given(mutator.retrieve(filter, "successHandler", AuthenticationSuccessHandler.class)) .willReturn(oldSuccessHandler); given(successHandler.withDelegate(oldSuccessHandler)).willReturn(newSuccessHandler); // When successHandlerWrapper.modify(filter); // Then verify(filter).setAuthenticationSuccessHandler(newSuccessHandler); }
@Test public void Can_update_the_delegate() throws IOException, ServletException { final HttpServletRequest request = mock(HttpServletRequest.class); final HttpServletResponse response = mock(HttpServletResponse.class); final Authentication authentication = mock(Authentication.class); final AuthenticationSuccessHandler delegate = mock(AuthenticationSuccessHandler.class); // Given successHandler.withDelegate(delegate); // When successHandler.onAuthenticationSuccess(request, response, authentication); // Then final InOrder order = inOrder(authenticationApplier, delegate); order.verify(authenticationApplier).apply(authentication, response); order.verify(delegate).onAuthenticationSuccess(request, response, authentication); }
@Test public void Can_set_a_wrapped_authentication_success_handler() throws IllegalAccessException { final AuthenticationSuccessHandler newSuccessHandler = mock(AuthenticationSuccessHandler.class); final JwtAuthenticationSuccessHandler withSuccessHandler = mock(JwtAuthenticationSuccessHandler.class); // Given final Object successHandler = extractFiledValue(filter, "successHandler"); given(jwtSuccessHandler.withDelegate((AuthenticationSuccessHandler) successHandler)) .willReturn(withSuccessHandler); // When final WrappedUsernamePasswordAuthenticationFilter wrappedFilter = new WrappedUsernamePasswordAuthenticationFilter(reflectionFieldMutator, filter, jwtSuccessHandler); wrappedFilter.setAuthenticationSuccessHandler(newSuccessHandler); // Then verify(jwtSuccessHandler).withDelegate(newSuccessHandler); assertThat(wrappedFilter.getSuccessHandler(), is((AuthenticationSuccessHandler) withSuccessHandler)); }
@SuppressWarnings("ProhibitedExceptionDeclared") @Override public void customize(final HttpSecurity http, final AuthenticationManager authenticationManager) throws Exception { final AuthenticationSuccessHandler successHandler = new IdolLoginSuccessHandler( FindController.CONFIG_PATH, FindController.APP_PATH, FindRole.CONFIG.toString(), authenticationInformationRetriever ); http.formLogin() .loginPage(FindController.DEFAULT_LOGIN_PAGE) .loginProcessingUrl("/authenticate") .successHandler(successHandler) .failureUrl(FindController.DEFAULT_LOGIN_PAGE + "?error=auth"); }
public AgentLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler, AuthenticationFailureHandler failureHandler, ObjectMapper mapper) { super(defaultProcessUrl); this.successHandler = successHandler; this.failureHandler = failureHandler; this.objectMapper = mapper; }
protected AuthenticationSuccessHandler successHandler() { return new AuthenticationSuccessHandler() { @Override public void onAuthenticationSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException { httpServletResponse.getWriter().append("OK"); httpServletResponse.setStatus(200); } }; }
public AjaxLoginProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler, AuthenticationFailureHandler failureHandler, ObjectMapper mapper) { super(defaultProcessUrl); this.successHandler = successHandler; this.failureHandler = failureHandler; this.objectMapper = mapper; }
public AdminUserProcessingFilter(String defaultProcessUrl, AuthenticationSuccessHandler successHandler, AuthenticationFailureHandler failureHandler, ObjectMapper mapper) { super(defaultProcessUrl); this.successHandler = successHandler; this.failureHandler = failureHandler; this.objectMapper = mapper; }
@Autowired public ProfChoperSecurityConfig(@Qualifier("profChoperDataSource") DataSource dataSource, AccessDeniedHandler accessDeniedHandler, AuthenticationSuccessHandler successHandler) { this.dataSource = dataSource; this.accessDeniedHandler = accessDeniedHandler; this.successHandler = successHandler; }
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; }
@Override public void modify(final UsernamePasswordAuthenticationFilter filter) { filter.setAuthenticationSuccessHandler( successHandler.withDelegate( mutator.retrieve(filter, "successHandler", AuthenticationSuccessHandler.class) ) ); }
public CookieAndHeaderJwtAuthenticationSuccessHandler( JwtAuthenticationApplier authenticationApplier, AuthenticationSuccessHandler delegate ) { this.authenticationApplier = authenticationApplier; this.delegate = delegate; }
@Before @SuppressWarnings("unchecked") public void setUp() { delegate = mock(AuthenticationSuccessHandler.class); authenticationApplier = mock(JwtAuthenticationApplier.class); successHandler = new CookieAndHeaderJwtAuthenticationSuccessHandler(authenticationApplier, delegate); }
/** * Success login hander, adding cookie auth * * @return */ @Bean public AuthenticationSuccessHandler successHandler() { return new SavedRequestAwareAuthenticationSuccessHandler() { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { LOG.info("LOGIN >>> " + authentication.getPrincipal()); UserAuth userAuth = (UserAuth) authentication.getPrincipal(); apiAuth.put(userAuth, response); PrintWriter writer = response.getWriter(); mapper.writeValue(writer, userAuth); writer.flush(); } }; }
@Bean public AuthenticationSuccessHandler successHandler() { final CustomAuthenticationSuccessHandler authSuccessHandler = new CustomAuthenticationSuccessHandler(); authSuccessHandler.setDefaultTargetUrl(MAIN); authSuccessHandler.setTargetUrlParameter("targetUrl"); return authSuccessHandler; }
@Override public void setAuthenticationSuccessHandler(AuthenticationSuccessHandler successHandler) { if (!LoginFailuresClearingHandler.class.isAssignableFrom(successHandler.getClass())) { throw new IllegalArgumentException("Invalid login success handler. Handler must be an instance of " + LoginFailuresClearingHandler.class.getName() + " but is " + successHandler); } super.setAuthenticationSuccessHandler(successHandler); }
private OAuth2ClientAuthenticationProcessingFilter createSsoFilter(ClientResourceDetails clientDetails, AuthenticationSuccessHandler successHandler, String path) { OAuth2ClientAuthenticationProcessingFilter ssoFilter = new OAuth2ClientAuthenticationProcessingFilter(path); ssoFilter.setAllowSessionCreation(false); OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(clientDetails.getClient(), oAuth2ClientContext); ssoFilter.setRestTemplate(restTemplate); ssoFilter.setTokenServices(new UserInfoTokenServices(clientDetails.getResource().getUserInfoUri(), clientDetails.getClient().getClientId())); ssoFilter.setAuthenticationSuccessHandler(successHandler); return ssoFilter; }
@Before public void setUp() throws Exception { mockRequest = new MockHttpServletRequest(); mockRequest.addHeader("X-Requested-With", "XMLHttpRequest"); mockResponse = new MockHttpServletResponse(); delegateSuccessHandler = mock(AuthenticationSuccessHandler.class); ajaxAuthenticationSuccessHandler = new AjaxAuthenticationSuccessHandler(delegateSuccessHandler); }
private AuthenticationSuccessHandler getSuccessHandler() { RedirectingAuthenticationSuccessHandler successHandler = new RedirectingAuthenticationSuccessHandler( "/"); successHandler.setDefaultTargetUrl("/index.html"); successHandler.setTargetUrlParameter("redirect"); return successHandler; }
@SuppressWarnings("ProhibitedExceptionDeclared") @Override protected void configure(final HttpSecurity http) throws Exception { final AuthenticationSuccessHandler loginSuccessHandler = new LoginSuccessHandler(FindRole.CONFIG.toString(), FindController.CONFIG_PATH, "/p/"); final HttpSessionRequestCache requestCache = new HttpSessionRequestCache(); requestCache.setRequestMatcher(new OrRequestMatcher( new AntPathRequestMatcher("/p/**"), new AntPathRequestMatcher(FindController.CONFIG_PATH) )); http.regexMatcher("/p/.*|/config/.*|/authenticate|/logout") .authorizeRequests() .antMatchers("/p/**").hasRole(FindRole.ADMIN.name()) .antMatchers(FindController.CONFIG_PATH).hasRole(FindRole.CONFIG.name()) .and() .requestCache() .requestCache(requestCache) .and() .formLogin() .loginPage(FindController.DEFAULT_LOGIN_PAGE) .loginProcessingUrl("/authenticate") .successHandler(loginSuccessHandler) .failureUrl(FindController.DEFAULT_LOGIN_PAGE + "?error=auth") .and() .logout() .logoutSuccessHandler(new HodLogoutSuccessHandler(new HodTokenLogoutSuccessHandler(SsoController.SSO_LOGOUT_PAGE, tokenRepository), FindController.APP_PATH)) .and() .csrf() .disable(); }
@Override public void afterPropertiesSet() throws Exception { try{ Map<String,AuthenticationSuccessHandler> beans = applicationContext.getBeansOfType(AuthenticationSuccessHandler.class); for(AuthenticationSuccessHandler h : beans.values()){ if(! ClassUtils.isAssignableValue(getClass(), h)){ this.handler = h; break; } } }catch(Exception e){ logger.debug("", e); } }
@Bean public AuthenticationSuccessHandler authenticationSuccessHandler() { return new AuthenticationSuccessHandlerImpl(); }
@Bean public AuthenticationSuccessHandler authenticationSuccessHandler() { return (req, res, aut) -> res.setStatus(HttpServletResponse.SC_OK); }
@Bean public AuthenticationSuccessHandler authenticationSuccessHandlerImpl() { return new AuthenticationSuccessHandlerRestImpl(); }
@Override public void setAuthenticationSuccessHandler(AuthenticationSuccessHandler successHandler) { this.successHandler = successHandler; }
@Bean public AuthenticationSuccessHandler authenticationSuccessHandler( JwtTokenService jwtTokenService) { return new DefaultAuthenticationSuccessHandler(jwtTokenService); }
public AuthenticationSuccessHandler getSuccessHandler() { return successHandler; }
public void setSuccessHandler(AuthenticationSuccessHandler successHandler) { this.successHandler = successHandler; }
@Bean public AuthenticationSuccessHandler authenticationSuccessHandler() { return new CustomAuthenticationSuccessHandler(); }
@Bean public AuthenticationSuccessHandler successHandler() { return new LoginSuccessHandler("/"); }
public AuthenticationSuccessHandler authenticationSuccessHandler() { SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler(); successHandler.setRedirectStrategy(new XForwardedAwareRedirectStrategy()); return successHandler; }
@Bean public AuthenticationSuccessHandler authenticationSuccessHandler() { return new AjaxAuthenticationSuccessHandler("/"); }
@Override public JwtAuthenticationSuccessHandler withDelegate(AuthenticationSuccessHandler delegate) { this.delegate = delegate; return this; }