org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler Java Examples

The following examples show how to use org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SecurityConfiguration.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
private RequestHeaderAuthenticationFilter requestHeaderAuthenticationFilter() throws Exception {
    RequestHeaderAuthenticationFilter f = new RequestHeaderAuthenticationFilter();
    f.setPrincipalRequestHeader("X-Forwarded-User");
    f.setCredentialsRequestHeader("X-Forwarded-Access-Token");
    f.setAuthenticationManager(authenticationManager());
    f.setAuthenticationDetailsSource(
        (AuthenticationDetailsSource<HttpServletRequest, PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails>)
            (request) ->new PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails(
                request,
                AuthorityUtils.createAuthorityList("ROLE_AUTHENTICATED")
            )
    );
    f.setAuthenticationFailureHandler(new SimpleUrlAuthenticationFailureHandler());
    f.setExceptionIfHeaderMissing(false);
    return f;
}
 
Example #2
Source File: SecurityConfig.java    From Spring-Security-Third-Edition with MIT License 6 votes vote down vote up
/**
 *
 * @return
 * @throws Exception
 */
@Bean
public DomainUsernamePasswordAuthenticationFilter domainUsernamePasswordAuthenticationFilter()
        throws Exception {
    DomainUsernamePasswordAuthenticationFilter dupaf = new DomainUsernamePasswordAuthenticationFilter(
                                                            super.authenticationManagerBean());
    dupaf.setFilterProcessesUrl("/login");
    dupaf.setUsernameParameter("username");
    dupaf.setPasswordParameter("password");

    dupaf.setAuthenticationSuccessHandler(
            new SavedRequestAwareAuthenticationSuccessHandler(){{
                setDefaultTargetUrl("/default");
            }}
    );

    dupaf.setAuthenticationFailureHandler(
            new SimpleUrlAuthenticationFailureHandler(){{
                setDefaultFailureUrl("/login/form?error");
            }}
    );

    dupaf.afterPropertiesSet();

    return dupaf;
}
 
Example #3
Source File: SecurityConfig.java    From microservices-platform with Apache License 2.0 5 votes vote down vote up
@Bean
public TenantUsernamePasswordAuthenticationFilter tenantAuthenticationFilter(AuthenticationManager authenticationManager) {
	TenantUsernamePasswordAuthenticationFilter filter = new TenantUsernamePasswordAuthenticationFilter();
	filter.setAuthenticationManager(authenticationManager);
	filter.setFilterProcessesUrl(SecurityConstants.OAUTH_LOGIN_PRO_URL);
	filter.setAuthenticationSuccessHandler(authenticationSuccessHandler);
	filter.setAuthenticationFailureHandler(new SimpleUrlAuthenticationFailureHandler(SecurityConstants.LOGIN_FAILURE_PAGE));
	return filter;
}
 
Example #4
Source File: InsightsSecurityConfigurationAdapterSAML.java    From Insights with Apache License 2.0 5 votes vote down vote up
/**
 * Used to handle logout senerio if unautheticated
 * 
 * @return
 */
@Bean
@Conditional(InsightsSAMLBeanInitializationCondition.class)
public SimpleUrlAuthenticationFailureHandler authenticationFailureHandler() {
	LOG.debug(" Inside authenticationFailureHandler ==== ");
	return new InsightsSimpleUrlAuthenticationFailureHandler("/insightsso/logout");
}
 
Example #5
Source File: BaseWebSecurityConfig.java    From jump-the-queue with Apache License 2.0 5 votes vote down vote up
/**
 * Create a simple authentication filter for REST logins that reads user-credentials from a json-parameter and returns
 * status 200 instead of redirect after login.
 *
 * @return the {@link JsonUsernamePasswordAuthenticationFilter}.
 * @throws Exception if something goes wrong.
 */
protected JsonUsernamePasswordAuthenticationFilter getSimpleRestAuthenticationFilter() throws Exception {

  JsonUsernamePasswordAuthenticationFilter jsonFilter = new JsonUsernamePasswordAuthenticationFilter(
      new AntPathRequestMatcher("/services/rest/login"));
  jsonFilter.setPasswordParameter("j_password");
  jsonFilter.setUsernameParameter("j_username");
  jsonFilter.setAuthenticationManager(authenticationManager());
  // set failurehandler that uses no redirect in case of login failure; just HTTP-status: 401
  jsonFilter.setAuthenticationManager(authenticationManagerBean());
  jsonFilter.setAuthenticationFailureHandler(new SimpleUrlAuthenticationFailureHandler());
  // set successhandler that uses no redirect in case of login success; just HTTP-status: 200
  jsonFilter.setAuthenticationSuccessHandler(new AuthenticationSuccessHandlerSendingOkHttpStatusCode());
  return jsonFilter;
}
 
