Search in sources :

Example 71 with MethodInvocation

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

the class MethodExpressionVoterTests method incorrectFilterTargetNameIsRejected.

@Test(expected = IllegalArgumentException.class)
public void incorrectFilterTargetNameIsRejected() throws Exception {
    MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), createCollectionArg("joe", "bob"));
    am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'joe')", "collcetion", null)));
}
Also used : SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) PreInvocationExpressionAttribute(org.springframework.security.access.expression.method.PreInvocationExpressionAttribute) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.Test)

Example 72 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(am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute(null, null, "hasRole('blah')")))).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
}
Also used : SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) PreInvocationExpressionAttribute(org.springframework.security.access.expression.method.PreInvocationExpressionAttribute) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.Test)

Example 73 with MethodInvocation

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

the class MethodExpressionVoterTests method accessIsGrantedIfNoPreAuthorizeAttributeIsUsed.

@Test
public void accessIsGrantedIfNoPreAuthorizeAttributeIsUsed() throws Exception {
    Collection arg = createCollectionArg("joe", "bob", "sam");
    MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), arg);
    assertThat(am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'jim')", "collection", null)))).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
    // All objects should have been removed, because the expression is always false
    assertThat(arg).isEmpty();
}
Also used : SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) PreInvocationExpressionAttribute(org.springframework.security.access.expression.method.PreInvocationExpressionAttribute) Collection(java.util.Collection) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.Test)

Example 74 with MethodInvocation

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

the class MethodExpressionVoterTests method matchingArgAgainstAuthenticationNameIsSuccessful.

@Test
public void matchingArgAgainstAuthenticationNameIsSuccessful() throws Exception {
    MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAString(), "joe");
    assertThat(am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute(null, null, "(#argument == principal) and (principal == 'joe')")))).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
}
Also used : SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) PreInvocationExpressionAttribute(org.springframework.security.access.expression.method.PreInvocationExpressionAttribute) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.Test)

Example 75 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<ConfigAttribute>(1);
    cad.add(new PreInvocationExpressionAttribute(null, null, "hasRole('joedoesnt')"));
    MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAnArray());
    assertThat(am.vote(joe, mi, cad)).isEqualTo(AccessDecisionVoter.ACCESS_DENIED);
}
Also used : ConfigAttribute(org.springframework.security.access.ConfigAttribute) PreInvocationExpressionAttribute(org.springframework.security.access.expression.method.PreInvocationExpressionAttribute) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) ArrayList(java.util.ArrayList) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.Test)

Aggregations

MethodInvocation (org.aopalliance.intercept.MethodInvocation)84 Test (org.junit.Test)59 SimpleMethodInvocation (org.springframework.security.util.SimpleMethodInvocation)22 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)15 ITestBean (org.springframework.tests.sample.beans.ITestBean)13 Method (java.lang.reflect.Method)11 Log (org.apache.commons.logging.Log)9 EvaluationContext (org.springframework.expression.EvaluationContext)9 Expression (org.springframework.expression.Expression)9 PreInvocationExpressionAttribute (org.springframework.security.access.expression.method.PreInvocationExpressionAttribute)9 Authentication (org.springframework.security.core.Authentication)9 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)9 TestBean (org.springframework.tests.sample.beans.TestBean)9 IOException (java.io.IOException)8 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)7 FileNotFoundException (java.io.FileNotFoundException)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)5 AccessibleObject (java.lang.reflect.AccessibleObject)4 ConnectException (java.rmi.ConnectException)4 RemoteException (java.rmi.RemoteException)4