use of org.springframework.security.util.SimpleMethodInvocation 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);
}
use of org.springframework.security.util.SimpleMethodInvocation 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)));
}
use of org.springframework.security.util.SimpleMethodInvocation 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");
}
use of org.springframework.security.util.SimpleMethodInvocation in project spring-security-oauth by spring-projects.
the class OAuth2MethodSecurityExpressionHandlerTests method testScopes.
@Test
public void testScopes() throws Exception {
OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request("foo", false, Collections.singleton("read"));
Authentication userAuthentication = null;
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
MethodInvocation invocation = new SimpleMethodInvocation(this, ReflectionUtils.findMethod(getClass(), "testOauthClient"));
EvaluationContext context = handler.createEvaluationContext(oAuth2Authentication, invocation);
Expression expression = handler.getExpressionParser().parseExpression("#oauth2.hasAnyScope('read','write')");
assertTrue((Boolean) expression.getValue(context));
}
use of org.springframework.security.util.SimpleMethodInvocation in project spring-security-oauth by spring-projects.
the class OAuth2MethodSecurityExpressionHandlerTests method testNonOauthClient.
@Test
public void testNonOauthClient() throws Exception {
Authentication clientAuthentication = new UsernamePasswordAuthenticationToken("foo", "bar");
MethodInvocation invocation = new SimpleMethodInvocation(this, ReflectionUtils.findMethod(getClass(), "testNonOauthClient"));
EvaluationContext context = handler.createEvaluationContext(clientAuthentication, invocation);
Expression expression = handler.getExpressionParser().parseExpression("#oauth2.clientHasAnyRole()");
assertFalse((Boolean) expression.getValue(context));
}
Aggregations