use of org.springframework.security.web.FilterInvocation in project spring-security by spring-projects.
the class WebSecurityExpressionRootTests method addressesInIpRangeMatch.
@Test
public void addressesInIpRangeMatch() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/test");
WebSecurityExpressionRoot root = new WebSecurityExpressionRoot(mock(Authentication.class), new FilterInvocation(request, mock(HttpServletResponse.class), mock(FilterChain.class)));
for (int i = 0; i < 255; i++) {
request.setRemoteAddr("192.168.1." + i);
assertThat(root.hasIpAddress("192.168.1.0/24")).isTrue();
}
request.setRemoteAddr("192.168.1.127");
// 25 = FF FF FF 80
assertThat(root.hasIpAddress("192.168.1.0/25")).isTrue();
// encroach on the mask
request.setRemoteAddr("192.168.1.128");
assertThat(root.hasIpAddress("192.168.1.0/25")).isFalse();
request.setRemoteAddr("192.168.1.255");
assertThat(root.hasIpAddress("192.168.1.128/25")).isTrue();
assertThat(root.hasIpAddress("192.168.1.192/26")).isTrue();
assertThat(root.hasIpAddress("192.168.1.224/27")).isTrue();
assertThat(root.hasIpAddress("192.168.1.240/27")).isTrue();
assertThat(root.hasIpAddress("192.168.1.255/32")).isTrue();
request.setRemoteAddr("202.24.199.127");
assertThat(root.hasIpAddress("202.24.0.0/14")).isTrue();
request.setRemoteAddr("202.25.179.135");
assertThat(root.hasIpAddress("202.24.0.0/14")).isTrue();
request.setRemoteAddr("202.26.179.135");
assertThat(root.hasIpAddress("202.24.0.0/14")).isTrue();
}
use of org.springframework.security.web.FilterInvocation in project spring-security by spring-projects.
the class DefaultFilterInvocationSecurityMetadataSourceTests method lookupNotRequiringExactMatchSucceedsIfNotMatching.
@Test
public void lookupNotRequiringExactMatchSucceedsIfNotMatching() {
createFids("/secure/super/**", null);
FilterInvocation fi = createFilterInvocation("/secure/super/somefile.html", null, null, null);
assertThat(this.fids.getAttributes(fi)).isEqualTo(this.def);
}
use of org.springframework.security.web.FilterInvocation in project spring-security by spring-projects.
the class DefaultFilterInvocationSecurityMetadataSourceTests method lookupNotRequiringExactMatchSucceedsIfSecureUrlPathContainsUpperCase.
/**
* SEC-501. Note that as of 2.0, lower case comparisons are the default for this
* class.
*/
@Test
public void lookupNotRequiringExactMatchSucceedsIfSecureUrlPathContainsUpperCase() {
createFids("/secure/super/**", null);
FilterInvocation fi = createFilterInvocation("/secure", "/super/somefile.html", null, null);
Collection<ConfigAttribute> response = this.fids.getAttributes(fi);
assertThat(response).isEqualTo(this.def);
}
use of org.springframework.security.web.FilterInvocation in project spring-security by spring-projects.
the class DefaultFilterInvocationSecurityMetadataSourceTests method lookupRequiringExactMatchIsSuccessful.
@Test
public void lookupRequiringExactMatchIsSuccessful() {
createFids("/SeCurE/super/**", null);
FilterInvocation fi = createFilterInvocation("/SeCurE/super/somefile.html", null, null, null);
Collection<ConfigAttribute> response = this.fids.getAttributes(fi);
assertThat(response).isEqualTo(this.def);
}
use of org.springframework.security.web.FilterInvocation in project spring-security by spring-projects.
the class SecureChannelProcessorTests method testDecideDetectsAcceptableChannel.
// ~ Methods
// ========================================================================================================
@Test
public void testDecideDetectsAcceptableChannel() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setQueryString("info=true");
request.setServerName("localhost");
request.setContextPath("/bigapp");
request.setServletPath("/servlet");
request.setScheme("https");
request.setSecure(true);
request.setServerPort(8443);
MockHttpServletResponse response = new MockHttpServletResponse();
FilterInvocation fi = new FilterInvocation(request, response, mock(FilterChain.class));
SecureChannelProcessor processor = new SecureChannelProcessor();
processor.decide(fi, SecurityConfig.createList("SOME_IGNORED_ATTRIBUTE", "REQUIRES_SECURE_CHANNEL"));
assertThat(fi.getResponse().isCommitted()).isFalse();
}
Aggregations