use of org.springframework.security.util.SimpleMethodInvocation in project spring-security by spring-projects.
the class ContextPropagatingRemoteInvocationTests method getRemoteInvocation.
private ContextPropagatingRemoteInvocation getRemoteInvocation() throws Exception {
Class<TargetObject> clazz = TargetObject.class;
Method method = clazz.getMethod("makeLowerCase", new Class[] { String.class });
MethodInvocation mi = new SimpleMethodInvocation(new TargetObject(), method, "SOME_STRING");
ContextPropagatingRemoteInvocationFactory factory = new ContextPropagatingRemoteInvocationFactory();
return (ContextPropagatingRemoteInvocation) factory.createRemoteInvocation(mi);
}
use of org.springframework.security.util.SimpleMethodInvocation in project spring-security-oauth by spring-projects.
the class OAuth2MethodSecurityExpressionHandlerTests method testScopesInsufficient.
@Test(expected = AccessDeniedException.class)
public void testScopesInsufficient() throws Exception {
AuthorizationRequest request = new AuthorizationRequest("foo", Collections.singleton("read"));
request.setResourceIdsAndAuthoritiesFromClientDetails(new BaseClientDetails("foo", "bar", "", "client_credentials", "ROLE_CLIENT"));
OAuth2Request clientAuthentication = request.createOAuth2Request();
Authentication userAuthentication = new UsernamePasswordAuthenticationToken("user", "pass", AuthorityUtils.createAuthorityList("ROLE_USER"));
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('write')");
expression.getValue(context);
}
use of org.springframework.security.util.SimpleMethodInvocation in project spring-security-oauth by spring-projects.
the class OAuth2MethodSecurityExpressionHandlerTests method testStandardSecurityRoot.
@Test
public void testStandardSecurityRoot() throws Exception {
Authentication clientAuthentication = new UsernamePasswordAuthenticationToken("foo", "bar", null);
assertTrue(clientAuthentication.isAuthenticated());
MethodInvocation invocation = new SimpleMethodInvocation(this, ReflectionUtils.findMethod(getClass(), "testStandardSecurityRoot"));
EvaluationContext context = handler.createEvaluationContext(clientAuthentication, invocation);
Expression expression = handler.getExpressionParser().parseExpression("isAuthenticated()");
assertTrue((Boolean) expression.getValue(context));
}
use of org.springframework.security.util.SimpleMethodInvocation in project spring-security-oauth by spring-projects.
the class OAuth2MethodSecurityExpressionHandlerTests method testReEvaluationWithDifferentRoot.
@Test
public void testReEvaluationWithDifferentRoot() throws Exception {
Expression expression = handler.getExpressionParser().parseExpression("#oauth2.isClient()");
MethodInvocation invocation = new SimpleMethodInvocation(this, ReflectionUtils.findMethod(getClass(), "testNonOauthClient"));
Authentication clientAuthentication = new UsernamePasswordAuthenticationToken("foo", "bar");
EvaluationContext context = handler.createEvaluationContext(clientAuthentication, invocation);
assertFalse((Boolean) expression.getValue(context));
OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request("foo", true, Collections.singleton("read"));
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(storedOAuth2Request, null);
EvaluationContext anotherContext = handler.createEvaluationContext(oAuth2Authentication, invocation);
assertTrue((Boolean) expression.getValue(anotherContext));
}
Aggregations