org.springframework.security.web.SecurityFilterChain Java Examples

The following examples show how to use org.springframework.security.web.SecurityFilterChain. 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: OAuth2Configuration.java    From okta-jhipster-microservices-oauth-example with Apache License 2.0 6 votes vote down vote up
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
    if (bean instanceof FilterChainProxy) {

        FilterChainProxy chains = (FilterChainProxy) bean;

        for (SecurityFilterChain chain : chains.getFilterChains()) {
            for (Filter filter : chain.getFilters()) {
                if (filter instanceof OAuth2ClientAuthenticationProcessingFilter) {
                    OAuth2ClientAuthenticationProcessingFilter oAuth2ClientAuthenticationProcessingFilter =
                        (OAuth2ClientAuthenticationProcessingFilter) filter;
                    oAuth2ClientAuthenticationProcessingFilter
                        .setAuthenticationSuccessHandler(new OAuth2AuthenticationSuccessHandler());
                }
            }
        }
    }
    return bean;
}
 
Example #2
Source File: WebSecurityConfig.java    From spring-tsers-auth with Apache License 2.0 6 votes vote down vote up
@Bean
public FilterChainProxy samlFilter() throws Exception {
    List<SecurityFilterChain> chains = new ArrayList<SecurityFilterChain>();
    chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/login/**"),
            samlEntryPoint()));
    chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/logout/**"),
            samlLogoutFilter()));
    chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/metadata/**"),
            metadataDisplayFilter()));
    chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSO/**"),
            samlWebSSOProcessingFilter()));
    chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSOHoK/**"),
            samlWebSSOHoKProcessingFilter()));
    chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SingleLogout/**"),
            samlLogoutProcessingFilter()));
    chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/discovery/**"),
            samlIDPDiscovery()));
    return new FilterChainProxy(chains);
}
 
Example #3
Source File: SAMLConfigurer.java    From spring-security-saml-dsl with MIT License 6 votes vote down vote up
private FilterChainProxy samlFilter(SAMLEntryPoint samlEntryPoint, SAMLLogoutFilter samlLogoutFilter,
									SAMLLogoutProcessingFilter samlLogoutProcessingFilter, SAMLContextProvider contextProvider) {
	List<SecurityFilterChain> chains = new ArrayList<>();
	chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/login/**"),
		samlEntryPoint));
	chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/logout/**"),
		samlLogoutFilter));
	chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/metadata/**"),
		metadataDisplayFilter(contextProvider)));
	try {
		chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSO/**"),
			samlWebSSOProcessingFilter(samlAuthenticationProvider, contextProvider, samlProcessor)));
	} catch (Exception e) {
		e.printStackTrace();
	}
	chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SingleLogout/**"),
			samlLogoutProcessingFilter));
	SAMLDiscovery samlDiscovery = new SAMLDiscovery();
	samlDiscovery.setMetadata(cachingMetadataManager);
	samlDiscovery.setContextProvider(contextProvider);
	chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/discovery/**"),
		samlDiscovery));
	return new FilterChainProxy(chains);
}
 
Example #4
Source File: SecurityFilterConfig.java    From cosmo with Apache License 2.0 6 votes vote down vote up
@Bean
public FilterRegistrationBean<?> securityFilterChain() {
    FilterSecurityInterceptor securityFilter = new FilterSecurityInterceptor();
    securityFilter.setAuthenticationManager(this.authManager);
    securityFilter.setAccessDecisionManager(this.davDecisionManager);
    LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> metadata = new LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>>();
    metadata.put(AnyRequestMatcher.INSTANCE, SecurityConfig.createList(ROLES));
    securityFilter.setSecurityMetadataSource(new DefaultFilterInvocationSecurityMetadataSource(metadata));

    /*
     * Note that the order in which filters are defined is highly important.
     */
    SecurityFilterChain filterChain = new DefaultSecurityFilterChain(AnyRequestMatcher.INSTANCE,
            this.cosmoExceptionFilter, this.extraTicketFilter, this.ticketFilter,
            new BasicAuthenticationFilter(authManager, this.authEntryPoint), securityFilter);
    FilterChainProxy proxy = new FilterChainProxy(filterChain);
    proxy.setFirewall(this.httpFirewall);
    FilterRegistrationBean<?> filterBean = new FilterRegistrationBean<>(proxy);
    filterBean.addUrlPatterns(PATH_DAV);
    return filterBean;
}
 
