use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.
the class FilterSecurityMetadataSourceBeanDefinitionParserTests method interceptUrlsSupportPropertyPlaceholders.
// SEC-1201
@Test
public void interceptUrlsSupportPropertyPlaceholders() {
System.setProperty("secure.url", "/secure");
System.setProperty("secure.role", "ROLE_A");
setContext("<b:bean class='org.springframework.beans.factory.config.PropertyPlaceholderConfigurer'/>" + "<filter-security-metadata-source id='fids' use-expressions='false'>" + " <intercept-url pattern='${secure.url}' access='${secure.role}'/>" + "</filter-security-metadata-source>");
DefaultFilterInvocationSecurityMetadataSource fids = (DefaultFilterInvocationSecurityMetadataSource) this.appContext.getBean("fids");
Collection<ConfigAttribute> cad = fids.getAttributes(createFilterInvocation("/secure", "GET"));
assertThat(cad).isNotNull();
assertThat(cad).hasSize(1);
assertThat(cad.contains(new SecurityConfig("ROLE_A"))).isTrue();
}
use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.
the class FilterSecurityMetadataSourceBeanDefinitionParserTests method parsingMinimalConfigurationIsSuccessful.
@Test
public void parsingMinimalConfigurationIsSuccessful() {
setContext("<filter-security-metadata-source id='fids' use-expressions='false'>" + " <intercept-url pattern='/**' access='ROLE_A'/>" + "</filter-security-metadata-source>");
DefaultFilterInvocationSecurityMetadataSource fids = (DefaultFilterInvocationSecurityMetadataSource) this.appContext.getBean("fids");
Collection<ConfigAttribute> cad = fids.getAttributes(createFilterInvocation("/anything", "GET"));
assertThat(cad).isNotNull();
assertThat(cad.contains(new SecurityConfig("ROLE_A"))).isTrue();
}
use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.
the class GlobalMethodSecurityBeanDefinitionParserTests method supportsCustomAuthenticationManager.
@Test
public void supportsCustomAuthenticationManager() 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' authentication-manager-ref='customAuthMgr'/>" + "<b:bean id='customAuthMgr' class='org.springframework.security.config.method.GlobalMethodSecurityBeanDefinitionParserTests$CustomAuthManager'>" + " <b:constructor-arg value='authManager'/>" + "</b:bean>" + AUTH_PROVIDER_XML);
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 genericsAreMatchedByProtectPointcut.
// SEC-1450
@Test(expected = AuthenticationException.class)
@SuppressWarnings("unchecked")
public void genericsAreMatchedByProtectPointcut() throws Exception {
setContext("<b:bean id='target' class='org.springframework.security.config.method.GlobalMethodSecurityBeanDefinitionParserTests$ConcreteFoo'/>" + "<global-method-security>" + " <protect-pointcut expression='execution(* org..*Foo.foo(..))' access='ROLE_USER'/>" + "</global-method-security>" + AUTH_PROVIDER_XML);
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 SecurityConfigTests method testHashCode.
// ~ Methods
// ========================================================================================================
@Test
public void testHashCode() {
SecurityConfig config = new SecurityConfig("TEST");
assertThat(config.hashCode()).isEqualTo("TEST".hashCode());
}
Aggregations