use of org.springframework.security.web.FilterInvocation in project spring-security by spring-projects.
the class FilterInvocationTests method testStringMethodsWithoutAnyQueryString.
@Test
public void testStringMethodsWithoutAnyQueryString() {
MockHttpServletRequest request = new MockHttpServletRequest(null, null);
request.setServletPath("/HelloWorld");
request.setServerName("www.example.com");
request.setScheme("http");
request.setServerPort(80);
request.setContextPath("/mycontext");
request.setRequestURI("/mycontext/HelloWorld");
MockHttpServletResponse response = new MockHttpServletResponse();
FilterInvocation fi = new FilterInvocation(request, response, mock(FilterChain.class));
assertThat(fi.getRequestUrl()).isEqualTo("/HelloWorld");
assertThat(fi.toString()).isEqualTo("FilterInvocation: URL: /HelloWorld");
assertThat(fi.getFullRequestUrl()).isEqualTo("http://www.example.com/mycontext/HelloWorld");
}
use of org.springframework.security.web.FilterInvocation in project spring-security-oauth by spring-projects.
the class OAuthConsumerProcessingFilter method getAccessTokenDependencies.
/**
* Loads the access token dependencies for the given request. This will be a set of {@link ProtectedResourceDetails#getId() resource ids}
* for which an OAuth access token is required.
*
* @param request The request.
* @param response The response
* @param filterChain The filter chain
* @return The access token dependencies (could be empty).
*/
protected Set<String> getAccessTokenDependencies(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) {
Set<String> deps = new TreeSet<String>();
if (getObjectDefinitionSource() != null) {
FilterInvocation invocation = new FilterInvocation(request, response, filterChain);
Collection<ConfigAttribute> attributes = getObjectDefinitionSource().getAttributes(invocation);
if (attributes != null) {
for (ConfigAttribute attribute : attributes) {
deps.add(attribute.getAttribute());
}
}
}
return deps;
}
use of org.springframework.security.web.FilterInvocation in project spring-security by spring-projects.
the class WebExpressionVoterTests method grantsAccessIfExpressionIsTrueDeniesIfFalse.
@Test
public void grantsAccessIfExpressionIsTrueDeniesIfFalse() {
WebExpressionVoter voter = new WebExpressionVoter();
Expression ex = mock(Expression.class);
EvaluationContextPostProcessor postProcessor = mock(EvaluationContextPostProcessor.class);
when(postProcessor.postProcess(any(EvaluationContext.class), any(FilterInvocation.class))).thenAnswer(new Answer<EvaluationContext>() {
public EvaluationContext answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArgumentAt(0, EvaluationContext.class);
}
});
WebExpressionConfigAttribute weca = new WebExpressionConfigAttribute(ex, postProcessor);
EvaluationContext ctx = mock(EvaluationContext.class);
SecurityExpressionHandler eh = mock(SecurityExpressionHandler.class);
FilterInvocation fi = new FilterInvocation("/path", "GET");
voter.setExpressionHandler(eh);
when(eh.createEvaluationContext(user, fi)).thenReturn(ctx);
when(ex.getValue(ctx, Boolean.class)).thenReturn(Boolean.TRUE).thenReturn(Boolean.FALSE);
ArrayList attributes = new ArrayList();
attributes.addAll(SecurityConfig.createList("A", "B", "C"));
attributes.add(weca);
assertThat(voter.vote(user, fi, attributes)).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
// Second time false
assertThat(voter.vote(user, fi, attributes)).isEqualTo(AccessDecisionVoter.ACCESS_DENIED);
}
use of org.springframework.security.web.FilterInvocation in project spring-security by spring-projects.
the class WebSecurityExpressionRootTests method ipAddressMatchesForEqualIpAddresses.
@Test
public void ipAddressMatchesForEqualIpAddresses() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/test");
// IPv4
request.setRemoteAddr("192.168.1.1");
WebSecurityExpressionRoot root = new WebSecurityExpressionRoot(mock(Authentication.class), new FilterInvocation(request, mock(HttpServletResponse.class), mock(FilterChain.class)));
assertThat(root.hasIpAddress("192.168.1.1")).isTrue();
// IPv6 Address
request.setRemoteAddr("fa:db8:85a3::8a2e:370:7334");
assertThat(root.hasIpAddress("fa:db8:85a3::8a2e:370:7334")).isTrue();
}
use of org.springframework.security.web.FilterInvocation in project spring-security by spring-projects.
the class DefaultFilterInvocationSecurityMetadataSourceTests method httpMethodLookupSucceeds.
@Test
public void httpMethodLookupSucceeds() {
createFids("/somepage**", "GET");
FilterInvocation fi = createFilterInvocation("/somepage", null, null, "GET");
Collection<ConfigAttribute> attrs = this.fids.getAttributes(fi);
assertThat(attrs).isEqualTo(this.def);
}
Aggregations