Search in sources :

Example 1 with DelegateEntry

use of org.springframework.security.web.server.authorization.ServerWebExchangeDelegatingServerAccessDeniedHandler.DelegateEntry in project spring-security by spring-projects.

the class ServerWebExchangeDelegatingServerAccessDeniedHandlerTests method handleWhenNothingMatchesThenOnlyDefaultHandlerInvoked.

@Test
public void handleWhenNothingMatchesThenOnlyDefaultHandlerInvoked() {
    ServerAccessDeniedHandler handler = mock(ServerAccessDeniedHandler.class);
    ServerWebExchangeMatcher matcher = mock(ServerWebExchangeMatcher.class);
    given(matcher.matches(this.exchange)).willReturn(MatchResult.notMatch());
    given(handler.handle(this.exchange, null)).willReturn(Mono.empty());
    given(this.accessDeniedHandler.handle(this.exchange, null)).willReturn(Mono.empty());
    this.entries.add(new DelegateEntry(matcher, handler));
    this.delegator = new ServerWebExchangeDelegatingServerAccessDeniedHandler(this.entries);
    this.delegator.setDefaultAccessDeniedHandler(this.accessDeniedHandler);
    this.delegator.handle(this.exchange, null).block();
    verify(this.accessDeniedHandler).handle(this.exchange, null);
    verify(handler, never()).handle(this.exchange, null);
}
Also used : ServerWebExchangeMatcher(org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher) DelegateEntry(org.springframework.security.web.server.authorization.ServerWebExchangeDelegatingServerAccessDeniedHandler.DelegateEntry) Test(org.junit.jupiter.api.Test)

Example 2 with DelegateEntry

use of org.springframework.security.web.server.authorization.ServerWebExchangeDelegatingServerAccessDeniedHandler.DelegateEntry in project spring-security by spring-projects.

the class ServerWebExchangeDelegatingServerAccessDeniedHandlerTests method handleWhenSecondMatchesThenOnlySecondInvoked.

@Test
public void handleWhenSecondMatchesThenOnlySecondInvoked() {
    ServerAccessDeniedHandler firstHandler = mock(ServerAccessDeniedHandler.class);
    ServerWebExchangeMatcher firstMatcher = mock(ServerWebExchangeMatcher.class);
    ServerAccessDeniedHandler secondHandler = mock(ServerAccessDeniedHandler.class);
    ServerWebExchangeMatcher secondMatcher = mock(ServerWebExchangeMatcher.class);
    given(firstMatcher.matches(this.exchange)).willReturn(MatchResult.notMatch());
    given(secondMatcher.matches(this.exchange)).willReturn(MatchResult.match());
    given(firstHandler.handle(this.exchange, null)).willReturn(Mono.empty());
    given(secondHandler.handle(this.exchange, null)).willReturn(Mono.empty());
    this.entries.add(new DelegateEntry(firstMatcher, firstHandler));
    this.entries.add(new DelegateEntry(secondMatcher, secondHandler));
    this.delegator = new ServerWebExchangeDelegatingServerAccessDeniedHandler(this.entries);
    this.delegator.handle(this.exchange, null).block();
    verify(secondHandler).handle(this.exchange, null);
    verify(firstHandler, never()).handle(this.exchange, null);
    verify(this.accessDeniedHandler, never()).handle(this.exchange, null);
}
Also used : ServerWebExchangeMatcher(org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher) DelegateEntry(org.springframework.security.web.server.authorization.ServerWebExchangeDelegatingServerAccessDeniedHandler.DelegateEntry) Test(org.junit.jupiter.api.Test)

Example 3 with DelegateEntry

use of org.springframework.security.web.server.authorization.ServerWebExchangeDelegatingServerAccessDeniedHandler.DelegateEntry in project spring-security by spring-projects.

the class ServerWebExchangeDelegatingServerAccessDeniedHandlerTests method handleWhenFirstMatchesThenOnlyFirstInvoked.

@Test
public void handleWhenFirstMatchesThenOnlyFirstInvoked() {
    ServerAccessDeniedHandler firstHandler = mock(ServerAccessDeniedHandler.class);
    ServerWebExchangeMatcher firstMatcher = mock(ServerWebExchangeMatcher.class);
    ServerAccessDeniedHandler secondHandler = mock(ServerAccessDeniedHandler.class);
    ServerWebExchangeMatcher secondMatcher = mock(ServerWebExchangeMatcher.class);
    given(firstMatcher.matches(this.exchange)).willReturn(MatchResult.match());
    given(firstHandler.handle(this.exchange, null)).willReturn(Mono.empty());
    given(secondHandler.handle(this.exchange, null)).willReturn(Mono.empty());
    this.entries.add(new DelegateEntry(firstMatcher, firstHandler));
    this.entries.add(new DelegateEntry(secondMatcher, secondHandler));
    this.delegator = new ServerWebExchangeDelegatingServerAccessDeniedHandler(this.entries);
    this.delegator.setDefaultAccessDeniedHandler(this.accessDeniedHandler);
    this.delegator.handle(this.exchange, null).block();
    verify(firstHandler).handle(this.exchange, null);
    verify(secondHandler, never()).handle(this.exchange, null);
    verify(this.accessDeniedHandler, never()).handle(this.exchange, null);
    verify(secondMatcher, never()).matches(this.exchange);
}
Also used : ServerWebExchangeMatcher(org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher) DelegateEntry(org.springframework.security.web.server.authorization.ServerWebExchangeDelegatingServerAccessDeniedHandler.DelegateEntry) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 DelegateEntry (org.springframework.security.web.server.authorization.ServerWebExchangeDelegatingServerAccessDeniedHandler.DelegateEntry)3 ServerWebExchangeMatcher (org.springframework.security.web.server.util.matcher.ServerWebExchangeMatcher)3