Example #5
Source File: WebSecurityConfig.java    From spring-boot-security-saml-sample with Apache License 2.0 6 votes vote down vote up
/**
* Define the security filter chain in order to support SSO Auth by using SAML 2.0
* 
* @return Filter chain proxy
* @throws Exception
*/
  @Bean
  public FilterChainProxy samlFilter() throws Exception {
      List<SecurityFilterChain> chains = new ArrayList<SecurityFilterChain>();
      chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/login/**"),
              samlEntryPoint()));
      chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/logout/**"),
              samlLogoutFilter()));
      chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/metadata/**"),
              metadataDisplayFilter()));
      chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSO/**"),
              samlWebSSOProcessingFilter()));
      chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSOHoK/**"),
              samlWebSSOHoKProcessingFilter()));
      chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SingleLogout/**"),
              samlLogoutProcessingFilter()));
      chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/discovery/**"),
              samlIDPDiscovery()));
      return new FilterChainProxy(chains);
  }
 
Example #6
Source File: CustomSpringSecurityFilterChain.java    From Spring with Apache License 2.0 5 votes vote down vote up
private static List<SecurityFilterChain> filterChains() {
    final List<SecurityFilterChain> filterChain = new ArrayList<>();

    final LogoutFilter customLogoutFilter =
            new LogoutFilter(new CustomLogoutSuccessHandler(), new SecurityContextLogoutHandler());
    customLogoutFilter.setFilterProcessesUrl("/customlogout");
    filterChain.add(new DefaultSecurityFilterChain(
            new AntPathRequestMatcher("/customlogout**"), customLogoutFilter));
    return filterChain;
}
 
Example #7
Source File: AuthenticationHandler.java    From blackduck-alert with Apache License 2.0 5 votes vote down vote up
@Bean
public FilterChainProxy samlFilter() throws Exception {
    List<SecurityFilterChain> chains = new ArrayList<>();

    chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/login/**"), samlEntryPoint()));
    chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SSO/**"), samlWebSSOProcessingFilter()));
    chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/logout/**"), samlLogoutFilter()));
    chains.add(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/saml/SingleLogout/**"), samlLogoutProcessingFilter()));
    return new AlertFilterChainProxy(chains, samlContext());
}
 
Example #8
Source File: InsightsSecurityConfigurationAdapterKerberos.java    From Insights with Apache License 2.0 5 votes vote down vote up
/**
 * Used to add filter chain based on Request Matcher
 * 
 * @return
 * @throws Exception
 */
@Bean
@Conditional(InsightsKerberosBeanInitializationCondition.class)
public FilterChainProxy kerberosFilter() throws Exception {
	LOG.debug("message Inside InsightsSecurityConfigurationAdapterKerberos FilterChainProxy, initial bean **** ");

	/*AuthenticationUtils.setSecurityFilterchain(
			new DefaultSecurityFilterChain(new AntPathRequestMatcher("/kerberos/login/**"), spnegoEntryPoint()));*/

	/*AuthenticationUtils.setSecurityFilterchain(new DefaultSecurityFilterChain(
			new AntPathRequestMatcher("/user/insightsso/**"), insightsSSOProcessingFilter()));*/

	List<Filter> filters = new ArrayList<>();
	filters.add(0, new InsightsCustomCsrfFilter());
	filters.add(1, new InsightsCrossScriptingFilter());
	filters.add(2, insightsServiceProcessingFilter());
	filters.add(3, new InsightsResponseHeaderWriterFilter());

	AuthenticationUtils
			.setSecurityFilterchain(new DefaultSecurityFilterChain(new AntPathRequestMatcher("/**"), filters));

	ListIterator<SecurityFilterChain> securityFilters = AuthenticationUtils.getSecurityFilterchains()
			.listIterator();
	while (securityFilters.hasNext()) {
		SecurityFilterChain as = securityFilters.next();
		LOG.debug("message Inside FilterChainProxy, initial bean name {} **** ",
				Arrays.toString(as.getFilters().toArray()));
	}

	return new FilterChainProxy(AuthenticationUtils.getSecurityFilterchains());//chains
}
 
Example #9
Source File: AppSpringModuleConfig.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Gets a filter chain proxy.
 *
 * @param trustedUserAuthenticationFilter the trusted user authentication filter.
 * @param httpHeaderAuthenticationFilter the HTTP header authentication filter.
 *
 * @return the filter chain proxy.
 */
@Bean
public FilterChainProxy filterChainProxy(final TrustedUserAuthenticationFilter trustedUserAuthenticationFilter,
    final HttpHeaderAuthenticationFilter httpHeaderAuthenticationFilter)
{
    return new FilterChainProxy(new SecurityFilterChain()
    {
        @Override
        public boolean matches(HttpServletRequest request)
        {
            // Match all URLs.
            return true;
        }

        @Override
        public List<Filter> getFilters()
        {
            List<Filter> filters = new ArrayList<>();

            // Required filter to store session information between HTTP requests.
            filters.add(new SecurityContextPersistenceFilter());

            // Trusted user filter to bypass security based on SpEL expression environment property.
            filters.add(trustedUserAuthenticationFilter);

            // Filter that authenticates based on http headers.
            if (Boolean.valueOf(configurationHelper.getProperty(ConfigurationValue.SECURITY_HTTP_HEADER_ENABLED)))
            {
                filters.add(httpHeaderAuthenticationFilter);
            }

            // Anonymous user filter.
            filters.add(new AnonymousAuthenticationFilter("AnonymousFilterKey"));

            return filters;
        }
    });
}
 
Example #10
Source File: MainController.java    From tutorials with MIT License 5 votes vote down vote up
@RequestMapping(method = RequestMethod.GET, value = "/filters")
@ResponseBody
public void getFilters() {
    FilterChainProxy filterChainProxy = (FilterChainProxy) springSecurityFilterChain;
    List<SecurityFilterChain> list = filterChainProxy.getFilterChains();
    list.stream()
          .flatMap(chain -> chain.getFilters().stream())
          .forEach(filter -> System.out.println(filter.getClass()));
}
 
Example #11
Source File: AlertFilterChainProxy.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
public AlertFilterChainProxy(final List<SecurityFilterChain> chains, final SAMLContext samlContext) {
    super(chains);
    this.samlContext = samlContext;
}
 
Example #12
Source File: AuthenticationUtils.java    From Insights with Apache License 2.0 4 votes vote down vote up
public static List<SecurityFilterChain> getSecurityFilterchains() {
	return AuthenticationUtils.securityFilterchains;
}
 
Example #13
Source File: AuthenticationUtils.java    From Insights with Apache License 2.0 4 votes vote down vote up
public static void setSecurityFilterchain(SecurityFilterChain securityFilterchains) {
	AuthenticationUtils.securityFilterchains.add(securityFilterchains);
}
 
Example #14
Source File: FilterChainBuilder.java    From gocd with Apache License 2.0 4 votes vote down vote up
public List<SecurityFilterChain> build() {
    return filterChain;
}
 
Example #15
Source File: SpringSecurityProvider.java    From osiris with Apache License 2.0 3 votes vote down vote up
protected void registerSpringSecurityFilters(Environment environment) {

		SecurityFilterChain filterChain = context.getBean(SecurityFilterChain.class);

		for (Filter filter : filterChain.getFilters()) {

			environment.addFilter(filter, "/*");
		}
		
		
	}