Search in sources :

Example 1 with ELRequestMatcher

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

the class ELRequestMatcherTests method testHasIpAddressFalse.

@Test
public void testHasIpAddressFalse() throws Exception {
    ELRequestMatcher requestMatcher = new ELRequestMatcher("hasIpAddress('1.1.1.1')");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("1.1.1.2");
    assertThat(requestMatcher.matches(request)).isFalse();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ELRequestMatcher(org.springframework.security.web.util.matcher.ELRequestMatcher) Test(org.junit.Test)

Example 2 with ELRequestMatcher

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

the class ELRequestMatcherTests method testHasHeaderFalse.

@Test
public void testHasHeaderFalse() throws Exception {
    ELRequestMatcher requestMatcher = new ELRequestMatcher("hasHeader('User-Agent','MSIE')");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("User-Agent", "wrong");
    assertThat(requestMatcher.matches(request)).isFalse();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ELRequestMatcher(org.springframework.security.web.util.matcher.ELRequestMatcher) Test(org.junit.Test)

Example 3 with ELRequestMatcher

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

the class ELRequestMatcherTests method testHasHeaderTrue.

@Test
public void testHasHeaderTrue() throws Exception {
    ELRequestMatcher requestMatcher = new ELRequestMatcher("hasHeader('User-Agent','MSIE')");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("User-Agent", "MSIE");
    assertThat(requestMatcher.matches(request)).isTrue();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ELRequestMatcher(org.springframework.security.web.util.matcher.ELRequestMatcher) Test(org.junit.Test)

Example 4 with ELRequestMatcher

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

the class ELRequestMatcherTests method testHasIpAddressTrue.

@Test
public void testHasIpAddressTrue() throws Exception {
    ELRequestMatcher requestMatcher = new ELRequestMatcher("hasIpAddress('1.1.1.1')");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setRemoteAddr("1.1.1.1");
    assertThat(requestMatcher.matches(request)).isTrue();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ELRequestMatcher(org.springframework.security.web.util.matcher.ELRequestMatcher) Test(org.junit.Test)

Example 5 with ELRequestMatcher

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

the class ELRequestMatcherTests method testHasHeaderTwoEntries.

@Test
public void testHasHeaderTwoEntries() throws Exception {
    ELRequestMatcher requestMatcher = new ELRequestMatcher("hasHeader('User-Agent','MSIE') or hasHeader('User-Agent','Mozilla')");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("User-Agent", "MSIE");
    assertThat(requestMatcher.matches(request)).isTrue();
    request = new MockHttpServletRequest();
    request.addHeader("User-Agent", "Mozilla");
    assertThat(requestMatcher.matches(request)).isTrue();
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ELRequestMatcher(org.springframework.security.web.util.matcher.ELRequestMatcher) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)6 ELRequestMatcher (org.springframework.security.web.util.matcher.ELRequestMatcher)6