use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.
the class GlobalMethodSecurityBeanDefinitionParserTests method supportsExternalMetadataSource.
@Test
@SuppressWarnings("unchecked")
public void supportsExternalMetadataSource() throws Exception {
setContext("<b:bean id='target' class='" + ConcreteFoo.class.getName() + "'/>" + "<method-security-metadata-source id='mds'>" + " <protect method='" + Foo.class.getName() + ".foo' access='ROLE_ADMIN'/>" + "</method-security-metadata-source>" + "<global-method-security pre-post-annotations='enabled' metadata-source-ref='mds'/>" + AUTH_PROVIDER_XML);
// External MDS should take precedence over PreAuthorize
SecurityContextHolder.getContext().setAuthentication(bob);
Foo foo = (Foo) appContext.getBean("target");
try {
foo.foo(new SecurityConfig("A"));
fail("Bob can't invoke admin methods");
} catch (AccessDeniedException expected) {
}
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("admin", "password"));
foo.foo(new SecurityConfig("A"));
}
use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.
the class GlobalMethodSecurityBeanDefinitionParserTests method genericsMethodArgumentNamesAreResolved.
// SEC-1448
@Test
@SuppressWarnings("unchecked")
public void genericsMethodArgumentNamesAreResolved() throws Exception {
setContext("<b:bean id='target' class='" + ConcreteFoo.class.getName() + "'/>" + "<global-method-security pre-post-annotations='enabled'/>" + AUTH_PROVIDER_XML);
SecurityContextHolder.getContext().setAuthentication(bob);
Foo foo = (Foo) appContext.getBean("target");
foo.foo(new SecurityConfig("A"));
}
use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.
the class RunAsManagerImplTests method testSupports.
@Test
public void testSupports() throws Exception {
RunAsManager runAs = new RunAsManagerImpl();
assertThat(runAs.supports(new SecurityConfig("RUN_AS_SOMETHING"))).isTrue();
assertThat(!runAs.supports(new SecurityConfig("ROLE_WHICH_IS_IGNORED"))).isTrue();
assertThat(!runAs.supports(new SecurityConfig("role_LOWER_CASE_FAILS"))).isTrue();
}
use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.
the class AbstractAccessDecisionManagerTests method testDelegatesSupportsRequests.
@Test
public void testDelegatesSupportsRequests() throws Exception {
List list = new Vector();
DenyVoter voter = new DenyVoter();
DenyAgainVoter denyVoter = new DenyAgainVoter();
list.add(voter);
list.add(denyVoter);
MockDecisionManagerImpl mock = new MockDecisionManagerImpl(list);
ConfigAttribute attr = new SecurityConfig("DENY_AGAIN_FOR_SURE");
assertThat(mock.supports(attr)).isTrue();
ConfigAttribute badAttr = new SecurityConfig("WE_DONT_SUPPORT_THIS");
assertThat(!mock.supports(badAttr)).isTrue();
}
use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.
the class AfterInvocationProviderManagerTests method testSupportsConfigAttributeIteration.
@Test
public void testSupportsConfigAttributeIteration() throws Exception {
AfterInvocationProviderManager manager = new AfterInvocationProviderManager();
List list = new Vector();
list.add(new MockAfterInvocationProvider("swap1", MethodInvocation.class, new SecurityConfig("GIVE_ME_SWAP1")));
list.add(new MockAfterInvocationProvider("swap2", MethodInvocation.class, new SecurityConfig("GIVE_ME_SWAP2")));
list.add(new MockAfterInvocationProvider("swap3", MethodInvocation.class, new SecurityConfig("GIVE_ME_SWAP3")));
manager.setProviders(list);
manager.afterPropertiesSet();
assertThat(manager.supports(new SecurityConfig("UNKNOWN_ATTRIB"))).isFalse();
assertThat(manager.supports(new SecurityConfig("GIVE_ME_SWAP2"))).isTrue();
}
Aggregations