Example #6
Source File: WebSecurityConfig.java    From spring-boot-security-saml-sample with Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleUrlAuthenticationFailureHandler authenticationFailureHandler() {
 	SimpleUrlAuthenticationFailureHandler failureHandler =
 			new SimpleUrlAuthenticationFailureHandler();
 	failureHandler.setUseForward(true);
 	failureHandler.setDefaultFailureUrl("/error");
 	return failureHandler;
}
 
Example #7
Source File: SAMLConfig.java    From spring-boot-security-saml-samples with MIT License 5 votes vote down vote up
@Bean
public SimpleUrlAuthenticationFailureHandler authenticationFailureHandler() {
    SimpleUrlAuthenticationFailureHandler handler = new SimpleUrlAuthenticationFailureHandler();
    handler.setUseForward(false);
    //handler.setDefaultFailureUrl("/error");
    return handler;
}
 
Example #8
Source File: WebSecurityConfig.java    From spring-tsers-auth with Apache License 2.0 5 votes vote down vote up
@Bean
public SimpleUrlAuthenticationFailureHandler authenticationFailureHandler() {
    SimpleUrlAuthenticationFailureHandler failureHandler =
            new SimpleUrlAuthenticationFailureHandler();
    failureHandler.setUseForward(true);
    failureHandler.setDefaultFailureUrl("/login");
    return failureHandler;
}
 
Example #9
Source File: WebSecurityConfig.java    From spring-tsers-auth with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure(HttpSecurity http) throws Exception {

    http
            .csrf()
            .disable();
    http
            .addFilterBefore(metadataGeneratorFilter(), ChannelProcessingFilter.class)
            .addFilterAfter(samlFilter(), BasicAuthenticationFilter.class);
    http
            .authorizeRequests()
            .antMatchers("/").permitAll()
            .antMatchers("/error").permitAll()
            .antMatchers("/saml/**").permitAll()
            .antMatchers("/css/**").permitAll()
            .anyRequest().authenticated();

    http
            .exceptionHandling().accessDeniedHandler(new AccessDeniedHandlerImpl())
            .authenticationEntryPoint(getAuthEntryPoint())
            .and()
            .formLogin()
            .loginProcessingUrl("/authenticate")
            .usernameParameter("username")
            .passwordParameter("password")
            .successHandler(new FormAuthSuccessHandler())
            .failureHandler(new SimpleUrlAuthenticationFailureHandler())
            .and()
            .logout()
            .logoutUrl("/logout")
            .logoutSuccessUrl("/")
            .permitAll();
}
 
Example #10
Source File: MavenArtifactNotifierWebappSecurityConfig.java    From artifact-listener with Apache License 2.0 4 votes vote down vote up
@Bean
public SimpleUrlAuthenticationFailureHandler pac4jAuthenticationFailureHandler() {
	return new Pac4jAuthenticationFailureHandler();
}
 
Example #11
Source File: JWTRequestParameterProcessingFilter.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
protected JWTRequestParameterProcessingFilter(AuthenticationManager authenticationManager, String failureUrl) {
    this.authenticationManager = authenticationManager;
    failureHandler = new SimpleUrlAuthenticationFailureHandler(failureUrl);
}
 
Example #12
Source File: SecurityConfig.java    From tutorials with MIT License 4 votes vote down vote up
public SimpleUrlAuthenticationFailureHandler failureHandler() {
    return new SimpleUrlAuthenticationFailureHandler("/login?error=true");
}
 
Example #13
Source File: SecurityConfig.java    From tutorials with MIT License 4 votes vote down vote up
public SimpleUrlAuthenticationFailureHandler failureHandler() {
    return new SimpleUrlAuthenticationFailureHandler("/login?error=true");
}
 
Example #14
Source File: FederationAuthenticationFilter.java    From cxf-fediz with Apache License 2.0 4 votes vote down vote up
public FederationAuthenticationFilter() {
    super("/j_spring_fediz_security_check");
    setAuthenticationFailureHandler(new SimpleUrlAuthenticationFailureHandler());
}
 
