List of usage examples for org.springframework.security.web.authentication.www BasicAuthenticationFilter BasicAuthenticationFilter
public BasicAuthenticationFilter(AuthenticationManager authenticationManager,
AuthenticationEntryPoint authenticationEntryPoint)
From source file:ch.thp.proto.spring.time.web.config.SecurityConfig.java
@Override protected void configure(HttpSecurity http) throws Exception { http.antMatcher("/hello/secure/**").authorizeRequests().antMatchers("/hello/secure/**").hasRole("USER") .and().antMatcher("/secure/**").authorizeRequests().antMatchers("/secure/**").hasRole("USER").and() .httpBasic().and()//from w w w .j av a 2 s . co m .addFilterBefore(new BasicAuthenticationFilter(authenticationManager(), new BasicJsonEntryPoint()), BasicAuthenticationFilter.class) //todo: check the csrf capability with angularjs .csrf().disable(); }
From source file:it.geosolutions.geoserver.authentication.filter.GeoFenceAuthFilter.java
@Override public void initializeFromConfig(SecurityNamedServiceConfig config) throws IOException { super.initializeFromConfig(config); GeoFenceAuthFilterConfig cfg = (GeoFenceAuthFilterConfig) config; // anything to set here? maybe the cache config aep = new BasicAuthenticationEntryPoint(); aep.setRealmName(GeoServerSecurityManager.REALM); try {/*w ww. j a v a 2 s. c o m*/ aep.afterPropertiesSet(); } catch (Exception e) { throw new IOException(e); } // BasicAuthenticationFilterConfig authConfig = (BasicAuthenticationFilterConfig) config; SecurityNamedServiceConfig authCfg = securityManager.loadAuthenticationProviderConfig("geofence"); GeofenceAuthenticationProvider geofenceAuthProvider = geofenceAuth.createAuthenticationProvider(authCfg); BasicAuthenticationFilter filter = new BasicAuthenticationFilter(geofenceAuthProvider, aep); // if (authConfig.isUseRememberMe()) { // filter.setRememberMeServices(securityManager.getRememberMeService()); // GeoServerWebAuthenticationDetailsSource s = new GeoServerWebAuthenticationDetailsSource(); // filter.setAuthenticationDetailsSource(s); // } filter.afterPropertiesSet(); getNestedFilters().add(filter); }
From source file:org.geoserver.geoserver.authentication.filter.GeoFenceAuthFilter.java
@Override public void initializeFromConfig(SecurityNamedServiceConfig config) throws IOException { super.initializeFromConfig(config); GeoFenceAuthFilterConfig cfg = (GeoFenceAuthFilterConfig) config; // anything to set here? maybe the cache config aep = new BasicAuthenticationEntryPoint(); aep.setRealmName(GeoServerSecurityManager.REALM); try {//from ww w . ja v a 2s .co m aep.afterPropertiesSet(); } catch (Exception e) { throw new IOException(e); } // BasicAuthenticationFilterConfig authConfig = (BasicAuthenticationFilterConfig) config; SecurityNamedServiceConfig authCfg = securityManager.loadAuthenticationProviderConfig("geofence"); GeoFenceAuthenticationProvider geofenceAuthProvider = geofenceAuth.createAuthenticationProvider(authCfg); BasicAuthenticationFilter filter = new BasicAuthenticationFilter(geofenceAuthProvider, aep); // if (authConfig.isUseRememberMe()) { // filter.setRememberMeServices(securityManager.getRememberMeService()); // GeoServerWebAuthenticationDetailsSource s = new GeoServerWebAuthenticationDetailsSource(); // filter.setAuthenticationDetailsSource(s); // } filter.afterPropertiesSet(); getNestedFilters().add(filter); }
From source file:org.springframework.cloud.dataflow.server.config.security.OAuthSecurityConfiguration.java
@Override protected void configure(HttpSecurity http) throws Exception { final RequestMatcher textHtmlMatcher = new MediaTypeRequestMatcher( new BrowserDetectingContentNegotiationStrategy(), MediaType.TEXT_HTML); final BasicAuthenticationEntryPoint basicAuthenticationEntryPoint = new BasicAuthenticationEntryPoint(); basicAuthenticationEntryPoint.setRealmName(securityProperties.getBasic().getRealm()); basicAuthenticationEntryPoint.afterPropertiesSet(); final Filter oauthFilter = oauthFilter(); BasicAuthenticationFilter basicAuthenticationFilter = new BasicAuthenticationFilter(providerManager(), basicAuthenticationEntryPoint); http.addFilterAfter(oauthFilter, basicAuthenticationFilter.getClass()); http.addFilterBefore(basicAuthenticationFilter, oauthFilter.getClass()); http.addFilterBefore(oAuth2AuthenticationProcessingFilter(), basicAuthenticationFilter.getClass()); http.authorizeRequests()/*www.jav a2 s . co m*/ .antMatchers("/security/info**", "/login**", dashboard("/logout-success-oauth.html"), dashboard("/styles/**"), dashboard("/images/**"), dashboard("/fonts/**"), dashboard("/lib/**")) .permitAll().anyRequest().authenticated().and().httpBasic().and().logout() .logoutSuccessUrl(dashboard("/logout-success-oauth.html")).and().csrf().disable() .exceptionHandling() .defaultAuthenticationEntryPointFor(new LoginUrlAuthenticationEntryPoint("/login"), textHtmlMatcher) .defaultAuthenticationEntryPointFor(basicAuthenticationEntryPoint, AnyRequestMatcher.INSTANCE); securityStateBean.setAuthenticationEnabled(true); securityStateBean.setAuthorizationEnabled(false); }
From source file:org.springframework.security.web.authentication.www.BasicAuthenticationFilterTests.java
@Before public void setUp() throws Exception { SecurityContextHolder.clearContext(); UsernamePasswordAuthenticationToken rodRequest = new UsernamePasswordAuthenticationToken("rod", "koala"); rodRequest.setDetails(new WebAuthenticationDetails(new MockHttpServletRequest())); Authentication rod = new UsernamePasswordAuthenticationToken("rod", "koala", AuthorityUtils.createAuthorityList("ROLE_1")); manager = mock(AuthenticationManager.class); when(manager.authenticate(rodRequest)).thenReturn(rod); when(manager.authenticate(not(eq(rodRequest)))).thenThrow(new BadCredentialsException("")); filter = new BasicAuthenticationFilter(manager, new BasicAuthenticationEntryPoint()); }
From source file:org.springframework.security.web.authentication.www.BasicAuthenticationFilterTests.java
@Test(expected = IllegalArgumentException.class) public void testStartupDetectsMissingAuthenticationEntryPoint() throws Exception { new BasicAuthenticationFilter(manager, null); }