use of org.aopalliance.intercept.MethodInvocation 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.aopalliance.intercept.MethodInvocation 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.aopalliance.intercept.MethodInvocation 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));
}
use of org.aopalliance.intercept.MethodInvocation in project spring-framework by spring-projects.
the class ThrowsAdviceInterceptorTests method testNotInvoked.
@Test
public void testNotInvoked() throws Throwable {
MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
Object ret = new Object();
MethodInvocation mi = mock(MethodInvocation.class);
given(mi.proceed()).willReturn(ret);
assertEquals(ret, ti.invoke(mi));
assertEquals(0, th.getCalls());
}
use of org.aopalliance.intercept.MethodInvocation in project spring-framework by spring-projects.
the class ThrowsAdviceInterceptorTests method testCorrectHandlerUsed.
@Test
public void testCorrectHandlerUsed() throws Throwable {
MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
FileNotFoundException ex = new FileNotFoundException();
MethodInvocation mi = mock(MethodInvocation.class);
given(mi.getMethod()).willReturn(Object.class.getMethod("hashCode"));
given(mi.getThis()).willReturn(new Object());
given(mi.proceed()).willThrow(ex);
try {
ti.invoke(mi);
fail();
} catch (Exception caught) {
assertEquals(ex, caught);
}
assertEquals(1, th.getCalls());
assertEquals(1, th.getCalls("ioException"));
}
Aggregations