@ -40,12 +40,14 @@ import org.springframework.aop.Pointcut;
import org.springframework.security.access.AccessDeniedException ;
import org.springframework.security.access.AccessDeniedException ;
import org.springframework.security.access.prepost.PreAuthorize ;
import org.springframework.security.access.prepost.PreAuthorize ;
import org.springframework.security.authentication.TestAuthentication ;
import org.springframework.security.authentication.TestAuthentication ;
import org.springframework.security.authorization.AuthorizationAdvisorProxyFactory.TargetVisitor ;
import org.springframework.security.authorization.method.AuthorizationAdvisor ;
import org.springframework.security.authorization.method.AuthorizationAdvisor ;
import org.springframework.security.core.Authentication ;
import org.springframework.security.core.Authentication ;
import org.springframework.security.core.context.SecurityContextHolder ;
import org.springframework.security.core.context.SecurityContextHolder ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThat ;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType ;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType ;
import static org.mockito.ArgumentMatchers.any ;
import static org.mockito.BDDMockito.given ;
import static org.mockito.BDDMockito.given ;
import static org.mockito.Mockito.atLeastOnce ;
import static org.mockito.Mockito.atLeastOnce ;
import static org.mockito.Mockito.mock ;
import static org.mockito.Mockito.mock ;
@ -64,7 +66,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenPreAuthorizeThenHonors ( ) {
public void proxyWhenPreAuthorizeThenHonors ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
Flight flight = new Flight ( ) ;
Flight flight = new Flight ( ) ;
assertThat ( flight . getAltitude ( ) ) . isEqualTo ( 35000d ) ;
assertThat ( flight . getAltitude ( ) ) . isEqualTo ( 35000d ) ;
Flight secured = proxy ( factory , flight ) ;
Flight secured = proxy ( factory , flight ) ;
@ -75,7 +77,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenPreAuthorizeOnInterfaceThenHonors ( ) {
public void proxyWhenPreAuthorizeOnInterfaceThenHonors ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
assertThat ( this . alan . getFirstName ( ) ) . isEqualTo ( "alan" ) ;
assertThat ( this . alan . getFirstName ( ) ) . isEqualTo ( "alan" ) ;
User secured = proxy ( factory , this . alan ) ;
User secured = proxy ( factory , this . alan ) ;
assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( secured : : getFirstName ) ;
assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( secured : : getFirstName ) ;
@ -89,7 +91,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenPreAuthorizeOnRecordThenHonors ( ) {
public void proxyWhenPreAuthorizeOnRecordThenHonors ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
HasSecret repo = new Repository ( "secret" ) ;
HasSecret repo = new Repository ( "secret" ) ;
assertThat ( repo . secret ( ) ) . isEqualTo ( "secret" ) ;
assertThat ( repo . secret ( ) ) . isEqualTo ( "secret" ) ;
HasSecret secured = proxy ( factory , repo ) ;
HasSecret secured = proxy ( factory , repo ) ;
@ -102,7 +104,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenImmutableListThenReturnsSecuredImmutableList ( ) {
public void proxyWhenImmutableListThenReturnsSecuredImmutableList ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
List < Flight > flights = List . of ( this . flight ) ;
List < Flight > flights = List . of ( this . flight ) ;
List < Flight > secured = proxy ( factory , flights ) ;
List < Flight > secured = proxy ( factory , flights ) ;
secured . forEach (
secured . forEach (
@ -114,7 +116,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenImmutableSetThenReturnsSecuredImmutableSet ( ) {
public void proxyWhenImmutableSetThenReturnsSecuredImmutableSet ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
Set < Flight > flights = Set . of ( this . flight ) ;
Set < Flight > flights = Set . of ( this . flight ) ;
Set < Flight > secured = proxy ( factory , flights ) ;
Set < Flight > secured = proxy ( factory , flights ) ;
secured . forEach (
secured . forEach (
@ -126,7 +128,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenQueueThenReturnsSecuredQueue ( ) {
public void proxyWhenQueueThenReturnsSecuredQueue ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
Queue < Flight > flights = new LinkedList < > ( List . of ( this . flight ) ) ;
Queue < Flight > flights = new LinkedList < > ( List . of ( this . flight ) ) ;
Queue < Flight > secured = proxy ( factory , flights ) ;
Queue < Flight > secured = proxy ( factory , flights ) ;
assertThat ( flights . size ( ) ) . isEqualTo ( secured . size ( ) ) ;
assertThat ( flights . size ( ) ) . isEqualTo ( secured . size ( ) ) ;
@ -138,7 +140,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenImmutableSortedSetThenReturnsSecuredImmutableSortedSet ( ) {
public void proxyWhenImmutableSortedSetThenReturnsSecuredImmutableSortedSet ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
SortedSet < User > users = Collections . unmodifiableSortedSet ( new TreeSet < > ( Set . of ( this . alan ) ) ) ;
SortedSet < User > users = Collections . unmodifiableSortedSet ( new TreeSet < > ( Set . of ( this . alan ) ) ) ;
SortedSet < User > secured = proxy ( factory , users ) ;
SortedSet < User > secured = proxy ( factory , users ) ;
secured
secured
@ -150,7 +152,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenImmutableSortedMapThenReturnsSecuredImmutableSortedMap ( ) {
public void proxyWhenImmutableSortedMapThenReturnsSecuredImmutableSortedMap ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
SortedMap < String , User > users = Collections
SortedMap < String , User > users = Collections
. unmodifiableSortedMap ( new TreeMap < > ( Map . of ( this . alan . getId ( ) , this . alan ) ) ) ;
. unmodifiableSortedMap ( new TreeMap < > ( Map . of ( this . alan . getId ( ) , this . alan ) ) ) ;
SortedMap < String , User > secured = proxy ( factory , users ) ;
SortedMap < String , User > secured = proxy ( factory , users ) ;
@ -163,7 +165,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenImmutableMapThenReturnsSecuredImmutableMap ( ) {
public void proxyWhenImmutableMapThenReturnsSecuredImmutableMap ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
Map < String , User > users = Map . of ( this . alan . getId ( ) , this . alan ) ;
Map < String , User > users = Map . of ( this . alan . getId ( ) , this . alan ) ;
Map < String , User > secured = proxy ( factory , users ) ;
Map < String , User > secured = proxy ( factory , users ) ;
secured . forEach (
secured . forEach (
@ -175,7 +177,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenMutableListThenReturnsSecuredMutableList ( ) {
public void proxyWhenMutableListThenReturnsSecuredMutableList ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
List < Flight > flights = new ArrayList < > ( List . of ( this . flight ) ) ;
List < Flight > flights = new ArrayList < > ( List . of ( this . flight ) ) ;
List < Flight > secured = proxy ( factory , flights ) ;
List < Flight > secured = proxy ( factory , flights ) ;
secured . forEach (
secured . forEach (
@ -187,7 +189,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenMutableSetThenReturnsSecuredMutableSet ( ) {
public void proxyWhenMutableSetThenReturnsSecuredMutableSet ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
Set < Flight > flights = new HashSet < > ( Set . of ( this . flight ) ) ;
Set < Flight > flights = new HashSet < > ( Set . of ( this . flight ) ) ;
Set < Flight > secured = proxy ( factory , flights ) ;
Set < Flight > secured = proxy ( factory , flights ) ;
secured . forEach (
secured . forEach (
@ -199,7 +201,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenMutableSortedSetThenReturnsSecuredMutableSortedSet ( ) {
public void proxyWhenMutableSortedSetThenReturnsSecuredMutableSortedSet ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
SortedSet < User > users = new TreeSet < > ( Set . of ( this . alan ) ) ;
SortedSet < User > users = new TreeSet < > ( Set . of ( this . alan ) ) ;
SortedSet < User > secured = proxy ( factory , users ) ;
SortedSet < User > secured = proxy ( factory , users ) ;
secured . forEach ( ( u ) - > assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( u : : getFirstName ) ) ;
secured . forEach ( ( u ) - > assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( u : : getFirstName ) ) ;
@ -210,7 +212,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenMutableSortedMapThenReturnsSecuredMutableSortedMap ( ) {
public void proxyWhenMutableSortedMapThenReturnsSecuredMutableSortedMap ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
SortedMap < String , User > users = new TreeMap < > ( Map . of ( this . alan . getId ( ) , this . alan ) ) ;
SortedMap < String , User > users = new TreeMap < > ( Map . of ( this . alan . getId ( ) , this . alan ) ) ;
SortedMap < String , User > secured = proxy ( factory , users ) ;
SortedMap < String , User > secured = proxy ( factory , users ) ;
secured . forEach ( ( id , u ) - > assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( u : : getFirstName ) ) ;
secured . forEach ( ( id , u ) - > assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( u : : getFirstName ) ) ;
@ -221,7 +223,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenMutableMapThenReturnsSecuredMutableMap ( ) {
public void proxyWhenMutableMapThenReturnsSecuredMutableMap ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
Map < String , User > users = new HashMap < > ( Map . of ( this . alan . getId ( ) , this . alan ) ) ;
Map < String , User > users = new HashMap < > ( Map . of ( this . alan . getId ( ) , this . alan ) ) ;
Map < String , User > secured = proxy ( factory , users ) ;
Map < String , User > secured = proxy ( factory , users ) ;
secured . forEach ( ( id , u ) - > assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( u : : getFirstName ) ) ;
secured . forEach ( ( id , u ) - > assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( u : : getFirstName ) ) ;
@ -232,7 +234,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenPreAuthorizeForOptionalThenHonors ( ) {
public void proxyWhenPreAuthorizeForOptionalThenHonors ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
Optional < Flight > flights = Optional . of ( this . flight ) ;
Optional < Flight > flights = Optional . of ( this . flight ) ;
assertThat ( flights . get ( ) . getAltitude ( ) ) . isEqualTo ( 35000d ) ;
assertThat ( flights . get ( ) . getAltitude ( ) ) . isEqualTo ( 35000d ) ;
Optional < Flight > secured = proxy ( factory , flights ) ;
Optional < Flight > secured = proxy ( factory , flights ) ;
@ -243,7 +245,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenPreAuthorizeForStreamThenHonors ( ) {
public void proxyWhenPreAuthorizeForStreamThenHonors ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
Stream < Flight > flights = Stream . of ( this . flight ) ;
Stream < Flight > flights = Stream . of ( this . flight ) ;
Stream < Flight > secured = proxy ( factory , flights ) ;
Stream < Flight > secured = proxy ( factory , flights ) ;
assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( ( ) - > secured . forEach ( Flight : : getAltitude ) ) ;
assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( ( ) - > secured . forEach ( Flight : : getAltitude ) ) ;
@ -253,7 +255,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenPreAuthorizeForArrayThenHonors ( ) {
public void proxyWhenPreAuthorizeForArrayThenHonors ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
Flight [ ] flights = { this . flight } ;
Flight [ ] flights = { this . flight } ;
Flight [ ] secured = proxy ( factory , flights ) ;
Flight [ ] secured = proxy ( factory , flights ) ;
assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( secured [ 0 ] : : getAltitude ) ;
assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( secured [ 0 ] : : getAltitude ) ;
@ -263,7 +265,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenPreAuthorizeForIteratorThenHonors ( ) {
public void proxyWhenPreAuthorizeForIteratorThenHonors ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
Iterator < Flight > flights = List . of ( this . flight ) . iterator ( ) ;
Iterator < Flight > flights = List . of ( this . flight ) . iterator ( ) ;
Iterator < Flight > secured = proxy ( factory , flights ) ;
Iterator < Flight > secured = proxy ( factory , flights ) ;
assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( ( ) - > secured . next ( ) . getAltitude ( ) ) ;
assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( ( ) - > secured . next ( ) . getAltitude ( ) ) ;
@ -273,7 +275,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenPreAuthorizeForIterableThenHonors ( ) {
public void proxyWhenPreAuthorizeForIterableThenHonors ( ) {
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( this . user ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
Iterable < User > users = new UserRepository ( ) ;
Iterable < User > users = new UserRepository ( ) ;
Iterable < User > secured = proxy ( factory , users ) ;
Iterable < User > secured = proxy ( factory , users ) ;
assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( ( ) - > secured . forEach ( User : : getFirstName ) ) ;
assertThatExceptionOfType ( AccessDeniedException . class ) . isThrownBy ( ( ) - > secured . forEach ( User : : getFirstName ) ) ;
@ -282,7 +284,7 @@ public class AuthorizationAdvisorProxyFactoryTests {
@Test
@Test
public void proxyWhenPreAuthorizeForClassThenHonors ( ) {
public void proxyWhenPreAuthorizeForClassThenHonors ( ) {
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
Class < Flight > clazz = proxy ( factory , Flight . class ) ;
Class < Flight > clazz = proxy ( factory , Flight . class ) ;
assertThat ( clazz . getSimpleName ( ) ) . contains ( "SpringCGLIB$$" ) ;
assertThat ( clazz . getSimpleName ( ) ) . contains ( "SpringCGLIB$$" ) ;
Flight secured = proxy ( factory , this . flight ) ;
Flight secured = proxy ( factory , this . flight ) ;
@ -297,13 +299,30 @@ public class AuthorizationAdvisorProxyFactoryTests {
AuthorizationAdvisor advisor = mock ( AuthorizationAdvisor . class ) ;
AuthorizationAdvisor advisor = mock ( AuthorizationAdvisor . class ) ;
given ( advisor . getAdvice ( ) ) . willReturn ( advisor ) ;
given ( advisor . getAdvice ( ) ) . willReturn ( advisor ) ;
given ( advisor . getPointcut ( ) ) . willReturn ( Pointcut . TRUE ) ;
given ( advisor . getPointcut ( ) ) . willReturn ( Pointcut . TRUE ) ;
AuthorizationAdvisorProxyFactory factory = new AuthorizationAdvisorProxyFactory ( ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
factory . setAdvisors ( advisor ) ;
factory . setAdvisors ( advisor ) ;
Flight flight = proxy ( factory , this . flight ) ;
Flight flight = proxy ( factory , this . flight ) ;
flight . getAltitude ( ) ;
flight . getAltitude ( ) ;
verify ( advisor , atLeastOnce ( ) ) . getPointcut ( ) ;
verify ( advisor , atLeastOnce ( ) ) . getPointcut ( ) ;
}
}
@Test
public void setTargetVisitorThenUses ( ) {
TargetVisitor visitor = mock ( TargetVisitor . class ) ;
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
factory . setTargetVisitor ( visitor ) ;
factory . proxy ( new Flight ( ) ) ;
verify ( visitor ) . visit ( any ( ) , any ( ) ) ;
}
@Test
public void setTargetVisitorIgnoreValueTypesThenIgnores ( ) {
AuthorizationAdvisorProxyFactory factory = AuthorizationAdvisorProxyFactory . withDefaults ( ) ;
assertThatExceptionOfType ( ClassCastException . class ) . isThrownBy ( ( ) - > ( ( Integer ) factory . proxy ( 35 ) ) . intValue ( ) ) ;
factory . setTargetVisitor ( TargetVisitor . defaultsSkipValueTypes ( ) ) ;
assertThat ( factory . proxy ( 35 ) ) . isEqualTo ( 35 ) ;
}
private Authentication authenticated ( String user , String . . . authorities ) {
private Authentication authenticated ( String user , String . . . authorities ) {
return TestAuthentication . authenticated ( TestAuthentication . withUsername ( user ) . authorities ( authorities ) . build ( ) ) ;
return TestAuthentication . authenticated ( TestAuthentication . withUsername ( user ) . authorities ( authorities ) . build ( ) ) ;
}
}