Example #15
Source File: WallRideSecurityConfiguration.java    From wallride with Apache License 2.0 4 votes vote down vote up
@Override
		protected void configure(HttpSecurity http) throws Exception {
			RedirectStrategy redirectStrategy = new BlogLanguageRedirectStrategy();

			SavedRequestAwareAuthenticationSuccessHandler successHandler = new SavedRequestAwareAuthenticationSuccessHandler();
			successHandler.setRedirectStrategy(redirectStrategy);
			successHandler.setDefaultTargetUrl("/");

			SimpleUrlAuthenticationFailureHandler failureHandler = new SimpleUrlAuthenticationFailureHandler("/login?failed");
			failureHandler.setRedirectStrategy(redirectStrategy);

			SimpleUrlLogoutSuccessHandler logoutSuccessHandler = new SimpleUrlLogoutSuccessHandler();
			logoutSuccessHandler.setRedirectStrategy(redirectStrategy);
			logoutSuccessHandler.setDefaultTargetUrl("/");

			// @formatter:off
			http.antMatcher("/**")
				.authorizeRequests()
					.accessDecisionManager(accessDecisionManager)
//		            .expressionHandler(securityExpressionHandler)
					.antMatchers("/settings/**").hasRole("VIEWER")
					.antMatchers("/comments/**").hasRole("VIEWER")
					.and()
				.formLogin()
					.loginPage("/login").permitAll()
					.loginProcessingUrl("/login")
					.successHandler(successHandler)
					.failureHandler(failureHandler)
					.and()
				.logout()
					.logoutRequestMatcher(new AntPathRequestMatcher("/logout", "GET"))
					.logoutSuccessHandler(logoutSuccessHandler)
					.and()
				.rememberMe()
					.tokenRepository(persistentTokenRepository)
					.and()
				.headers()
					.frameOptions().disable()
					.cacheControl().disable()
					.httpStrictTransportSecurity().disable()
					.and()
				.csrf()
					.disable()
				.exceptionHandling()
					.accessDeniedPage("/login");
			// @formatter:on
		}
 
Example #16
Source File: SecurityConfiguration.java    From secure-rest-spring-tut with MIT License 4 votes vote down vote up
@Bean
public SimpleUrlAuthenticationFailureHandler authenticationFailureHandler() {
	return new SimpleUrlAuthenticationFailureHandler();
}
 
