use of org.springframework.security.access.ConfigAttribute in project spring-security by spring-projects.
the class SecuredAnnotationSecurityMetadataSourceTests method classLevelAttributesAreFound.
@Test
public void classLevelAttributesAreFound() {
Collection<ConfigAttribute> attrs = this.mds.findAttributes(BusinessService.class);
assertThat(attrs).isNotNull();
// expect 1 annotation
assertThat(attrs).hasSize(1);
// should have 1 SecurityConfig
SecurityConfig sc = (SecurityConfig) attrs.toArray()[0];
assertThat(sc.getAttribute()).isEqualTo("ROLE_USER");
}
use of org.springframework.security.access.ConfigAttribute in project spring-security by spring-projects.
the class SecuredAnnotationSecurityMetadataSourceTests method genericsSuperclassDeclarationsAreIncludedWhenSubclassesOverride.
// ~ Methods
// ========================================================================================================
@Test
public void genericsSuperclassDeclarationsAreIncludedWhenSubclassesOverride() {
Method method = null;
try {
method = DepartmentServiceImpl.class.getMethod("someUserMethod3", new Class[] { Department.class });
} catch (NoSuchMethodException unexpected) {
fail("Should be a superMethod called 'someUserMethod3' on class!");
}
Collection<ConfigAttribute> attrs = mds.findAttributes(method, DepartmentServiceImpl.class);
assertThat(attrs).isNotNull();
// expect 1 attribute
assertThat(attrs.size() == 1).as("Did not find 1 attribute").isTrue();
// should have 1 SecurityConfig
for (ConfigAttribute sc : attrs) {
assertThat(sc.getAttribute()).as("Found an incorrect role").isEqualTo("ROLE_ADMIN");
}
Method superMethod = null;
try {
superMethod = DepartmentServiceImpl.class.getMethod("someUserMethod3", new Class[] { Entity.class });
} catch (NoSuchMethodException unexpected) {
fail("Should be a superMethod called 'someUserMethod3' on class!");
}
Collection<ConfigAttribute> superAttrs = this.mds.findAttributes(superMethod, DepartmentServiceImpl.class);
assertThat(superAttrs).isNotNull();
// This part of the test relates to SEC-274
// expect 1 attribute
assertThat(superAttrs).as("Did not find 1 attribute").hasSize(1);
// should have 1 SecurityConfig
for (ConfigAttribute sc : superAttrs) {
assertThat(sc.getAttribute()).as("Found an incorrect role").isEqualTo("ROLE_ADMIN");
}
}
use of org.springframework.security.access.ConfigAttribute 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')");
}
use of org.springframework.security.access.ConfigAttribute in project spring-security by spring-projects.
the class UnanimousBasedTests method testRoleVoterPrefixObserved.
@Test
public void testRoleVoterPrefixObserved() throws Exception {
TestingAuthenticationToken auth = makeTestTokenWithFooBarPrefix();
UnanimousBased mgr = makeDecisionManagerWithFooBarPrefix();
List<ConfigAttribute> config = SecurityConfig.createList(new String[] { "FOOBAR_1", "FOOBAR_2" });
mgr.decide(auth, new Object(), config);
}
use of org.springframework.security.access.ConfigAttribute in project spring-security by spring-projects.
the class UnanimousBasedTests method testTwoAffirmativeVotesTwoAbstainVotesGrantsAccess.
@Test
public void testTwoAffirmativeVotesTwoAbstainVotesGrantsAccess() throws Exception {
TestingAuthenticationToken auth = makeTestToken();
UnanimousBased mgr = makeDecisionManager();
List<ConfigAttribute> config = SecurityConfig.createList(new String[] { "ROLE_1", "ROLE_2" });
mgr.decide(auth, new Object(), config);
}
Aggregations