Search in sources :

Example 1 with PreInvocationAttribute

use of org.springframework.security.access.prepost.PreInvocationAttribute in project spring-security by spring-projects.

the class ExpressionBasedPreInvocationAdviceTests method findFilterTargetNameNotProvided.

@Test
public void findFilterTargetNameNotProvided() throws Exception {
    PreInvocationAttribute attribute = new PreInvocationExpressionAttribute("true", "", 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 2 with PreInvocationAttribute

use of org.springframework.security.access.prepost.PreInvocationAttribute in project spring-security by spring-projects.

the class ExpressionBasedPreInvocationAdviceTests method findFilterTargetNameProvidedArrayUnsupported.

@Test
public void findFilterTargetNameProvidedArrayUnsupported() throws Exception {
    PreInvocationAttribute attribute = new PreInvocationExpressionAttribute("true", "param", 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 3 with PreInvocationAttribute

use of org.springframework.security.access.prepost.PreInvocationAttribute in project spring-security by spring-projects.

the class ExpressionBasedPreInvocationAdviceTests method findFilterTargetNameNotProvidedMethodAcceptMoreThenOneArgument.

@Test
public void findFilterTargetNameNotProvidedMethodAcceptMoreThenOneArgument() throws Exception {
    PreInvocationAttribute attribute = new PreInvocationExpressionAttribute("true", "", null);
    MockMethodInvocation methodInvocation = new MockMethodInvocation(new TestClass(), TestClass.class, "doSomethingTwoArgs", new Class[] { String.class, List.class }, new Object[] { "param", 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 4 with PreInvocationAttribute

use of org.springframework.security.access.prepost.PreInvocationAttribute 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 5 with PreInvocationAttribute

use of org.springframework.security.access.prepost.PreInvocationAttribute 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)

Aggregations

Test (org.junit.jupiter.api.Test)7 MockMethodInvocation (org.springframework.security.access.intercept.method.MockMethodInvocation)7 PreInvocationAttribute (org.springframework.security.access.prepost.PreInvocationAttribute)7