Example #17
Source File: SSOConfigurerTest.java    From spring-boot-security-saml with MIT License 4 votes vote down vote up
@Test
public void configure_custom_noHoK() throws Exception {
    SSOConfigurer configurer = spy(new SSOConfigurer());
    SAMLProcessingFilter ssoFilter = mock(SAMLProcessingFilter.class);
    when(configurer.createDefaultSamlProcessingFilter()).thenReturn(ssoFilter);
    SAMLWebSSOHoKProcessingFilter ssoHoKFilter = mock(SAMLWebSSOHoKProcessingFilter.class);
    when(configurer.createDefaultSamlHoKProcessingFilter()).thenReturn(ssoHoKFilter);
    SAMLDiscovery discoveryFilter = mock(SAMLDiscovery.class);
    when(configurer.createDefaultSamlDiscoveryFilter()).thenReturn(discoveryFilter);
    SAMLEntryPoint entryPoint = mock(SAMLEntryPoint.class);
    when(configurer.createDefaultSamlEntryPoint()).thenReturn(entryPoint);
    SavedRequestAwareAuthenticationSuccessHandler successHandler = mock(SavedRequestAwareAuthenticationSuccessHandler.class);
    SimpleUrlAuthenticationFailureHandler failureHandler = mock(SimpleUrlAuthenticationFailureHandler.class);
    WebSSOProfileOptions profileOptions = mock(WebSSOProfileOptions.class);

    configurer.init(builder);
    configurer
            .defaultSuccessURL("/success")
            .failureHandler(failureHandler)
            .successHandler(successHandler)
            .defaultFailureURL("/failure")
            .discoveryProcessingURL("/discovery")
            .enableSsoHoK(false)
            .idpSelectionPageURL("/idp")
            .profileOptions(profileOptions)
            .ssoHoKProcessingURL("/hok")
            .ssoLoginURL("/login")
            .ssoProcessingURL("/sso");
    configurer.configure(builder);

    verify(properties, never()).getDefaultFailureUrl();
    verify(properties, never()).getDefaultSuccessUrl();
    verify(properties, never()).getDiscoveryProcessingUrl();
    verify(properties, never()).getIdpSelectionPageUrl();
    verify(properties, never()).getSsoHokProcessingUrl();
    verify(properties, never()).getSsoLoginUrl();
    verify(properties, never()).getSsoProcessingUrl();
    verify(properties, never()).getProfileOptions();

    verify(successHandler, never()).setDefaultTargetUrl(eq("/success"));
    verify(failureHandler, never()).setDefaultFailureUrl(eq("/failure"));

    verify(ssoFilter).setAuthenticationManager(eq(authenticationManager));
    verify(ssoFilter).setAuthenticationSuccessHandler(eq(successHandler));
    verify(ssoFilter).setAuthenticationFailureHandler(eq(failureHandler));
    verify(ssoFilter).setFilterProcessesUrl(eq("/sso"));

    verify(ssoHoKFilter, never()).setAuthenticationManager(eq(authenticationManager));
    verify(ssoHoKFilter, never()).setAuthenticationSuccessHandler(eq(successHandler));
    verify(ssoHoKFilter, never()).setAuthenticationFailureHandler(eq(failureHandler));
    verify(ssoHoKFilter, never()).setFilterProcessesUrl(eq("/hok"));

    verify(serviceProviderEndpoints).setSsoProcessingURL("/sso");
    verify(serviceProviderEndpoints, never()).setSsoHoKProcessingURL("/hok");
    verify(serviceProviderEndpoints).setDefaultFailureURL("/failure");
    verify(serviceProviderEndpoints).setDiscoveryProcessingURL("/discovery");
    verify(serviceProviderEndpoints).setIdpSelectionPageURL("/idp");
    verify(serviceProviderEndpoints).setSsoLoginURL("/login");

    verify(discoveryFilter).setFilterProcessesUrl(eq("/discovery"));
    verify(discoveryFilter).setIdpSelectionPath(eq("/idp"));

    verify(entryPoint).setFilterProcessesUrl(eq("/login"));
    verify(entryPoint).setDefaultProfileOptions(eq(profileOptions));

    verify(builder).setSharedObject(eq(SAMLProcessingFilter.class), eq(ssoFilter));
    verify(builder).setSharedObject(eq(SAMLWebSSOHoKProcessingFilter.class), eq(null));
    verify(builder).setSharedObject(eq(SAMLDiscovery.class), eq(discoveryFilter));
    verify(builder).setSharedObject(eq(SAMLEntryPoint.class), eq(entryPoint));

}
 
