Search in sources :

Example 6 with MockMethodInvocation

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

the class MethodInvocationFactory method createSec2150MethodInvocation.

/**
	 * In order to reproduce the bug for SEC-2150, we must have a proxy object that
	 * implements TargetSourceAware and implements our annotated interface.
	 *
	 * @return
	 * @throws NoSuchMethodException
	 */
public static MockMethodInvocation createSec2150MethodInvocation() throws NoSuchMethodException {
    ProxyFactory factory = new ProxyFactory(new Class[] { PersonRepository.class });
    factory.setTargetClass(CrudRepository.class);
    PersonRepository repository = (PersonRepository) factory.getProxy();
    return new MockMethodInvocation(repository, PersonRepository.class, "findAll");
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory) MockMethodInvocation(org.springframework.security.access.intercept.method.MockMethodInvocation)

Example 7 with MockMethodInvocation

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

the class Jsr250MethodSecurityMetadataSourceTests method classLevelAnnotationsImpactMemberLevel.

@Test
public void classLevelAnnotationsImpactMemberLevel() throws Exception {
    Child target = new Child();
    MockMethodInvocation mi = new MockMethodInvocation(target, target.getClass(), "defaults");
    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 8 with MockMethodInvocation

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

the class Jsr250MethodSecurityMetadataSourceTests method interfacesNeverContributeAnnotationsClassLevel.

@Test
public void interfacesNeverContributeAnnotationsClassLevel() throws Exception {
    Parent target = new Parent();
    MockMethodInvocation mi = new MockMethodInvocation(target, target.getClass(), "notOverriden");
    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 9 with MockMethodInvocation

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

the class Jsr250MethodSecurityMetadataSourceTests method classLevelAnnotationsOnlyAffectTheClassTheyAnnotateAndTheirMembers.

// JSR-250 Spec Tests
/**
	 * Class-level annotations only affect the class they annotate and their members, that
	 * is, its methods and fields. They never affect a member declared by a superclass,
	 * even if it is not hidden or overridden by the class in question.
	 *
	 * @throws Exception
	 */
@Test
public void classLevelAnnotationsOnlyAffectTheClassTheyAnnotateAndTheirMembers() throws Exception {
    Child target = new Child();
    MockMethodInvocation mi = new MockMethodInvocation(target, target.getClass(), "notOverriden");
    Collection<ConfigAttribute> accessAttributes = this.mds.getAttributes(mi);
    assertThat(accessAttributes).isNull();
}
Also used : ConfigAttribute(org.springframework.security.access.ConfigAttribute) MockMethodInvocation(org.springframework.security.access.intercept.method.MockMethodInvocation) Test(org.junit.Test)

Example 10 with MockMethodInvocation

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

the class Jsr250MethodSecurityMetadataSourceTests method classLevelAnnotationsIgnoredByExplicitMemberAnnotation.

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

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