Search in sources :

Example 36 with RequestMatcher

use of org.springframework.security.web.util.matcher.RequestMatcher in project spring-boot by spring-projects.

the class StaticResourceRequestTests method atLocationWhenHasServletPathShouldMatchLocation.

@Test
void atLocationWhenHasServletPathShouldMatchLocation() {
    RequestMatcher matcher = this.resourceRequest.at(StaticResourceLocation.CSS);
    assertMatcher(matcher, null, "/foo").matches("/foo", "/css/file.css");
    assertMatcher(matcher, null, "/foo").doesNotMatch("/foo", "/js/file.js");
}
Also used : RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) Test(org.junit.jupiter.api.Test)

Example 37 with RequestMatcher

use of org.springframework.security.web.util.matcher.RequestMatcher in project spring-boot by spring-projects.

the class StaticResourceRequestTests method atCommonLocationsShouldMatchCommonLocations.

@Test
void atCommonLocationsShouldMatchCommonLocations() {
    RequestMatcher matcher = this.resourceRequest.atCommonLocations();
    assertMatcher(matcher).matches("/css/file.css");
    assertMatcher(matcher).matches("/js/file.js");
    assertMatcher(matcher).matches("/images/file.css");
    assertMatcher(matcher).matches("/webjars/file.css");
    assertMatcher(matcher).matches("/favicon.ico");
    assertMatcher(matcher).matches("/favicon.png");
    assertMatcher(matcher).matches("/icons/icon-48x48.png");
    assertMatcher(matcher).doesNotMatch("/bar");
}
Also used : RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) Test(org.junit.jupiter.api.Test)

Example 38 with RequestMatcher

use of org.springframework.security.web.util.matcher.RequestMatcher in project spring-boot by spring-projects.

the class StaticResourceRequestTests method atCommonLocationsWithExcludeShouldNotMatchExcluded.

@Test
void atCommonLocationsWithExcludeShouldNotMatchExcluded() {
    RequestMatcher matcher = this.resourceRequest.atCommonLocations().excluding(StaticResourceLocation.CSS);
    assertMatcher(matcher).doesNotMatch("/css/file.css");
    assertMatcher(matcher).matches("/js/file.js");
}
Also used : RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) Test(org.junit.jupiter.api.Test)

Example 39 with RequestMatcher

use of org.springframework.security.web.util.matcher.RequestMatcher in project incubator-atlas by apache.

the class AtlasSecurityConfig method getDelegatingAuthenticationEntryPoint.

public DelegatingAuthenticationEntryPoint getDelegatingAuthenticationEntryPoint() {
    LinkedHashMap<RequestMatcher, AuthenticationEntryPoint> entryPointMap = new LinkedHashMap<>();
    entryPointMap.put(new RequestHeaderRequestMatcher("User-Agent", "Mozilla"), atlasAuthenticationEntryPoint);
    DelegatingAuthenticationEntryPoint entryPoint = new DelegatingAuthenticationEntryPoint(entryPointMap);
    entryPoint.setDefaultEntryPoint(getAuthenticationEntryPoint());
    return entryPoint;
}
Also used : RequestHeaderRequestMatcher(org.springframework.security.web.util.matcher.RequestHeaderRequestMatcher) RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) AtlasAuthenticationEntryPoint(org.apache.atlas.web.filters.AtlasAuthenticationEntryPoint) DelegatingAuthenticationEntryPoint(org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint) BasicAuthenticationEntryPoint(org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint) AuthenticationEntryPoint(org.springframework.security.web.AuthenticationEntryPoint) RequestHeaderRequestMatcher(org.springframework.security.web.util.matcher.RequestHeaderRequestMatcher) DelegatingAuthenticationEntryPoint(org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint) LinkedHashMap(java.util.LinkedHashMap)

Example 40 with RequestMatcher

use of org.springframework.security.web.util.matcher.RequestMatcher in project CzechIdMng by bcvsolutions.

the class WebSecurityConfig method configure.

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable();
    http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
    // 
    AuthenticationFilter authenticationFilter = authenticationFilter();
    Set<RequestMatcher> publicPaths = authenticationFilter.getPublicPathRequestMatchers();
    // 
    http.addFilterBefore(requestContextFilter(), BasicAuthenticationFilter.class).addFilterBefore(startUserTransactionFilter(), BasicAuthenticationFilter.class).addFilterAfter(authenticationFilter, BasicAuthenticationFilter.class).addFilterAfter(extendExpirationFilter(), BasicAuthenticationFilter.class).authorizeRequests().expressionHandler(expressionHandler()).antMatchers(HttpMethod.OPTIONS).permitAll().requestMatchers(publicPaths.toArray(new RequestMatcher[publicPaths.size()])).permitAll().antMatchers(BaseDtoController.BASE_PATH + "/**").fullyAuthenticated().anyRequest().permitAll();
}
Also used : RequestMatcher(org.springframework.security.web.util.matcher.RequestMatcher) BasicAuthenticationFilter(org.springframework.security.web.authentication.www.BasicAuthenticationFilter) AuthenticationFilter(eu.bcvsolutions.idm.core.security.api.auth.filter.AuthenticationFilter) BasicAuthenticationFilter(org.springframework.security.web.authentication.www.BasicAuthenticationFilter)

Aggregations

RequestMatcher (org.springframework.security.web.util.matcher.RequestMatcher)85 Test (org.junit.jupiter.api.Test)40 AntPathRequestMatcher (org.springframework.security.web.util.matcher.AntPathRequestMatcher)27 LinkedHashMap (java.util.LinkedHashMap)16 AndRequestMatcher (org.springframework.security.web.util.matcher.AndRequestMatcher)14 NegatedRequestMatcher (org.springframework.security.web.util.matcher.NegatedRequestMatcher)12 RequestHeaderRequestMatcher (org.springframework.security.web.util.matcher.RequestHeaderRequestMatcher)12 ArrayList (java.util.ArrayList)11 AuthenticationEntryPoint (org.springframework.security.web.AuthenticationEntryPoint)10 OrRequestMatcher (org.springframework.security.web.util.matcher.OrRequestMatcher)10 MediaTypeRequestMatcher (org.springframework.security.web.util.matcher.MediaTypeRequestMatcher)9 Collection (java.util.Collection)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 ConfigAttribute (org.springframework.security.access.ConfigAttribute)7 AnyRequestMatcher (org.springframework.security.web.util.matcher.AnyRequestMatcher)7 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 DelegatingAuthenticationEntryPoint (org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint)6 ContentNegotiationStrategy (org.springframework.web.accept.ContentNegotiationStrategy)6 HeaderContentNegotiationStrategy (org.springframework.web.accept.HeaderContentNegotiationStrategy)6