Example #18
Source File: SSOConfigurerTest.java    From spring-boot-security-saml with MIT License 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void configure_custom_entry_point() throws Exception {
    SSOConfigurer configurer = spy(new SSOConfigurer());
    SAMLProcessingFilter ssoFilter = mock(SAMLProcessingFilter.class);
    when(configurer.createDefaultSamlProcessingFilter()).thenReturn(ssoFilter);
    SAMLWebSSOHoKProcessingFilter ssoHoKFilter = mock(SAMLWebSSOHoKProcessingFilter.class);
    when(configurer.createDefaultSamlHoKProcessingFilter()).thenReturn(ssoHoKFilter);
    SAMLDiscovery discoveryFilter = mock(SAMLDiscovery.class);
    when(configurer.createDefaultSamlDiscoveryFilter()).thenReturn(discoveryFilter);
    when(configurer.createDefaultSamlEntryPoint()).thenThrow(IllegalStateException.class);
    SavedRequestAwareAuthenticationSuccessHandler successHandler = mock(SavedRequestAwareAuthenticationSuccessHandler.class);
    SimpleUrlAuthenticationFailureHandler failureHandler = mock(SimpleUrlAuthenticationFailureHandler.class);
    WebSSOProfileOptions profileOptions = new WebSSOProfileOptions();
    profileOptions.setAllowCreate(true);
    profileOptions.setAllowedIDPs(Collections.singleton("allowedIdps"));
    profileOptions.setAssertionConsumerIndex(999);
    profileOptions.setAuthnContextComparison(AuthnContextComparisonTypeEnumeration.MINIMUM);
    profileOptions.setAuthnContexts(Collections.singleton("contexts"));
    profileOptions.setBinding("binding");
    profileOptions.setForceAuthN(true);
    profileOptions.setIncludeScoping(true);
    profileOptions.setNameID("nameId");
    profileOptions.setPassive(true);
    profileOptions.setProviderName("providerName");
    profileOptions.setProxyCount(null);
    profileOptions.setRelayState("relayState");

    SAMLEntryPoint customEntryPoint = mock(SAMLEntryPoint.class);
    configurer.init(builder);
    configurer
            .defaultSuccessURL("/success")
            .failureHandler(failureHandler)
            .successHandler(successHandler)
            .defaultFailureURL("/failure")
            .discoveryProcessingURL("/discovery")
            .enableSsoHoK(true)
            .idpSelectionPageURL("/idp")
            .profileOptions(profileOptions)
            .ssoHoKProcessingURL("/hok")
            .ssoLoginURL("/login")
            .ssoProcessingURL("/sso")
            .samlEntryPoint(customEntryPoint);
    configurer.configure(builder);

    verify(properties, never()).getDefaultFailureUrl();
    verify(properties, never()).getDefaultSuccessUrl();
    verify(properties, never()).getDiscoveryProcessingUrl();
    verify(properties, never()).getIdpSelectionPageUrl();
    verify(properties, never()).getSsoHokProcessingUrl();
    verify(properties, never()).getSsoLoginUrl();
    verify(properties, never()).getSsoProcessingUrl();
    verify(properties, never()).getProfileOptions();

    verify(successHandler, never()).setDefaultTargetUrl(eq("/success"));
    verify(failureHandler, never()).setDefaultFailureUrl(eq("/failure"));

    verify(ssoFilter).setAuthenticationManager(eq(authenticationManager));
    verify(ssoFilter).setAuthenticationSuccessHandler(eq(successHandler));
    verify(ssoFilter).setAuthenticationFailureHandler(eq(failureHandler));
    verify(ssoFilter).setFilterProcessesUrl(eq("/sso"));

    verify(ssoHoKFilter).setAuthenticationManager(eq(authenticationManager));
    verify(ssoHoKFilter).setAuthenticationSuccessHandler(eq(successHandler));
    verify(ssoHoKFilter).setAuthenticationFailureHandler(eq(failureHandler));
    verify(ssoHoKFilter).setFilterProcessesUrl(eq("/hok"));

    verify(serviceProviderEndpoints).setSsoProcessingURL("/sso");
    verify(serviceProviderEndpoints).setSsoHoKProcessingURL("/hok");
    verify(serviceProviderEndpoints).setDefaultFailureURL("/failure");
    verify(serviceProviderEndpoints).setDiscoveryProcessingURL("/discovery");
    verify(serviceProviderEndpoints).setIdpSelectionPageURL("/idp");
    verify(serviceProviderEndpoints).setSsoLoginURL("/login");

    verify(discoveryFilter).setFilterProcessesUrl(eq("/discovery"));
    verify(discoveryFilter).setIdpSelectionPath(eq("/idp"));

    verify(customEntryPoint).setFilterProcessesUrl(eq("/login"));
    ArgumentCaptor<WebSSOProfileOptions> optionsCaptor = ArgumentCaptor.forClass(WebSSOProfileOptions.class);
    verify(customEntryPoint).setDefaultProfileOptions(optionsCaptor.capture());
    WebSSOProfileOptions options = optionsCaptor.getValue();
    Assertions.assertThat(options.isAllowCreate()).isEqualTo(true);
    Assertions.assertThat(options.getAllowedIDPs()).containsExactly("allowedIdps");
    Assertions.assertThat(options.getAssertionConsumerIndex()).isEqualTo(999);
    Assertions.assertThat(options.getAuthnContextComparison()).isEqualTo(AuthnContextComparisonTypeEnumeration.MINIMUM);
    Assertions.assertThat(options.getAuthnContexts()).containsExactly("contexts");
    Assertions.assertThat(options.getBinding()).isEqualTo("binding");
    Assertions.assertThat(options.getForceAuthN()).isEqualTo(true);
    Assertions.assertThat(options.isIncludeScoping()).isEqualTo(true);
    Assertions.assertThat(options.getNameID()).isEqualTo("nameId");
    Assertions.assertThat(options.getPassive()).isEqualTo(true);
    Assertions.assertThat(options.getProviderName()).isEqualTo("providerName");
    Assertions.assertThat(options.getProxyCount()).isEqualTo(null);
    Assertions.assertThat(options.getRelayState()).isEqualTo("relayState");

    verify(builder).setSharedObject(eq(SAMLProcessingFilter.class), eq(ssoFilter));
    verify(builder).setSharedObject(eq(SAMLWebSSOHoKProcessingFilter.class), eq(ssoHoKFilter));
    verify(builder).setSharedObject(eq(SAMLDiscovery.class), eq(discoveryFilter));
    verify(builder).setSharedObject(eq(SAMLEntryPoint.class), eq(customEntryPoint));

}
 
