Search in sources :

Example 96 with MethodInvocation

use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.

the class MethodExpressionVoterTests method hasRoleExpressionDeniesUserWithoutRole.

@Test
public void hasRoleExpressionDeniesUserWithoutRole() throws Exception {
    List<ConfigAttribute> cad = new ArrayList<>(1);
    cad.add(new PreInvocationExpressionAttribute(null, null, "hasRole('joedoesnt')"));
    MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAnArray());
    assertThat(this.am.vote(this.joe, mi, cad)).isEqualTo(AccessDecisionVoter.ACCESS_DENIED);
}
Also used : ConfigAttribute(org.springframework.security.access.ConfigAttribute) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) ArrayList(java.util.ArrayList) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.jupiter.api.Test)

Example 97 with MethodInvocation

use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.

the class MethodExpressionVoterTests method hasRoleExpressionAllowsUserWithRole.

@Test
public void hasRoleExpressionAllowsUserWithRole() throws Exception {
    MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAnArray());
    assertThat(this.am.vote(this.joe, mi, createAttributes(new PreInvocationExpressionAttribute(null, null, "hasRole('blah')")))).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
}
Also used : SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.jupiter.api.Test)

Example 98 with MethodInvocation

use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.

the class MethodExpressionVoterTests method incorrectFilterTargetNameIsRejected.

@Test
public void incorrectFilterTargetNameIsRejected() throws Exception {
    MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), createCollectionArg("joe", "bob"));
    assertThatIllegalArgumentException().isThrownBy(() -> this.am.vote(this.joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'joe')", "collcetion", null))));
}
Also used : SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.jupiter.api.Test)

Example 99 with MethodInvocation

use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.

the class AbstractAclVoterTests method correctArgumentIsSelectedFromMultipleArgs.

@Test
public void correctArgumentIsSelectedFromMultipleArgs() {
    this.voter.setProcessDomainObjectClass(String.class);
    MethodInvocation mi = MethodInvocationUtils.create(new TestClass(), "methodTakingAListAndAString", new ArrayList<>(), "The Argument");
    assertThat(this.voter.getDomainObjectInstance(mi)).isEqualTo("The Argument");
}
Also used : MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.jupiter.api.Test)

Example 100 with MethodInvocation

use of org.aopalliance.intercept.MethodInvocation in project spring-security by spring-projects.

the class MethodInvocationUtilsTests method createFromClassReturnsMethodIfArgInfoOmittedAndMethodNameIsUnique.

@Test
public void createFromClassReturnsMethodIfArgInfoOmittedAndMethodNameIsUnique() {
    MethodInvocation mi = MethodInvocationUtils.createFromClass(BusinessServiceImpl.class, "methodReturningAnArray");
    assertThat(mi).isNotNull();
}
Also used : MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.jupiter.api.Test)

Aggregations

MethodInvocation (org.aopalliance.intercept.MethodInvocation)124 Test (org.junit.jupiter.api.Test)50 Test (org.junit.Test)36 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)27 Method (java.lang.reflect.Method)24 SimpleMethodInvocation (org.springframework.security.util.SimpleMethodInvocation)22 ArrayList (java.util.ArrayList)11 Log (org.apache.commons.logging.Log)11 Authentication (org.springframework.security.core.Authentication)10 EvaluationContext (org.springframework.expression.EvaluationContext)9 Expression (org.springframework.expression.Expression)9 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)9 List (java.util.List)7 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 MyThrowsHandler (org.springframework.aop.testfixture.advice.MyThrowsHandler)7 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)7 RemoteInvocation (org.springframework.remoting.support.RemoteInvocation)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)5