Search in sources :

Example 26 with SecurityConfig

use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.

the class SecurityConfigTests method testObjectEquals.

@Test
public void testObjectEquals() throws Exception {
    SecurityConfig security1 = new SecurityConfig("TEST");
    SecurityConfig security2 = new SecurityConfig("TEST");
    assertThat(security2).isEqualTo(security1);
    // SEC-311: Must observe symmetry requirement of Object.equals(Object) contract
    String securityString1 = "TEST";
    assertThat(securityString1).isNotSameAs(security1);
    String securityString2 = "NOT_EQUAL";
    assertThat(!security1.equals(securityString2)).isTrue();
    SecurityConfig security3 = new SecurityConfig("NOT_EQUAL");
    assertThat(!security1.equals(security3)).isTrue();
    MockConfigAttribute mock1 = new MockConfigAttribute("TEST");
    assertThat(security1).isEqualTo(mock1);
    MockConfigAttribute mock2 = new MockConfigAttribute("NOT_EQUAL");
    assertThat(security1).isNotEqualTo(mock2);
    Integer int1 = Integer.valueOf(987);
    assertThat(security1).isNotEqualTo(int1);
}
Also used : SecurityConfig(org.springframework.security.access.SecurityConfig) Test(org.junit.Test)

Example 27 with SecurityConfig

use of org.springframework.security.access.SecurityConfig 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");
}
Also used : ConfigAttribute(org.springframework.security.access.ConfigAttribute) SecurityConfig(org.springframework.security.access.SecurityConfig) Test(org.junit.Test)

Example 28 with SecurityConfig

use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.

the class AfterInvocationProviderManagerTests method testSupportsSecureObjectIteration.

@Test
public void testSupportsSecureObjectIteration() 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();
    // assertFalse(manager.supports(FilterInvocation.class));
    assertThat(manager.supports(MethodInvocation.class)).isTrue();
}
Also used : SecurityConfig(org.springframework.security.access.SecurityConfig) List(java.util.List) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Vector(java.util.Vector) Test(org.junit.Test)

Example 29 with SecurityConfig

use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.

the class AfterInvocationProviderManagerTests method testRejectsNonAfterInvocationProviders.

@Test
public void testRejectsNonAfterInvocationProviders() {
    AfterInvocationProviderManager manager = new AfterInvocationProviderManager();
    List list = new Vector();
    list.add(new MockAfterInvocationProvider("swap1", MethodInvocation.class, new SecurityConfig("GIVE_ME_SWAP1")));
    list.add(Integer.valueOf(45));
    list.add(new MockAfterInvocationProvider("swap3", MethodInvocation.class, new SecurityConfig("GIVE_ME_SWAP3")));
    try {
        manager.setProviders(list);
        fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException expected) {
        assertThat(true).isTrue();
    }
}
Also used : SecurityConfig(org.springframework.security.access.SecurityConfig) List(java.util.List) SimpleMethodInvocation(org.springframework.security.util.SimpleMethodInvocation) MethodInvocation(org.aopalliance.intercept.MethodInvocation) Vector(java.util.Vector) Test(org.junit.Test)

Example 30 with SecurityConfig

use of org.springframework.security.access.SecurityConfig in project spring-security by spring-projects.

the class NullRunAsManagerTests method testNeverSupportsAttribute.

@Test
public void testNeverSupportsAttribute() {
    NullRunAsManager runAs = new NullRunAsManager();
    assertThat(runAs.supports(new SecurityConfig("X"))).isFalse();
}
Also used : SecurityConfig(org.springframework.security.access.SecurityConfig) Test(org.junit.Test)

Aggregations

SecurityConfig (org.springframework.security.access.SecurityConfig)39 Test (org.junit.Test)33 ConfigAttribute (org.springframework.security.access.ConfigAttribute)21 List (java.util.List)7 Vector (java.util.Vector)6 Authentication (org.springframework.security.core.Authentication)6 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)5 OAuth2Request (org.springframework.security.oauth2.provider.OAuth2Request)5 MethodInvocation (org.aopalliance.intercept.MethodInvocation)4 AccessDeniedException (org.springframework.security.access.AccessDeniedException)4 SimpleMethodInvocation (org.springframework.security.util.SimpleMethodInvocation)4 AuditApplicationEvent (org.springframework.boot.actuate.audit.listener.AuditApplicationEvent)3 ArrayList (java.util.ArrayList)2 AuthorizationFailureEvent (org.springframework.security.access.event.AuthorizationFailureEvent)2 DefaultFilterInvocationSecurityMetadataSource (org.springframework.security.web.access.intercept.DefaultFilterInvocationSecurityMetadataSource)2 Method (java.lang.reflect.Method)1 LinkedHashMap (java.util.LinkedHashMap)1 Before (org.junit.Before)1 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)1