Example #19
Source File: SSOConfigurerTest.java    From spring-boot-security-saml with MIT License 4 votes vote down vote up
@Test
public void configure_defaults() throws Exception {
    SSOConfigurer configurer = spy(new SSOConfigurer());
    SAMLProcessingFilter ssoFilter = mock(SAMLProcessingFilter.class);
    when(configurer.createDefaultSamlProcessingFilter()).thenReturn(ssoFilter);
    SAMLWebSSOHoKProcessingFilter ssoHoKFilter = mock(SAMLWebSSOHoKProcessingFilter.class);
    when(configurer.createDefaultSamlHoKProcessingFilter()).thenReturn(ssoHoKFilter);
    SAMLDiscovery discoveryFilter = mock(SAMLDiscovery.class);
    when(configurer.createDefaultSamlDiscoveryFilter()).thenReturn(discoveryFilter);
    SAMLEntryPoint entryPoint = mock(SAMLEntryPoint.class);
    when(configurer.createDefaultSamlEntryPoint()).thenReturn(entryPoint);
    SavedRequestAwareAuthenticationSuccessHandler successHandler = mock(SavedRequestAwareAuthenticationSuccessHandler.class);
    when(configurer.createDefaultSuccessHandler()).thenReturn(successHandler);
    SimpleUrlAuthenticationFailureHandler failureHandler = mock(SimpleUrlAuthenticationFailureHandler.class);
    when(configurer.createDefaultFailureHandler()).thenReturn(failureHandler);
    configurer.init(builder);
    configurer.configure(builder);

    verify(properties).getDefaultFailureUrl();
    verify(properties).getDefaultSuccessUrl();
    verify(properties).getDiscoveryProcessingUrl();
    verify(properties).getIdpSelectionPageUrl();
    verify(properties).getSsoHokProcessingUrl();
    verify(properties).getSsoLoginUrl();
    verify(properties).getSsoProcessingUrl();
    verify(properties).getProfileOptions();

    verify(successHandler).setDefaultTargetUrl(eq(properties.getDefaultSuccessUrl()));
    verify(failureHandler).setDefaultFailureUrl(eq(properties.getDefaultFailureUrl()));

    verify(ssoFilter).setAuthenticationManager(eq(authenticationManager));
    verify(ssoFilter).setAuthenticationSuccessHandler(eq(successHandler));
    verify(ssoFilter).setAuthenticationFailureHandler(eq(failureHandler));
    verify(ssoFilter).setFilterProcessesUrl(eq(properties.getSsoProcessingUrl()));

    verify(ssoHoKFilter).setAuthenticationManager(eq(authenticationManager));
    verify(ssoHoKFilter).setAuthenticationSuccessHandler(eq(successHandler));
    verify(ssoHoKFilter).setAuthenticationFailureHandler(eq(failureHandler));
    verify(ssoHoKFilter).setFilterProcessesUrl(eq(properties.getSsoHokProcessingUrl()));

    verify(serviceProviderEndpoints).setSsoProcessingURL(properties.getSsoProcessingUrl());
    verify(serviceProviderEndpoints).setSsoHoKProcessingURL(properties.getSsoHokProcessingUrl());
    verify(serviceProviderEndpoints).setDefaultFailureURL(properties.getDefaultFailureUrl());
    verify(serviceProviderEndpoints).setDiscoveryProcessingURL(properties.getDiscoveryProcessingUrl());
    verify(serviceProviderEndpoints).setIdpSelectionPageURL(properties.getIdpSelectionPageUrl());
    verify(serviceProviderEndpoints).setSsoLoginURL(properties.getSsoLoginUrl());

    verify(discoveryFilter).setFilterProcessesUrl(eq(properties.getDiscoveryProcessingUrl()));
    verify(discoveryFilter).setIdpSelectionPath(eq(properties.getIdpSelectionPageUrl()));

    verify(entryPoint).setFilterProcessesUrl(eq(properties.getSsoLoginUrl()));
    ArgumentCaptor<WebSSOProfileOptions> optionsCaptor = ArgumentCaptor.forClass(WebSSOProfileOptions.class);
    verify(entryPoint).setDefaultProfileOptions(optionsCaptor.capture());
    WebSSOProfileOptions options = optionsCaptor.getValue();
    Assertions.assertThat(options.isAllowCreate()).isEqualTo(properties.getProfileOptions().getAllowCreate());
    Assertions.assertThat(options.getAllowedIDPs()).isEqualTo(properties.getProfileOptions().getAllowedIdps());
    Assertions.assertThat(options.getAssertionConsumerIndex()).isEqualTo(properties.getProfileOptions().getAssertionConsumerIndex());
    Assertions.assertThat(options.getAuthnContextComparison()).isEqualTo(properties.getProfileOptions().getAuthnContextComparison().getType());
    Assertions.assertThat(options.getAuthnContexts()).isEqualTo(properties.getProfileOptions().getAuthnContexts());
    Assertions.assertThat(options.getBinding()).isEqualTo(properties.getProfileOptions().getBinding());
    Assertions.assertThat(options.getForceAuthN()).isEqualTo(properties.getProfileOptions().getForceAuthn());
    Assertions.assertThat(options.isIncludeScoping()).isEqualTo(properties.getProfileOptions().getIncludeScoping());
    Assertions.assertThat(options.getNameID()).isEqualTo(properties.getProfileOptions().getNameId());
    Assertions.assertThat(options.getPassive()).isEqualTo(properties.getProfileOptions().getPassive());
    Assertions.assertThat(options.getProviderName()).isEqualTo(properties.getProfileOptions().getProviderName());
    Assertions.assertThat(options.getProxyCount()).isEqualTo(properties.getProfileOptions().getProxyCount());
    Assertions.assertThat(options.getRelayState()).isEqualTo(properties.getProfileOptions().getRelayState());

    verify(builder).setSharedObject(eq(SAMLProcessingFilter.class), eq(ssoFilter));
    verify(builder).setSharedObject(eq(SAMLWebSSOHoKProcessingFilter.class), eq(ssoHoKFilter));
    verify(builder).setSharedObject(eq(SAMLDiscovery.class), eq(discoveryFilter));
    verify(builder).setSharedObject(eq(SAMLEntryPoint.class), eq(entryPoint));

}
 
