@Test public void customAnnotationAtClassLevelIsDetected() throws Exception { ConfigAttribute[] attrs = mds.getAttributes(annotatedAtClassLevel).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); }
@Test public void customAnnotationAtInterfaceLevelIsDetected() throws Exception { ConfigAttribute[] attrs = mds.getAttributes(annotatedAtInterfaceLevel).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); }
@Test public void customAnnotationAtMethodLevelIsDetected() throws Exception { ConfigAttribute[] attrs = mds.getAttributes(annotatedAtMethodLevel).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); }
@Test public void methodWithPreFilterOnlyIsAllowed() { ConfigAttribute[] attrs = mds.getAttributes(voidImpl3).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("permitAll"); assertThat(pre.getFilterExpression()).isNotNull(); assertThat(pre.getFilterExpression().getExpressionString()).isEqualTo("somePreFilterExpression"); }
@Test public void mixedClassAndMethodPreAnnotationsAreBothIncluded() { ConfigAttribute[] attrs = mds.getAttributes(voidImpl2).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("someExpression"); assertThat(pre.getFilterExpression()).isNotNull(); assertThat(pre.getFilterExpression().getExpressionString()).isEqualTo("somePreFilterExpression"); }
@Test public void methodWithPostFilterOnlyIsAllowed() { ConfigAttribute[] attrs = mds.getAttributes(listImpl1).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(2); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); assertThat(attrs[1] instanceof PostInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; PostInvocationExpressionAttribute post = (PostInvocationExpressionAttribute) attrs[1]; assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("permitAll"); assertThat(post.getFilterExpression()).isNotNull(); assertThat(post.getFilterExpression().getExpressionString()).isEqualTo("somePostFilterExpression"); }
@Test public void classLevelPreAnnotationIsPickedUpWhenNoMethodLevelExists() throws Exception { ConfigAttribute[] attrs = mds.getAttributes(voidImpl1).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getAuthorizeExpression()).isNotNull(); assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("someExpression"); assertThat(pre.getFilterExpression()).isNull(); }
@Test public void interfaceAttributesAreIncluded() { ConfigAttribute[] attrs = mds.getAttributes(notherListImpl1).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getFilterExpression()).isNotNull(); assertThat(pre.getAuthorizeExpression()).isNotNull(); assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("interfaceMethodAuthzExpression"); assertThat(pre.getFilterExpression().getExpressionString()).isEqualTo("interfacePreFilterExpression"); }
@Test public void classAttributesTakesPrecedeceOverInterfaceAttributes() { ConfigAttribute[] attrs = mds.getAttributes(notherListImpl2).toArray( new ConfigAttribute[0]); assertThat(attrs).hasSize(1); assertThat(attrs[0] instanceof PreInvocationExpressionAttribute).isTrue(); PreInvocationExpressionAttribute pre = (PreInvocationExpressionAttribute) attrs[0]; assertThat(pre.getFilterExpression()).isNotNull(); assertThat(pre.getAuthorizeExpression()).isNotNull(); assertThat(pre.getAuthorizeExpression().getExpressionString()).isEqualTo("interfaceMethodAuthzExpression"); assertThat(pre.getFilterExpression().getExpressionString()).isEqualTo("classMethodPreFilterExpression"); }
@Test public void proxyFactoryInterfaceAttributesFound() throws Exception { MockMethodInvocation mi = MethodInvocationFactory.createSec2150MethodInvocation(); Collection<ConfigAttribute> attributes = mds.getAttributes(mi); assertThat(attributes).hasSize(1); Expression expression = (Expression) ReflectionTestUtils.getField(attributes .iterator().next(), "authorizeExpression"); assertThat(expression.getExpressionString()).isEqualTo("hasRole('ROLE_PERSON')"); }