Search in sources :

Example 1 with PreInvocationExpressionAttribute

use of org.springframework.security.access.expression.method.PreInvocationExpressionAttribute in project spring-security by spring-projects.

the class MethodExpressionVoterTests method ruleDefinedInAClassMethodIsApplied.

@Test
public void ruleDefinedInAClassMethodIsApplied() throws Exception {
    MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAString(), "joe");
    assertThat(am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute(null, null, "T(org.springframework.security.access.expression.method.SecurityRules).isJoe(#argument)")))).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 2 with PreInvocationExpressionAttribute

use of org.springframework.security.access.expression.method.PreInvocationExpressionAttribute in project spring-security by spring-projects.

the class MethodExpressionVoterTests method arraysCannotBePrefiltered.

@Test(expected = IllegalArgumentException.class)
public void arraysCannotBePrefiltered() throws Exception {
    MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingAnArray(), createArrayArg("sam", "joe"));
    am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'jim')", "someArray", 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 3 with PreInvocationExpressionAttribute

use of org.springframework.security.access.expression.method.PreInvocationExpressionAttribute in project spring-security by spring-projects.

the class MethodExpressionVoterTests method collectionPreFilteringIsSuccessful.

@Test
public void collectionPreFilteringIsSuccessful() throws Exception {
    List arg = createCollectionArg("joe", "bob", "sam");
    MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), arg);
    am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'joe' or filterObject == 'sam')", "collection", "permitAll")));
    assertThat(arg).containsExactly("joe", "sam");
}
Also used : SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) PreInvocationExpressionAttribute(org.springframework.security.access.expression.method.PreInvocationExpressionAttribute) ArrayList(java.util.ArrayList) List(java.util.List) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Test(org.junit.Test)

Example 4 with PreInvocationExpressionAttribute

use of org.springframework.security.access.expression.method.PreInvocationExpressionAttribute in project spring-security by spring-projects.

the class MethodExpressionVoterTests method nullNamedFilterTargetIsRejected.

@Test(expected = IllegalArgumentException.class)
public void nullNamedFilterTargetIsRejected() throws Exception {
    MethodInvocation mi = new SimpleMethodInvocation(new TargetImpl(), methodTakingACollection(), new Object[] { null });
    am.vote(joe, mi, createAttributes(new PreInvocationExpressionAttribute("(filterObject == 'joe')", "collection", 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 5 with PreInvocationExpressionAttribute

use of org.springframework.security.access.expression.method.PreInvocationExpressionAttribute 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)

Aggregations

MethodInvocation (org.aopalliance.intercept.MethodInvocation)9 Test (org.junit.Test)9 PreInvocationExpressionAttribute (org.springframework.security.access.expression.method.PreInvocationExpressionAttribute)9 SimpleMethodInvocation (org.springframework.security.util.SimpleMethodInvocation)9 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)1 List (java.util.List)1 ConfigAttribute (org.springframework.security.access.ConfigAttribute)1