Search in sources :

Example 36 with MockMethodInvocation

use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.

the class ExpressionBasedPreInvocationAdviceTests method findFilterTargetNameProvided.

@Test
public void findFilterTargetNameProvided() throws Exception {
    PreInvocationAttribute attribute = new PreInvocationExpressionAttribute("true", "param", null);
    MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "doSomethingCollection", new Class[] { List.class }, new Object[] { new ArrayList<>() });
    boolean result = this.expressionBasedPreInvocationAdvice.before(this.authentication, methodInvocation, attribute);
    assertThat(result).isTrue();
}
Also used : MockMethodInvocation(org.springframework.security.access.intercept.method.MockMethodInvocation) PreInvocationAttribute(org.springframework.security.access.prepost.PreInvocationAttribute) Test(org.junit.jupiter.api.Test)

Example 37 with MockMethodInvocation

use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.

the class ExpressionBasedPreInvocationAdviceTests method findFilterTargetNameNotProvidedArrayUnsupported.

@Test
public void findFilterTargetNameNotProvidedArrayUnsupported() throws Exception {
    PreInvocationAttribute attribute = new PreInvocationExpressionAttribute("true", "", null);
    MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "doSomethingArray", new Class[] { String[].class }, new Object[] { new String[0] });
    assertThatIllegalArgumentException().isThrownBy(() -> this.expressionBasedPreInvocationAdvice.before(this.authentication, methodInvocation, attribute));
}
Also used : MockMethodInvocation(org.springframework.security.access.intercept.method.MockMethodInvocation) PreInvocationAttribute(org.springframework.security.access.prepost.PreInvocationAttribute) Test(org.junit.jupiter.api.Test)

Example 38 with MockMethodInvocation

use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.

the class ExpressionBasedPreInvocationAdviceTests method findFilterTargetNameNotProvidedTypeNotSupported.

@Test
public void findFilterTargetNameNotProvidedTypeNotSupported() throws Exception {
    PreInvocationAttribute attribute = new PreInvocationExpressionAttribute("true", "", null);
    MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "doSomethingString", new Class[] { String.class }, new Object[] { "param" });
    assertThatIllegalArgumentException().isThrownBy(() -> this.expressionBasedPreInvocationAdvice.before(this.authentication, methodInvocation, attribute));
}
Also used : MockMethodInvocation(org.springframework.security.access.intercept.method.MockMethodInvocation) PreInvocationAttribute(org.springframework.security.access.prepost.PreInvocationAttribute) Test(org.junit.jupiter.api.Test)

Example 39 with MockMethodInvocation

use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.

the class ExpressionBasedPreInvocationAdviceTests method findFilterTargetNameProvidedButNotMatch.

@Test
public void findFilterTargetNameProvidedButNotMatch() throws Exception {
    PreInvocationAttribute attribute = new PreInvocationExpressionAttribute("true", "filterTargetDoesNotMatch", null);
    MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "doSomethingCollection", new Class[] { List.class }, new Object[] { new ArrayList<>() });
    assertThatIllegalArgumentException().isThrownBy(() -> this.expressionBasedPreInvocationAdvice.before(this.authentication, methodInvocation, attribute));
}
Also used : MockMethodInvocation(org.springframework.security.access.intercept.method.MockMethodInvocation) PreInvocationAttribute(org.springframework.security.access.prepost.PreInvocationAttribute) Test(org.junit.jupiter.api.Test)

Example 40 with MockMethodInvocation

use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.

the class PrePostAnnotationSecurityMetadataSourceTests method setUpData.

@BeforeEach
public void setUpData() throws Exception {
    this.voidImpl1 = new MockMethodInvocation(new ReturnVoidImpl1(), ReturnVoid.class, "doSomething", List.class);
    this.voidImpl2 = new MockMethodInvocation(new ReturnVoidImpl2(), ReturnVoid.class, "doSomething", List.class);
    this.voidImpl3 = new MockMethodInvocation(new ReturnVoidImpl3(), ReturnVoid.class, "doSomething", List.class);
    this.listImpl1 = new MockMethodInvocation(new ReturnAListImpl1(), ReturnAList.class, "doSomething", List.class);
    this.notherListImpl1 = new MockMethodInvocation(new ReturnAnotherListImpl1(), ReturnAnotherList.class, "doSomething", List.class);
    this.notherListImpl2 = new MockMethodInvocation(new ReturnAnotherListImpl2(), ReturnAnotherList.class, "doSomething", List.class);
    this.annotatedAtClassLevel = new MockMethodInvocation(new CustomAnnotationAtClassLevel(), ReturnVoid.class, "doSomething", List.class);
    this.annotatedAtInterfaceLevel = new MockMethodInvocation(new CustomAnnotationAtInterfaceLevel(), ReturnVoid2.class, "doSomething", List.class);
    this.annotatedAtMethodLevel = new MockMethodInvocation(new CustomAnnotationAtMethodLevel(), ReturnVoid.class, "doSomething", List.class);
}
Also used : MockMethodInvocation(org.springframework.security.access.intercept.method.MockMethodInvocation) List(java.util.List) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MockMethodInvocation (org.springframework.security.access.intercept.method.MockMethodInvocation)72 Test (org.junit.jupiter.api.Test)70 TestAuthentication (org.springframework.security.authentication.TestAuthentication)36 AuthorizationDecision (org.springframework.security.authorization.AuthorizationDecision)27 TestingAuthenticationToken (org.springframework.security.authentication.TestingAuthenticationToken)23 Authentication (org.springframework.security.core.Authentication)20 AnnotationConfigurationException (org.springframework.core.annotation.AnnotationConfigurationException)13 ConfigAttribute (org.springframework.security.access.ConfigAttribute)12 PreInvocationAttribute (org.springframework.security.access.prepost.PreInvocationAttribute)7 EvaluationContext (org.springframework.expression.EvaluationContext)3 SecurityExpressionRoot (org.springframework.security.access.expression.SecurityExpressionRoot)3 ArrayList (java.util.ArrayList)2 List (java.util.List)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 Expression (org.springframework.expression.Expression)1