Search in sources :

Example 11 with MockMethodInvocation

use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.

the class Jsr250MethodSecurityMetadataSourceTests method classLevelAnnotationsOnlyAffectTheClassTheyAnnotateAndTheirMembersOverriden.

@Test
public void classLevelAnnotationsOnlyAffectTheClassTheyAnnotateAndTheirMembersOverriden() throws Exception {
    Child target = new Child();
    MockMethodInvocation mi = new MockMethodInvocation(target, target.getClass(), "overriden");
    Collection<ConfigAttribute> accessAttributes = this.mds.getAttributes(mi);
    assertThat(accessAttributes).hasSize(1);
    assertThat(accessAttributes.toArray()[0].toString()).isEqualTo("ROLE_DERIVED");
}
Also used : ConfigAttribute(org.springframework.security.access.ConfigAttribute) MockMethodInvocation(org.springframework.security.access.intercept.method.MockMethodInvocation) Test(org.junit.Test)

Example 12 with MockMethodInvocation

use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.

the class Jsr250MethodSecurityMetadataSourceTests method interfacesNeverContributeAnnotationsMethodLevel.

/**
	 * The interfaces implemented by a class never contribute annotations to the class
	 * itself or any of its members.
	 *
	 * @throws Exception
	 */
@Test
public void interfacesNeverContributeAnnotationsMethodLevel() throws Exception {
    Parent target = new Parent();
    MockMethodInvocation mi = new MockMethodInvocation(target, target.getClass(), "interfaceMethod");
    Collection<ConfigAttribute> accessAttributes = this.mds.getAttributes(mi);
    assertThat(accessAttributes).isEmpty();
}
Also used : ConfigAttribute(org.springframework.security.access.ConfigAttribute) MockMethodInvocation(org.springframework.security.access.intercept.method.MockMethodInvocation) Test(org.junit.Test)

Example 13 with MockMethodInvocation

use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.

the class PrePostAnnotationSecurityMetadataSourceTests method proxyFactoryInterfaceAttributesFound.

@Test
public void proxyFactoryInterfaceAttributesFound() throws Exception {
    MockMethodInvocation mi = MethodInvocationFactory.createSec2150MethodInvocation();
    Collection<ConfigAttribute> attributes = mds.getAttributes(mi);
    assertThat(attributes.size()).isEqualTo(1);
    Expression expression = (Expression) ReflectionTestUtils.getField(attributes.iterator().next(), "authorizeExpression");
    assertThat(expression.getExpressionString()).isEqualTo("hasRole('ROLE_PERSON')");
}
Also used : ConfigAttribute(org.springframework.security.access.ConfigAttribute) Expression(org.springframework.expression.Expression) MockMethodInvocation(org.springframework.security.access.intercept.method.MockMethodInvocation) Test(org.junit.Test)

Example 14 with MockMethodInvocation

use of org.springframework.security.access.intercept.method.MockMethodInvocation in project spring-security by spring-projects.

the class PrePostAnnotationSecurityMetadataSourceTests method setUpData.

@Before
public void setUpData() throws Exception {
    voidImpl1 = new MockMethodInvocation(new ReturnVoidImpl1(), ReturnVoid.class, "doSomething", List.class);
    voidImpl2 = new MockMethodInvocation(new ReturnVoidImpl2(), ReturnVoid.class, "doSomething", List.class);
    voidImpl3 = new MockMethodInvocation(new ReturnVoidImpl3(), ReturnVoid.class, "doSomething", List.class);
    listImpl1 = new MockMethodInvocation(new ReturnAListImpl1(), ReturnAList.class, "doSomething", List.class);
    notherListImpl1 = new MockMethodInvocation(new ReturnAnotherListImpl1(), ReturnAnotherList.class, "doSomething", List.class);
    notherListImpl2 = new MockMethodInvocation(new ReturnAnotherListImpl2(), ReturnAnotherList.class, "doSomething", List.class);
    annotatedAtClassLevel = new MockMethodInvocation(new CustomAnnotationAtClassLevel(), ReturnVoid.class, "doSomething", List.class);
    annotatedAtInterfaceLevel = new MockMethodInvocation(new CustomAnnotationAtInterfaceLevel(), ReturnVoid2.class, "doSomething", List.class);
    annotatedAtMethodLevel = new MockMethodInvocation(new CustomAnnotationAtMethodLevel(), ReturnVoid.class, "doSomething", List.class);
}
Also used : MockMethodInvocation(org.springframework.security.access.intercept.method.MockMethodInvocation) List(java.util.List) Before(org.junit.Before)

Aggregations

MockMethodInvocation (org.springframework.security.access.intercept.method.MockMethodInvocation)14 Test (org.junit.Test)12 ConfigAttribute (org.springframework.security.access.ConfigAttribute)12 List (java.util.List)1 Before (org.junit.Before)1 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 Expression (org.springframework.expression.Expression)1