@ -19,278 +19,243 @@ import org.springframework.security.providers.TestingAuthenticationToken;
/ * *
/ * *
* Test class for { @link AclAuthorizationStrategyImpl } and { @link AclImpl }
* Test class for { @link AclAuthorizationStrategyImpl } and { @link AclImpl }
* security checks .
* security checks .
*
*
* @author Andrei Stefan
* @author Andrei Stefan
* /
* /
public class AclImplementationSecurityCheckTests extends TestCase {
public class AclImplementationSecurityCheckTests extends TestCase {
//~ Methods ========================================================================================================
protected void setUp ( ) throws Exception {
//~ Methods ========================================================================================================
SecurityContextHolder . clearContext ( ) ;
}
protected void tearDown ( ) throws Exception {
protected void setUp ( ) throws Exception {
SecurityContextHolder . clearContext ( ) ;
SecurityContextHolder . clearContext ( ) ;
}
}
public void testSecurityCheckNoACEs ( ) throws Exception {
protected void tearDown ( ) throws Exception {
Authentication auth = new TestingAuthenticationToken ( "user" , "password" , new GrantedAuthority [ ] {
SecurityContextHolder . clearContext ( ) ;
new GrantedAuthorityImpl ( "ROLE_GENERAL" ) , new GrantedAuthorityImpl ( "ROLE_AUDITING" ) ,
}
new GrantedAuthorityImpl ( "ROLE_OWNERSHIP" ) } ) ;
auth . setAuthenticated ( true ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( auth ) ;
ObjectIdentity identity = new ObjectIdentityImpl ( "org.springframework.security.TargetObject" , new Long ( 100 ) ) ;
public void testSecurityCheckNoACEs ( ) throws Exception {
AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl ( new GrantedAuthority [ ] {
Authentication auth = new TestingAuthenticationToken ( "user" , "password" , "ROLE_GENERAL" , "ROLE_AUDITING" , "ROLE_OWNERSHIP" ) ;
new GrantedAuthorityImpl ( "ROLE_OWNERSHIP" ) , new GrantedAuthorityImpl ( "ROLE_AUDITING" ) ,
auth . setAuthenticated ( true ) ;
new GrantedAuthorityImpl ( "ROLE_GENERAL" ) } ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( auth ) ;
Acl acl = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy , new ConsoleAuditLogger ( ) ) ;
ObjectIdentity identity = new ObjectIdentityImpl ( "org.springframework.security.TargetObject" , new Long ( 100 ) ) ;
try {
AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl ( new GrantedAuthority [ ] {
aclAuthorizationStrategy . securityCheck ( acl , AclAuthorizationStrategy . CHANGE_GENERAL ) ;
new GrantedAuthorityImpl ( "ROLE_OWNERSHIP" ) , new GrantedAuthorityImpl ( "ROLE_AUDITING" ) ,
Assert . assertTrue ( true ) ;
new GrantedAuthorityImpl ( "ROLE_GENERAL" ) } ) ;
}
catch ( AccessDeniedException notExpected ) {
Assert . fail ( "It shouldn't have thrown AccessDeniedException" ) ;
}
try {
aclAuthorizationStrategy . securityCheck ( acl , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
Assert . assertTrue ( true ) ;
}
catch ( AccessDeniedException notExpected ) {
Assert . fail ( "It shouldn't have thrown AccessDeniedException" ) ;
}
try {
aclAuthorizationStrategy . securityCheck ( acl , AclAuthorizationStrategy . CHANGE_OWNERSHIP ) ;
Assert . assertTrue ( true ) ;
}
catch ( AccessDeniedException notExpected ) {
Assert . fail ( "It shouldn't have thrown AccessDeniedException" ) ;
}
// Create another authorization strategy
Acl acl = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy , new ConsoleAuditLogger ( ) ) ;
AclAuthorizationStrategy aclAuthorizationStrategy2 = new AclAuthorizationStrategyImpl ( new GrantedAuthority [ ] {
new GrantedAuthorityImpl ( "ROLE_ONE" ) , new GrantedAuthorityImpl ( "ROLE_TWO" ) ,
new GrantedAuthorityImpl ( "ROLE_THREE" ) } ) ;
Acl acl2 = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy2 , new ConsoleAuditLogger ( ) ) ;
// Check access in case the principal has no authorization rights
try {
aclAuthorizationStrategy2 . securityCheck ( acl2 , AclAuthorizationStrategy . CHANGE_GENERAL ) ;
Assert . fail ( "It should have thrown NotFoundException" ) ;
}
catch ( NotFoundException expected ) {
Assert . assertTrue ( true ) ;
}
try {
aclAuthorizationStrategy2 . securityCheck ( acl2 , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
Assert . fail ( "It should have thrown NotFoundException" ) ;
}
catch ( NotFoundException expected ) {
Assert . assertTrue ( true ) ;
}
try {
aclAuthorizationStrategy2 . securityCheck ( acl2 , AclAuthorizationStrategy . CHANGE_OWNERSHIP ) ;
Assert . fail ( "It should have thrown NotFoundException" ) ;
}
catch ( NotFoundException expected ) {
Assert . assertTrue ( true ) ;
}
}
public void testSecurityCheckWithMultipleACEs ( ) throws Exception {
aclAuthorizationStrategy . securityCheck ( acl , AclAuthorizationStrategy . CHANGE_GENERAL ) ;
// Create a simple authentication with ROLE_GENERAL
aclAuthorizationStrategy . securityCheck ( acl , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
Authentication auth = new TestingAuthenticationToken ( "user" , "password" ,
aclAuthorizationStrategy . securityCheck ( acl , AclAuthorizationStrategy . CHANGE_OWNERSHIP ) ;
new GrantedAuthority [ ] { new GrantedAuthorityImpl ( "ROLE_GENERAL" ) } ) ;
auth . setAuthenticated ( true ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( auth ) ;
ObjectIdentity identity = new ObjectIdentityImpl ( "org.springframework.security.TargetObject" , new Long ( 100 ) ) ;
// Create another authorization strategy
// Authorization strategy will require a different role for each access
AclAuthorizationStrategy aclAuthorizationStrategy2 = new AclAuthorizationStrategyImpl ( new GrantedAuthority [ ] {
AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl ( new GrantedAuthority [ ] {
new GrantedAuthorityImpl ( "ROLE_ONE" ) , new GrantedAuthorityImpl ( "ROLE_TWO" ) ,
new GrantedAuthorityImpl ( "ROLE_OWNERSHIP" ) , new GrantedAuthorityImpl ( "ROLE_AUDITING" ) ,
new GrantedAuthorityImpl ( "ROLE_THREE" ) } ) ;
new GrantedAuthorityImpl ( "ROLE_GENERAL" ) } ) ;
Acl acl2 = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy2 , new ConsoleAuditLogger ( ) ) ;
// Check access in case the principal has no authorization rights
try {
aclAuthorizationStrategy2 . securityCheck ( acl2 , AclAuthorizationStrategy . CHANGE_GENERAL ) ;
Assert . fail ( "It should have thrown NotFoundException" ) ;
}
catch ( NotFoundException expected ) {
}
try {
aclAuthorizationStrategy2 . securityCheck ( acl2 , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
Assert . fail ( "It should have thrown NotFoundException" ) ;
}
catch ( NotFoundException expected ) {
}
try {
aclAuthorizationStrategy2 . securityCheck ( acl2 , AclAuthorizationStrategy . CHANGE_OWNERSHIP ) ;
Assert . fail ( "It should have thrown NotFoundException" ) ;
}
catch ( NotFoundException expected ) {
}
}
// Let's give the principal the ADMINISTRATION permission, without
public void testSecurityCheckWithMultipleACEs ( ) throws Exception {
// granting access
// Create a simple authentication with ROLE_GENERAL
MutableAcl aclFirstDeny = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy , new ConsoleAuditLogger ( ) ) ;
Authentication auth = new TestingAuthenticationToken ( "user" , "password" ,
aclFirstDeny . insertAce ( 0 , BasePermission . ADMINISTRATION , new PrincipalSid ( auth ) , false ) ;
new GrantedAuthority [ ] { new GrantedAuthorityImpl ( "ROLE_GENERAL" ) } ) ;
auth . setAuthenticated ( true ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( auth ) ;
// The CHANGE_GENERAL test should pass as the principal has ROLE_GENERAL
ObjectIdentity identity = new ObjectIdentityImpl ( "org.springframework.security.TargetObject" , new Long ( 100 ) ) ;
try {
// Authorization strategy will require a different role for each access
aclAuthorizationStrategy . securityCheck ( aclFirstDeny , AclAuthorizationStrategy . CHANGE_GENERAL ) ;
AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl ( new GrantedAuthority [ ] {
Assert . assertTrue ( true ) ;
new GrantedAuthorityImpl ( "ROLE_OWNERSHIP" ) , new GrantedAuthorityImpl ( "ROLE_AUDITING" ) ,
}
new GrantedAuthorityImpl ( "ROLE_GENERAL" ) } ) ;
catch ( AccessDeniedException notExpected ) {
Assert . fail ( "It shouldn't have thrown AccessDeniedException" ) ;
}
// The CHANGE_AUDITING and CHANGE_OWNERSHIP should fail since the
// principal doesn't have these authorities,
// nor granting access
try {
aclAuthorizationStrategy . securityCheck ( aclFirstDeny , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
Assert . fail ( "It should have thrown AccessDeniedException" ) ;
}
catch ( AccessDeniedException expected ) {
Assert . assertTrue ( true ) ;
}
try {
aclAuthorizationStrategy . securityCheck ( aclFirstDeny , AclAuthorizationStrategy . CHANGE_OWNERSHIP ) ;
Assert . fail ( "It should have thrown AccessDeniedException" ) ;
}
catch ( AccessDeniedException expected ) {
Assert . assertTrue ( true ) ;
}
// Add granting access to this principal
// Let's give the principal the ADMINISTRATION permission, without
aclFirstDeny . insertAce ( 1 , BasePermission . ADMINISTRATION , new PrincipalSid ( auth ) , true ) ;
// granting access
// and try again for CHANGE_AUDITING - the first ACE's granting flag
MutableAcl aclFirstDeny = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy , new ConsoleAuditLogger ( ) ) ;
// (false) will deny this access
aclFirstDeny . insertAce ( 0 , BasePermission . ADMINISTRATION , new PrincipalSid ( auth ) , false ) ;
try {
aclAuthorizationStrategy . securityCheck ( aclFirstDeny , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
Assert . fail ( "It should have thrown AccessDeniedException" ) ;
}
catch ( AccessDeniedException expected ) {
Assert . assertTrue ( true ) ;
}
// Create another ACL and give the principal the ADMINISTRATION
// The CHANGE_GENERAL test should pass as the principal has ROLE_GENERAL
// permission, with granting access
aclAuthorizationStrategy . securityCheck ( aclFirstDeny , AclAuthorizationStrategy . CHANGE_GENERAL ) ;
MutableAcl aclFirstAllow = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy ,
new ConsoleAuditLogger ( ) ) ;
aclFirstAllow . insertAce ( 0 , BasePermission . ADMINISTRATION , new PrincipalSid ( auth ) , true ) ;
// The CHANGE_AUDITING test should pass as there is one ACE with
// The CHANGE_AUDITING and CHANGE_OWNERSHIP should fail since the
// granting access
// principal doesn't have these authorities,
try {
// nor granting access
aclAuthorizationStrategy . securityCheck ( aclFirstAllow , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
try {
Assert . assertTrue ( true ) ;
aclAuthorizationStrategy . securityCheck ( aclFirstDeny , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
}
Assert . fail ( "It should have thrown AccessDeniedException" ) ;
catch ( AccessDeniedException notExpected ) {
}
Assert . fail ( "It shouldn't have thrown AccessDeniedException" ) ;
catch ( AccessDeniedException expected ) {
}
}
try {
aclAuthorizationStrategy . securityCheck ( aclFirstDeny , AclAuthorizationStrategy . CHANGE_OWNERSHIP ) ;
Assert . fail ( "It should have thrown AccessDeniedException" ) ;
}
catch ( AccessDeniedException expected ) {
}
// Add a deny ACE and test again for CHANGE_AUDITING
// Add granting access to this principal
aclFirstAllow . insertAce ( 1 , BasePermission . ADMINISTRATION , new PrincipalSid ( auth ) , false ) ;
aclFirstDeny . insertAce ( 1 , BasePermission . ADMINISTRATION , new PrincipalSid ( auth ) , true ) ;
try {
// and try again for CHANGE_AUDITING - the first ACE's granting flag
aclAuthorizationStrategy . securityCheck ( aclFirstAllow , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
// (false) will deny this access
Assert . assertTrue ( true ) ;
try {
}
aclAuthorizationStrategy . securityCheck ( aclFirstDeny , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
catch ( AccessDeniedException notExpected ) {
Assert . fail ( "It should have thrown AccessDeniedException" ) ;
Assert . fail ( "It shouldn't have thrown AccessDeniedException" ) ;
}
}
catch ( AccessDeniedException expected ) {
}
// Create an ACL with no ACE
// Create another ACL and give the principal the ADMINISTRATION
MutableAcl aclNoACE = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy , new ConsoleAuditLogger ( ) ) ;
// permission, with granting access
try {
MutableAcl aclFirstAllow = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy ,
aclAuthorizationStrategy . securityCheck ( aclNoACE , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
new ConsoleAuditLogger ( ) ) ;
Assert . fail ( "It should have thrown NotFoundException" ) ;
aclFirstAllow . insertAce ( 0 , BasePermission . ADMINISTRATION , new PrincipalSid ( auth ) , true ) ;
}
catch ( NotFoundException expected ) {
Assert . assertTrue ( true ) ;
}
// and still grant access for CHANGE_GENERAL
try {
aclAuthorizationStrategy . securityCheck ( aclNoACE , AclAuthorizationStrategy . CHANGE_GENERAL ) ;
Assert . assertTrue ( true ) ;
}
catch ( NotFoundException expected ) {
Assert . fail ( "It shouldn't have thrown NotFoundException" ) ;
}
}
public void testSecurityCheckWithInheritableACEs ( ) throws Exception {
// The CHANGE_AUDITING test should pass as there is one ACE with
// Create a simple authentication with ROLE_GENERAL
// granting access
Authentication auth = new TestingAuthenticationToken ( "user" , "password" ,
new GrantedAuthority [ ] { new GrantedAuthorityImpl ( "ROLE_GENERAL" ) } ) ;
auth . setAuthenticated ( true ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( auth ) ;
ObjectIdentity identity = new ObjectIdentityImpl ( "org.springframework.security.TargetObject" , new Long ( 100 ) ) ;
aclAuthorizationStrategy . securityCheck ( aclFirstAllow , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
// Authorization strategy will require a different role for each access
AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl ( new GrantedAuthority [ ] {
new GrantedAuthorityImpl ( "ROLE_ONE" ) , new GrantedAuthorityImpl ( "ROLE_TWO" ) ,
new GrantedAuthorityImpl ( "ROLE_GENERAL" ) } ) ;
// Let's give the principal an ADMINISTRATION permission, with granting
// Add a deny ACE and test again for CHANGE_AUDITING
// access
aclFirstAllow . insertAce ( 1 , BasePermission . ADMINISTRATION , new PrincipalSid ( auth ) , false ) ;
MutableAcl parentAcl = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy , new ConsoleAuditLogger ( ) ) ;
try {
parentAcl . insertAce ( 0 , BasePermission . ADMINISTRATION , new PrincipalSid ( auth ) , true ) ;
aclAuthorizationStrategy . securityCheck ( aclFirstAllow , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
MutableAcl childAcl = new AclImpl ( identity , new Long ( 2 ) , aclAuthorizationStrategy , new ConsoleAuditLogger ( ) ) ;
Assert . assertTrue ( true ) ;
}
catch ( AccessDeniedException notExpected ) {
Assert . fail ( "It shouldn't have thrown AccessDeniedException" ) ;
}
// Check against the 'child' acl, which doesn't offer any authorization
// Create an ACL with no ACE
// rights on CHANGE_OWNERSHIP
MutableAcl aclNoACE = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy , new ConsoleAuditLogger ( ) ) ;
try {
try {
aclAuthorizationStrategy . securityCheck ( childAcl , AclAuthorizationStrategy . CHANGE_OWNERSHIP ) ;
aclAuthorizationStrategy . securityCheck ( aclNoACE , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
Assert . fail ( "It should have thrown NotFoundException" ) ;
Assert . fail ( "It should have thrown NotFoundException" ) ;
}
}
catch ( NotFoundException expected ) {
catch ( NotFoundException expected ) {
Assert . assertTrue ( true ) ;
Assert . assertTrue ( true ) ;
}
}
// and still grant access for CHANGE_GENERAL
try {
aclAuthorizationStrategy . securityCheck ( aclNoACE , AclAuthorizationStrategy . CHANGE_GENERAL ) ;
Assert . assertTrue ( true ) ;
}
catch ( NotFoundException expected ) {
Assert . fail ( "It shouldn't have thrown NotFoundException" ) ;
}
}
// Link the child with its parent and test again against the
public void testSecurityCheckWithInheritableACEs ( ) throws Exception {
// CHANGE_OWNERSHIP right
// Create a simple authentication with ROLE_GENERAL
childAcl . setParent ( parentAcl ) ;
Authentication auth = new TestingAuthenticationToken ( "user" , "password" ,
childAcl . setEntriesInheriting ( true ) ;
new GrantedAuthority [ ] { new GrantedAuthorityImpl ( "ROLE_GENERAL" ) } ) ;
try {
auth . setAuthenticated ( true ) ;
aclAuthorizationStrategy . securityCheck ( childAcl , AclAuthorizationStrategy . CHANGE_OWNERSHIP ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( auth ) ;
Assert . assertTrue ( true ) ;
}
catch ( NotFoundException expected ) {
Assert . fail ( "It shouldn't have thrown NotFoundException" ) ;
}
// Create a root parent and link it to the middle parent
ObjectIdentity identity = new ObjectIdentityImpl ( "org.springframework.security.TargetObject" , new Long ( 100 ) ) ;
MutableAcl rootParentAcl = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy ,
// Authorization strategy will require a different role for each access
new ConsoleAuditLogger ( ) ) ;
AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl ( new GrantedAuthority [ ] {
parentAcl = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy , new ConsoleAuditLogger ( ) ) ;
new GrantedAuthorityImpl ( "ROLE_ONE" ) , new GrantedAuthorityImpl ( "ROLE_TWO" ) ,
rootParentAcl . insertAce ( 0 , BasePermission . ADMINISTRATION , new PrincipalSid ( auth ) , true ) ;
new GrantedAuthorityImpl ( "ROLE_GENERAL" ) } ) ;
parentAcl . setEntriesInheriting ( true ) ;
parentAcl . setParent ( rootParentAcl ) ;
childAcl . setParent ( parentAcl ) ;
try {
aclAuthorizationStrategy . securityCheck ( childAcl , AclAuthorizationStrategy . CHANGE_OWNERSHIP ) ;
Assert . assertTrue ( true ) ;
}
catch ( NotFoundException expected ) {
Assert . fail ( "It shouldn't have thrown NotFoundException" ) ;
}
}
public void testSecurityCheckPrincipalOwner ( ) throws Exception {
// Let's give the principal an ADMINISTRATION permission, with granting
Authentication auth = new TestingAuthenticationToken ( "user" , "password" , new GrantedAuthority [ ] {
// access
new GrantedAuthorityImpl ( "ROLE_ONE" ) , new GrantedAuthorityImpl ( "ROLE_ONE" ) ,
MutableAcl parentAcl = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy , new ConsoleAuditLogger ( ) ) ;
new GrantedAuthorityImpl ( "ROLE_ONE" ) } ) ;
parentAcl . insertAce ( 0 , BasePermission . ADMINISTRATION , new PrincipalSid ( auth ) , true ) ;
auth . setAuthenticated ( true ) ;
MutableAcl childAcl = new AclImpl ( identity , new Long ( 2 ) , aclAuthorizationStrategy , new ConsoleAuditLogger ( ) ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( auth ) ;
ObjectIdentity identity = new ObjectIdentityImpl ( "org.springframework.security.TargetObject" , new Long ( 100 ) ) ;
// Check against the 'child' acl, which doesn't offer any authorization
AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl ( new GrantedAuthority [ ] {
// rights on CHANGE_OWNERSHIP
new GrantedAuthorityImpl ( "ROLE_OWNERSHIP" ) , new GrantedAuthorityImpl ( "ROLE_AUDITING" ) ,
try {
new GrantedAuthorityImpl ( "ROLE_GENERAL" ) } ) ;
aclAuthorizationStrategy . securityCheck ( childAcl , AclAuthorizationStrategy . CHANGE_OWNERSHIP ) ;
Assert . fail ( "It should have thrown NotFoundException" ) ;
}
catch ( NotFoundException expected ) {
Assert . assertTrue ( true ) ;
}
Acl acl = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy , new ConsoleAuditLogger ( ) , null , null ,
// Link the child with its parent and test again against the
false , new PrincipalSid ( auth ) ) ;
// CHANGE_OWNERSHIP right
try {
childAcl . setParent ( parentAcl ) ;
aclAuthorizationStrategy . securityCheck ( acl , AclAuthorizationStrategy . CHANGE_GENERAL ) ;
childAcl . setEntriesInheriting ( true ) ;
Assert . assertTrue ( true ) ;
try {
}
aclAuthorizationStrategy . securityCheck ( childAcl , AclAuthorizationStrategy . CHANGE_OWNERSHIP ) ;
catch ( AccessDeniedException notExpected ) {
Assert . assertTrue ( true ) ;
Assert . fail ( "It shouldn't have thrown AccessDeniedException" ) ;
}
}
catch ( NotFoundException expected ) {
try {
Assert . fail ( "It shouldn't have thrown NotFoundException" ) ;
aclAuthorizationStrategy . securityCheck ( acl , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
}
Assert . fail ( "It shouldn't have thrown AccessDeniedException" ) ;
}
// Create a root parent and link it to the middle parent
catch ( NotFoundException expected ) {
MutableAcl rootParentAcl = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy ,
Assert . assertTrue ( true ) ;
new ConsoleAuditLogger ( ) ) ;
}
parentAcl = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy , new ConsoleAuditLogger ( ) ) ;
try {
rootParentAcl . insertAce ( 0 , BasePermission . ADMINISTRATION , new PrincipalSid ( auth ) , true ) ;
aclAuthorizationStrategy . securityCheck ( acl , AclAuthorizationStrategy . CHANGE_OWNERSHIP ) ;
parentAcl . setEntriesInheriting ( true ) ;
Assert . assertTrue ( true ) ;
parentAcl . setParent ( rootParentAcl ) ;
}
childAcl . setParent ( parentAcl ) ;
catch ( AccessDeniedException notExpected ) {
try {
Assert . fail ( "It shouldn't have thrown AccessDeniedException" ) ;
aclAuthorizationStrategy . securityCheck ( childAcl , AclAuthorizationStrategy . CHANGE_OWNERSHIP ) ;
}
Assert . assertTrue ( true ) ;
}
}
catch ( NotFoundException expected ) {
Assert . fail ( "It shouldn't have thrown NotFoundException" ) ;
}
}
public void testSecurityCheckPrincipalOwner ( ) throws Exception {
Authentication auth = new TestingAuthenticationToken ( "user" , "password" , new GrantedAuthority [ ] {
new GrantedAuthorityImpl ( "ROLE_ONE" ) , new GrantedAuthorityImpl ( "ROLE_ONE" ) ,
new GrantedAuthorityImpl ( "ROLE_ONE" ) } ) ;
auth . setAuthenticated ( true ) ;
SecurityContextHolder . getContext ( ) . setAuthentication ( auth ) ;
ObjectIdentity identity = new ObjectIdentityImpl ( "org.springframework.security.TargetObject" , new Long ( 100 ) ) ;
AclAuthorizationStrategy aclAuthorizationStrategy = new AclAuthorizationStrategyImpl ( new GrantedAuthority [ ] {
new GrantedAuthorityImpl ( "ROLE_OWNERSHIP" ) , new GrantedAuthorityImpl ( "ROLE_AUDITING" ) ,
new GrantedAuthorityImpl ( "ROLE_GENERAL" ) } ) ;
Acl acl = new AclImpl ( identity , new Long ( 1 ) , aclAuthorizationStrategy , new ConsoleAuditLogger ( ) , null , null ,
false , new PrincipalSid ( auth ) ) ;
try {
aclAuthorizationStrategy . securityCheck ( acl , AclAuthorizationStrategy . CHANGE_GENERAL ) ;
Assert . assertTrue ( true ) ;
}
catch ( AccessDeniedException notExpected ) {
Assert . fail ( "It shouldn't have thrown AccessDeniedException" ) ;
}
try {
aclAuthorizationStrategy . securityCheck ( acl , AclAuthorizationStrategy . CHANGE_AUDITING ) ;
Assert . fail ( "It shouldn't have thrown AccessDeniedException" ) ;
}
catch ( NotFoundException expected ) {
Assert . assertTrue ( true ) ;
}
try {
aclAuthorizationStrategy . securityCheck ( acl , AclAuthorizationStrategy . CHANGE_OWNERSHIP ) ;
Assert . assertTrue ( true ) ;
}
catch ( AccessDeniedException notExpected ) {
Assert . fail ( "It shouldn't have thrown AccessDeniedException" ) ;
}
}
}
}