Example #20
Source File: SSOConfigurer.java    From spring-boot-security-saml with MIT License 4 votes vote down vote up
@VisibleForTesting
protected SimpleUrlAuthenticationFailureHandler createDefaultFailureHandler() {
    return new SimpleUrlAuthenticationFailureHandler();
}
 
Example #21
Source File: SSOConfigurer.java    From spring-boot-security-saml with MIT License 4 votes vote down vote up
@Override
public void configure(ServiceProviderBuilder builder) throws Exception {
    if (successHandler == null) {
        SavedRequestAwareAuthenticationSuccessHandler successRedirectHandler = createDefaultSuccessHandler();
        successRedirectHandler.setDefaultTargetUrl(Optional.ofNullable(defaultSuccessURL).orElseGet(config::getDefaultSuccessUrl));
        successHandler = postProcess(successRedirectHandler);
    }

    defaultFailureURL = Optional.ofNullable(defaultFailureURL).orElseGet(config::getDefaultFailureUrl);
    if (failureHandler == null) {
        SimpleUrlAuthenticationFailureHandler authenticationFailureHandler = createDefaultFailureHandler();
        authenticationFailureHandler.setDefaultFailureUrl(defaultFailureURL);
        failureHandler = postProcess(authenticationFailureHandler);
    }
    endpoints.setDefaultFailureURL(defaultFailureURL);


    SAMLProcessingFilter ssoFilter = createDefaultSamlProcessingFilter();
    ssoFilter.setAuthenticationManager(authenticationManager);
    ssoFilter.setAuthenticationSuccessHandler(successHandler);
    ssoFilter.setAuthenticationFailureHandler(failureHandler);
    ssoProcessingURL = Optional.ofNullable(ssoProcessingURL).orElseGet(config::getSsoProcessingUrl);
    endpoints.setSsoProcessingURL(ssoProcessingURL);
    ssoFilter.setFilterProcessesUrl(ssoProcessingURL);
    if (sessionAuthenticationStrategy != null) {
        ssoFilter.setSessionAuthenticationStrategy(sessionAuthenticationStrategy);
    }

    SAMLWebSSOHoKProcessingFilter ssoHoKFilter = null;
    if (Optional.ofNullable(enableSsoHoK).orElseGet(config::isEnableSsoHok)) {
        ssoHoKFilter = createDefaultSamlHoKProcessingFilter();
        ssoHoKFilter.setAuthenticationSuccessHandler(successHandler);
        ssoHoKFilter.setAuthenticationManager(authenticationManager);
        ssoHoKFilter.setAuthenticationFailureHandler(failureHandler);
        ssoHoKProcessingURL = Optional.ofNullable(ssoHoKProcessingURL).orElseGet(config::getSsoHokProcessingUrl);
        endpoints.setSsoHoKProcessingURL(ssoHoKProcessingURL);
        ssoHoKFilter.setFilterProcessesUrl(ssoHoKProcessingURL);
        if (sessionAuthenticationStrategy != null) {
            ssoHoKFilter.setSessionAuthenticationStrategy(sessionAuthenticationStrategy);
        }
    }

    SAMLDiscovery discoveryFilter = createDefaultSamlDiscoveryFilter();
    discoveryProcessingURL = Optional.ofNullable(discoveryProcessingURL).orElseGet(config::getDiscoveryProcessingUrl);
    endpoints.setDiscoveryProcessingURL(discoveryProcessingURL);
    discoveryFilter.setFilterProcessesUrl(discoveryProcessingURL);
    idpSelectionPageURL = Optional.ofNullable(idpSelectionPageURL).orElseGet(config::getIdpSelectionPageUrl);
    endpoints.setIdpSelectionPageURL(idpSelectionPageURL);
    discoveryFilter.setIdpSelectionPath(idpSelectionPageURL);

    SAMLEntryPoint entryPoint = Optional.ofNullable(samlEntryPointBean).orElseGet(this::createDefaultSamlEntryPoint);
    entryPoint.setDefaultProfileOptions(Optional.ofNullable(profileOptions).orElseGet(this::getProfileOptions));
    ssoLoginURL = Optional.ofNullable(ssoLoginURL).orElseGet(config::getSsoLoginUrl);
    endpoints.setSsoLoginURL(ssoLoginURL);
    entryPoint.setFilterProcessesUrl(ssoLoginURL);

    builder.setSharedObject(SAMLProcessingFilter.class, ssoFilter);
    builder.setSharedObject(SAMLWebSSOHoKProcessingFilter.class, ssoHoKFilter);
    builder.setSharedObject(SAMLDiscovery.class, discoveryFilter);
    builder.setSharedObject(SAMLEntryPoint.class, entryPoint);
}
 
