@Bean(name = "authFilter") public Filter authFilter() throws Exception { log.info("Creating authFilter..."); RequestMatcher antReqMatch = new AntPathRequestMatcher(API_LOGIN_URL); List<RequestMatcher> reqMatches = new ArrayList<>(); reqMatches.add(antReqMatch); RequestMatcher reqMatch = new AndRequestMatcher(reqMatches); UsernamePasswordAuthenticationFilter filter = new UsernamePasswordAuthenticationFilter(); filter.setPostOnly(true); filter.setUsernameParameter(USERNAME); filter.setPasswordParameter(PASSWORD); filter.setRequiresAuthenticationRequestMatcher(reqMatch); filter.setAuthenticationSuccessHandler(apiAuthenticationSuccessHandler); filter.setAuthenticationFailureHandler(apiAuthenticationFailureHandler); filter.setAuthenticationManager(authenticationManager()); return filter; }
protected AbstractAuthenticationProcessingFilter createCustomFilter() throws Exception { //here we define the interfaces which don't need any authorisation AuthFilter filter = new AuthFilter(new NegatedRequestMatcher( new AndRequestMatcher( new AntPathRequestMatcher("/login"), new AntPathRequestMatcher("/health") ) )); filter.setAuthenticationManager(authenticationManagerBean()); return filter; }
@Override public void init(HttpSecurity http) { metadataProvider = identityProvider.metadataProvider(); ExtendedMetadata extendedMetadata = extendedMetadata(identityProvider.discoveryEnabled); extendedMetadataDelegate = extendedMetadataDelegate(extendedMetadata); serviceProvider.keyManager = serviceProvider.keyManager(); cachingMetadataManager = cachingMetadataManager(); webSSOProfile = new WebSSOProfileImpl(samlProcessor, cachingMetadataManager); samlAuthenticationProvider = samlAuthenticationProvider(webSSOProfileConsumer); bootstrap(); SAMLContextProvider contextProvider = contextProvider(); SAMLEntryPoint samlEntryPoint = samlEntryPoint(contextProvider); try { http .httpBasic() .authenticationEntryPoint(samlEntryPoint); CsrfConfigurer<HttpSecurity> csrfConfigurer = http.getConfigurer(CsrfConfigurer.class); if(csrfConfigurer != null) { // Workaround to get working with Spring Security 3.2. RequestMatcher ignored = new AntPathRequestMatcher("/saml/SSO"); RequestMatcher notIgnored = new NegatedRequestMatcher(ignored); RequestMatcher matcher = new AndRequestMatcher(new DefaultRequiresCsrfMatcher(), notIgnored); csrfConfigurer.requireCsrfProtectionMatcher(matcher); } } catch (Exception e) { e.printStackTrace(); } http .addFilterBefore(metadataGeneratorFilter(samlEntryPoint, extendedMetadata), ChannelProcessingFilter.class) .addFilterAfter(samlFilter(samlEntryPoint, contextProvider), BasicAuthenticationFilter.class) .authenticationProvider(samlAuthenticationProvider); }