Search in sources :

Example 1 with SpringSecurityMessageSource

use of org.springframework.security.core.SpringSecurityMessageSource in project spring-security by spring-projects.

the class AclEntryAfterInvocationProviderTests method accessIsAllowedIfPermissionIsGranted.

@Test
public void accessIsAllowedIfPermissionIsGranted() {
    AclService service = mock(AclService.class);
    Acl acl = mock(Acl.class);
    given(acl.isGranted(any(List.class), any(List.class), anyBoolean())).willReturn(true);
    given(service.readAclById(any(), any())).willReturn(acl);
    AclEntryAfterInvocationProvider provider = new AclEntryAfterInvocationProvider(service, Arrays.asList(mock(Permission.class)));
    provider.setMessageSource(new SpringSecurityMessageSource());
    provider.setObjectIdentityRetrievalStrategy(mock(ObjectIdentityRetrievalStrategy.class));
    provider.setProcessDomainObjectClass(Object.class);
    provider.setSidRetrievalStrategy(mock(SidRetrievalStrategy.class));
    Object returned = new Object();
    assertThat(returned).isSameAs(provider.decide(mock(Authentication.class), new Object(), SecurityConfig.createList("AFTER_ACL_READ"), returned));
}
Also used : SpringSecurityMessageSource(org.springframework.security.core.SpringSecurityMessageSource) List(java.util.List) Acl(org.springframework.security.acls.model.Acl) ObjectIdentityRetrievalStrategy(org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy) AclService(org.springframework.security.acls.model.AclService) SidRetrievalStrategy(org.springframework.security.acls.model.SidRetrievalStrategy) Test(org.junit.jupiter.api.Test)

Example 2 with SpringSecurityMessageSource

use of org.springframework.security.core.SpringSecurityMessageSource in project spring-security by spring-projects.

the class BindAuthenticatorTests method setUp.

@BeforeEach
public void setUp() {
    this.authenticator = new BindAuthenticator(this.contextSource);
    this.authenticator.setMessageSource(new SpringSecurityMessageSource());
    this.bob = new UsernamePasswordAuthenticationToken("bob", "bobspassword");
}
Also used : SpringSecurityMessageSource(org.springframework.security.core.SpringSecurityMessageSource) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with SpringSecurityMessageSource

use of org.springframework.security.core.SpringSecurityMessageSource in project spring-security by spring-projects.

the class SubjectDnX509PrincipalExtractorTests method setUp.

@Before
public void setUp() {
    extractor = new SubjectDnX509PrincipalExtractor();
    extractor.setMessageSource(new SpringSecurityMessageSource());
}
Also used : SpringSecurityMessageSource(org.springframework.security.core.SpringSecurityMessageSource) SubjectDnX509PrincipalExtractor(org.springframework.security.web.authentication.preauth.x509.SubjectDnX509PrincipalExtractor) Before(org.junit.Before)

Example 4 with SpringSecurityMessageSource

use of org.springframework.security.core.SpringSecurityMessageSource in project spring-security by spring-projects.

the class AclEntryAfterInvocationProviderTests method accessIsDeniedIfPermissionIsNotGranted.

@Test
public void accessIsDeniedIfPermissionIsNotGranted() {
    AclService service = mock(AclService.class);
    Acl acl = mock(Acl.class);
    given(acl.isGranted(any(List.class), any(List.class), anyBoolean())).willReturn(false);
    // Try a second time with no permissions found
    given(acl.isGranted(any(), any(List.class), anyBoolean())).willThrow(new NotFoundException(""));
    given(service.readAclById(any(), any())).willReturn(acl);
    AclEntryAfterInvocationProvider provider = new AclEntryAfterInvocationProvider(service, Arrays.asList(mock(Permission.class)));
    provider.setProcessConfigAttribute("MY_ATTRIBUTE");
    provider.setMessageSource(new SpringSecurityMessageSource());
    provider.setObjectIdentityRetrievalStrategy(mock(ObjectIdentityRetrievalStrategy.class));
    provider.setProcessDomainObjectClass(Object.class);
    provider.setSidRetrievalStrategy(mock(SidRetrievalStrategy.class));
    assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> provider.decide(mock(Authentication.class), new Object(), SecurityConfig.createList("UNSUPPORTED", "MY_ATTRIBUTE"), new Object()));
    // Second scenario with no acls found
    assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(() -> provider.decide(mock(Authentication.class), new Object(), SecurityConfig.createList("UNSUPPORTED", "MY_ATTRIBUTE"), new Object()));
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) SpringSecurityMessageSource(org.springframework.security.core.SpringSecurityMessageSource) NotFoundException(org.springframework.security.acls.model.NotFoundException) List(java.util.List) Acl(org.springframework.security.acls.model.Acl) ObjectIdentityRetrievalStrategy(org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy) AclService(org.springframework.security.acls.model.AclService) SidRetrievalStrategy(org.springframework.security.acls.model.SidRetrievalStrategy) Test(org.junit.jupiter.api.Test)

Aggregations

SpringSecurityMessageSource (org.springframework.security.core.SpringSecurityMessageSource)4 List (java.util.List)2 Test (org.junit.jupiter.api.Test)2 Acl (org.springframework.security.acls.model.Acl)2 AclService (org.springframework.security.acls.model.AclService)2 ObjectIdentityRetrievalStrategy (org.springframework.security.acls.model.ObjectIdentityRetrievalStrategy)2 SidRetrievalStrategy (org.springframework.security.acls.model.SidRetrievalStrategy)2 Before (org.junit.Before)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1 NotFoundException (org.springframework.security.acls.model.NotFoundException)1 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)1 SubjectDnX509PrincipalExtractor (org.springframework.security.web.authentication.preauth.x509.SubjectDnX509PrincipalExtractor)1