Example #22
Source File: SocialAuthenticationFilter.java    From graviteeio-access-management with Apache License 2.0 4 votes vote down vote up
public SocialAuthenticationFilter(String defaultFilterProcessesUrl) {
    super(defaultFilterProcessesUrl);
    setAuthenticationManager(new NoopAuthenticationManager());
    setAuthenticationFailureHandler(new SimpleUrlAuthenticationFailureHandler(errorPage));
}
 
Example #23
Source File: AuthenticationHandler.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
@Bean
public SimpleUrlAuthenticationFailureHandler authenticationFailureHandler() {
    return new SimpleUrlAuthenticationFailureHandler();
}
 
Example #24
Source File: JWTRequestParameterProcessingFilter.java    From airsonic with GNU General Public License v3.0 4 votes vote down vote up
protected JWTRequestParameterProcessingFilter(AuthenticationManager authenticationManager, String failureUrl) {
    this.authenticationManager = authenticationManager;
    failureHandler = new SimpleUrlAuthenticationFailureHandler(failureUrl);
}
 
Example #25
Source File: CustomSecurityConfig.java    From multitenancy with Apache License 2.0 2 votes vote down vote up
/**
 * The page to show if authentication fails
 * 
 * @return
 */
public SimpleUrlAuthenticationFailureHandler failureHandler() {
    return new SimpleUrlAuthenticationFailureHandler("/login?error=true");
}