|
|
|
|
@ -1,12 +1,10 @@
@@ -1,12 +1,10 @@
|
|
|
|
|
package org.springframework.security.acls.expression; |
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
|
import static org.mockito.Mockito.*; |
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
import org.jmock.Expectations; |
|
|
|
|
import org.jmock.Mockery; |
|
|
|
|
import org.jmock.integration.junit4.JUnit4Mockery; |
|
|
|
|
import org.junit.Before; |
|
|
|
|
import org.junit.Test; |
|
|
|
|
import org.springframework.security.acls.Acl; |
|
|
|
|
@ -24,7 +22,6 @@ import org.springframework.security.core.Authentication;
@@ -24,7 +22,6 @@ import org.springframework.security.core.Authentication;
|
|
|
|
|
* @since 2.5 |
|
|
|
|
*/ |
|
|
|
|
public class AclPermissionEvaluatorTests { |
|
|
|
|
Mockery jmock = new JUnit4Mockery(); |
|
|
|
|
Authentication user; |
|
|
|
|
private AclService service; |
|
|
|
|
private ObjectIdentityRetrievalStrategy oidStrategy; |
|
|
|
|
@ -32,28 +29,22 @@ public class AclPermissionEvaluatorTests {
@@ -32,28 +29,22 @@ public class AclPermissionEvaluatorTests {
|
|
|
|
|
|
|
|
|
|
@Before |
|
|
|
|
public void setup() throws Exception { |
|
|
|
|
user = jmock.mock(Authentication.class); |
|
|
|
|
service = jmock.mock(AclService.class); |
|
|
|
|
oidStrategy = jmock.mock(ObjectIdentityRetrievalStrategy.class); |
|
|
|
|
sidStrategy = jmock.mock(SidRetrievalStrategy.class); |
|
|
|
|
user = mock(Authentication.class); |
|
|
|
|
service = mock(AclService.class); |
|
|
|
|
oidStrategy = mock(ObjectIdentityRetrievalStrategy.class); |
|
|
|
|
sidStrategy = mock(SidRetrievalStrategy.class); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
public void hasPermissionReturnsTrueIfAclGrantsPermission() throws Exception { |
|
|
|
|
AclPermissionEvaluator pe = new AclPermissionEvaluator(service); |
|
|
|
|
final Acl acl = jmock.mock(Acl.class); |
|
|
|
|
final Acl acl = mock(Acl.class); |
|
|
|
|
pe.setObjectIdentityRetrievalStrategy(oidStrategy); |
|
|
|
|
pe.setSidRetrievalStrategy(sidStrategy); |
|
|
|
|
|
|
|
|
|
jmock.checking(new Expectations() {{ |
|
|
|
|
ignoring(user); |
|
|
|
|
ignoring(oidStrategy); |
|
|
|
|
ignoring(sidStrategy); |
|
|
|
|
oneOf(service).readAclById(with(any(ObjectIdentity.class)), with(any(List.class))); |
|
|
|
|
will(returnValue(acl)); |
|
|
|
|
oneOf(acl).isGranted(with(any(List.class)), with(any(List.class)), with(equal(false))); |
|
|
|
|
will(returnValue(true)); |
|
|
|
|
}}); |
|
|
|
|
when(service.readAclById(any(ObjectIdentity.class), any(List.class))).thenReturn(acl); |
|
|
|
|
when(acl.isGranted(any(List.class), any(List.class), false)).thenReturn(true); |
|
|
|
|
|
|
|
|
|
assertTrue(pe.hasPermission(user, new Object(), "READ")); |
|
|
|
|
} |
|
|
|
|
|