1 19 20 package com.sslexplorer.testcontainer.policyframework; 21 22 import static org.junit.Assert.assertEquals; 23 import static org.junit.Assert.assertFalse; 24 import static org.junit.Assert.assertTrue; 25 26 import java.util.Collections ; 27 28 import org.junit.Test; 29 30 import com.sslexplorer.boot.PropertyList; 31 import com.sslexplorer.navigation.Favorite; 32 import com.sslexplorer.policyframework.AccessRights; 33 import com.sslexplorer.policyframework.Permission; 34 import com.sslexplorer.policyframework.Policy; 35 import com.sslexplorer.policyframework.PolicyConstants; 36 import com.sslexplorer.policyframework.PolicyDatabaseFactory; 37 import com.sslexplorer.policyframework.Resource; 38 import com.sslexplorer.realms.Realm; 39 import com.sslexplorer.security.Role; 40 import com.sslexplorer.security.SystemDatabaseFactory; 41 import com.sslexplorer.security.User; 42 43 46 public abstract class AbstractTestPolicyEnabledResource<T extends Resource> extends AbstractTestResource<T> { 47 50 @Test 51 public void checkAllAccessRights() throws Exception { 52 Realm realm = getDefaultRealm(); 53 Policy policy = createPolicy(realm); 54 User user = createAccount(); 55 getPolicyService().grantPolicyToPrincipal(policy, user); 56 AccessRights accessRights = createAllAccessRights(getResourceType().getPermissionClass()); 57 PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()}); 58 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo()); 59 60 assertEquals("The newly created and default.", getPolicyService().getPermittingAccessRights(null, null, null, user).size(), getDefaultAccessRightCount() + 1); 61 Permission[] permissions = new Permission[] {PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, PolicyConstants.PERM_DELETE}; 62 assertTrue("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 63 64 getPolicyService().revokePolicyFromPrincipal(policy, user); 65 deleteAccount(user); 66 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo()); 67 getPolicyService().deleteAccessRights(accessRights.getResourceId()); 68 getPolicyService().deletePolicy(policy.getResourceId()); 69 } 70 71 74 @Test 75 public void checkNoAccessRights() throws Exception { 76 Realm realm = getDefaultRealm(); 77 Policy policy = createPolicy(realm); 78 User user = createAccount(); 79 getPolicyService().grantPolicyToPrincipal(policy, user); 80 AccessRights accessRights = createAllAccessRights(getResourceType().getPermissionClass()); 81 PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()}); 82 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo()); 83 84 Permission[] permissions = new Permission[] {}; 85 assertFalse("The permissions should not be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 86 87 getPolicyService().revokePolicyFromPrincipal(policy, user); 88 deleteAccount(user); 89 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo()); 90 getPolicyService().deleteAccessRights(accessRights.getResourceId()); 91 getPolicyService().deletePolicy(policy.getResourceId()); 92 } 93 94 97 @Test 98 public void checkDeleteAccessRights() throws Exception { 99 Realm realm = getDefaultRealm(); 100 Policy policy = createPolicy(realm); 101 User user = createAccount(); 102 getPolicyService().grantPolicyToPrincipal(policy, user); 103 AccessRights accessRights = createDeleteAccessRights(getResourceType().getPermissionClass()); 104 PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()}); 105 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo()); 106 107 Permission[] permissions = new Permission[] {PolicyConstants.PERM_DELETE}; 108 assertTrue("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 109 permissions = new Permission[] {PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN}; 110 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 111 permissions = new Permission[] {PolicyConstants.PERM_EDIT_AND_ASSIGN}; 112 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 113 permissions = new Permission[] {PolicyConstants.PERM_ASSIGN}; 114 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 115 116 getPolicyService().revokePolicyFromPrincipal(policy, user); 117 deleteAccount(user); 118 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo()); 119 getPolicyService().deleteAccessRights(accessRights.getResourceId()); 120 getPolicyService().deletePolicy(policy.getResourceId()); 121 } 122 123 126 @Test 127 public void checkCreateEditAssignAssignAccessRights() throws Exception { 128 Realm realm = getDefaultRealm(); 129 Policy policy = createPolicy(realm); 130 User user = createAccount(); 131 getPolicyService().grantPolicyToPrincipal(policy, user); 132 AccessRights accessRights = createCreateEditAssignAccessRights(getResourceType().getPermissionClass()); 133 PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()}); 134 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo()); 135 136 Permission[] permissions = new Permission[] {PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN}; 137 assertTrue("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 138 permissions = new Permission[] {PolicyConstants.PERM_DELETE}; 139 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 140 permissions = new Permission[] {PolicyConstants.PERM_EDIT_AND_ASSIGN}; 141 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 142 permissions = new Permission[] {PolicyConstants.PERM_ASSIGN}; 143 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 144 145 getPolicyService().revokePolicyFromPrincipal(policy, user); 146 deleteAccount(user); 147 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo()); 148 getPolicyService().deleteAccessRights(accessRights.getResourceId()); 149 getPolicyService().deletePolicy(policy.getResourceId()); 150 } 151 152 155 @Test 156 public void checkEditAssignAccessRights() throws Exception { 157 Realm realm = getDefaultRealm(); 158 Policy policy = createPolicy(realm); 159 int users = getDefaultUserDatabase().listAllUsers("*.*").length ; 160 User user = createAccount(); 161 assertEquals(getDefaultUserDatabase().listAllUsers("*.*").length, users +1); 162 getPolicyService().grantPolicyToPrincipal(policy, user); 163 AccessRights accessRights = createEditAssignAccessRights(getResourceType().getPermissionClass()); 164 PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()}); 165 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo()); 166 167 Permission[] permissions = new Permission[] {PolicyConstants.PERM_EDIT_AND_ASSIGN}; 168 assertTrue("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 169 permissions = new Permission[] {PolicyConstants.PERM_DELETE}; 170 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 171 permissions = new Permission[] {PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN}; 172 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 173 permissions = new Permission[] {PolicyConstants.PERM_ASSIGN}; 174 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 175 176 getPolicyService().revokePolicyFromPrincipal(policy, user); 177 deleteAccount(user); 178 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo()); 179 getPolicyService().deleteAccessRights(accessRights.getResourceId()); 180 getPolicyService().deletePolicy(policy.getResourceId()); 181 } 182 183 186 @Test 187 public void checkAssignAccessRights() throws Exception { 188 Realm realm = getDefaultRealm(); 189 Policy policy = createPolicy(realm); 190 User user = createAccount(); 191 getPolicyService().grantPolicyToPrincipal(policy, user); 192 AccessRights accessRights = createAssignAccessRights(getResourceType().getPermissionClass()); 193 PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()}); 194 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo()); 195 196 Permission[] permissions = new Permission[] {PolicyConstants.PERM_ASSIGN}; 197 assertTrue("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 198 permissions = new Permission[] {PolicyConstants.PERM_DELETE}; 199 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 200 permissions = new Permission[] {PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN}; 201 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 202 permissions = new Permission[] {PolicyConstants.PERM_EDIT_AND_ASSIGN}; 203 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 204 205 getPolicyService().revokePolicyFromPrincipal(policy, user); 206 deleteAccount(user); 207 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo()); 208 getPolicyService().deleteAccessRights(accessRights.getResourceId()); 209 getPolicyService().deletePolicy(policy.getResourceId()); 210 } 211 212 215 @Test 216 public void checkResourceAccessRights() throws Exception { 217 Realm realm = getDefaultRealm(); 218 Policy policy = createPolicy(realm); 219 User user = createAccount(); 220 getPolicyService().grantPolicyToPrincipal(policy, user); 221 AccessRights accessRights = createAssignAccessRights(getResourceType().getPermissionClass()); 222 PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()}); 223 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo()); 224 225 T resource = createResource(); 226 assertFalse("Should not be.", getPolicyService().isPrincipalGrantedResourcesOfType(user, resource.getResourceType(), null)); 227 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(resource, selectedPolicies, getSessionInfo()); 228 assertTrue("Should be.", getPolicyService().isPrincipalGrantedResourcesOfType(user, resource.getResourceType(), null)); 229 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(resource, getSessionInfo()); 230 assertFalse("Should not be.", getPolicyService().isPrincipalGrantedResourcesOfType(user, resource.getResourceType(), null)); 231 232 getPolicyService().revokePolicyFromPrincipal(policy, user); 233 deleteAccount(user); 234 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo()); 235 deleteResource(resource); 236 getPolicyService().deleteAccessRights(accessRights.getResourceId()); 237 getPolicyService().deletePolicy(policy.getResourceId()); 238 } 239 240 243 @Test 244 public void checkResourceAccessViaRole() throws Exception { 245 User user = createAccount(); 246 Role role = createRole(); 247 user = updateAccountRoles(user, Collections.singleton(role)); 248 Realm realm = getDefaultRealm(); 249 Policy policy = createPolicy(realm); 250 T resource = createResource(); 251 getPolicyService().attachResourceToPolicy(resource, policy, 0, realm); 252 253 assertFalse("User should not have access", PolicyDatabaseFactory.getInstance().isPrincipalAllowed(user, resource, false)); 254 getPolicyService().grantPolicyToPrincipal(policy, role); 255 assertTrue("User should have access", PolicyDatabaseFactory.getInstance().isPrincipalAllowed(user, resource, false)); 256 getPolicyService().revokePolicyFromPrincipal(policy, role); 257 assertFalse("User should not have access", PolicyDatabaseFactory.getInstance().isPrincipalAllowed(user, resource, false)); 258 259 deleteResource(resource); 260 getPolicyService().deletePolicy(policy.getResourceId()); 261 user = updateAccountRoles(user, Collections.<Role>emptyList()); 262 deleteRole(role); 263 deleteAccount(user); 264 } 265 266 269 @Test 270 public void checkAllAccessRightsViaRole() throws Exception { 271 User user = createAccount(); 272 Role role = createRole(); 273 user = updateAccountRoles(user, Collections.singleton(role)); 274 Realm realm = getDefaultRealm(); 275 Policy policy = createPolicy(realm); 276 T resource = createResource(); 277 getPolicyService().attachResourceToPolicy(resource, policy, 0, realm); 278 279 getPolicyService().grantPolicyToPrincipal(policy, role); 280 AccessRights accessRights = createAllAccessRights(getResourceType().getPermissionClass()); 281 PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()}); 282 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo()); 283 284 assertEquals("The newly created and default.", getPolicyService().getPermittingAccessRights(null, null, null, user).size(), getDefaultAccessRightCount() + 1); 285 Permission[] permissions = new Permission[] {PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, PolicyConstants.PERM_DELETE}; 286 assertTrue("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 287 288 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo()); 289 getPolicyService().deleteAccessRights(accessRights.getResourceId()); 290 deleteResource(resource); 291 getPolicyService().deletePolicy(policy.getResourceId()); 292 user = updateAccountRoles(user, Collections.<Role>emptyList()); 293 deleteRole(role); 294 deleteAccount(user); 295 } 296 297 300 @Test 301 public void checkNoAccessRightsViaRole() throws Exception { 302 User user = createAccount(); 303 Role role = createRole(); 304 user = updateAccountRoles(user, Collections.singleton(role)); 305 Realm realm = getDefaultRealm(); 306 Policy policy = createPolicy(realm); 307 T resource = createResource(); 308 getPolicyService().attachResourceToPolicy(resource, policy, 0, realm); 309 310 getPolicyService().grantPolicyToPrincipal(policy, role); 311 AccessRights accessRights = createAllAccessRights(getResourceType().getPermissionClass()); 312 PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()}); 313 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo()); 314 315 Permission[] permissions = new Permission[] {}; 316 assertFalse("The permissions should not be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 317 318 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo()); 319 getPolicyService().deleteAccessRights(accessRights.getResourceId()); 320 deleteResource(resource); 321 getPolicyService().deletePolicy(policy.getResourceId()); 322 user = updateAccountRoles(user, Collections.<Role>emptyList()); 323 deleteRole(role); 324 deleteAccount(user); 325 } 326 327 330 @Test 331 public void checkDeleteAccessRightsViaRole() throws Exception { 332 User user = createAccount(); 333 Role role = createRole(); 334 user = updateAccountRoles(user, Collections.singleton(role)); 335 Realm realm = getDefaultRealm(); 336 Policy policy = createPolicy(realm); 337 T resource = createResource(); 338 getPolicyService().attachResourceToPolicy(resource, policy, 0, realm); 339 340 getPolicyService().grantPolicyToPrincipal(policy, role); 341 AccessRights accessRights = createDeleteAccessRights(getResourceType().getPermissionClass()); 342 PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()}); 343 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo()); 344 345 Permission[] permissions = new Permission[] {PolicyConstants.PERM_DELETE}; 346 assertTrue("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 347 permissions = new Permission[] {PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN}; 348 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 349 permissions = new Permission[] {PolicyConstants.PERM_EDIT_AND_ASSIGN}; 350 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 351 permissions = new Permission[] {PolicyConstants.PERM_ASSIGN}; 352 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 353 354 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo()); 355 getPolicyService().deleteAccessRights(accessRights.getResourceId()); 356 deleteResource(resource); 357 getPolicyService().deletePolicy(policy.getResourceId()); 358 user = updateAccountRoles(user, Collections.<Role>emptyList()); 359 deleteRole(role); 360 deleteAccount(user); 361 } 362 363 366 @Test 367 public void checkCreateEditAssignAssignAccessRightsViaRole() throws Exception { 368 User user = createAccount(); 369 Role role = createRole(); 370 user = updateAccountRoles(user, Collections.singleton(role)); 371 Realm realm = getDefaultRealm(); 372 Policy policy = createPolicy(realm); 373 T resource = createResource(); 374 getPolicyService().attachResourceToPolicy(resource, policy, 0, realm); 375 376 getPolicyService().grantPolicyToPrincipal(policy, role); 377 AccessRights accessRights = createCreateEditAssignAccessRights(getResourceType().getPermissionClass()); 378 PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()}); 379 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo()); 380 381 Permission[] permissions = new Permission[] {PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN}; 382 assertTrue("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 383 permissions = new Permission[] {PolicyConstants.PERM_DELETE}; 384 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 385 permissions = new Permission[] {PolicyConstants.PERM_EDIT_AND_ASSIGN}; 386 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 387 permissions = new Permission[] {PolicyConstants.PERM_ASSIGN}; 388 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 389 390 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo()); 391 getPolicyService().deleteAccessRights(accessRights.getResourceId()); 392 deleteResource(resource); 393 getPolicyService().deletePolicy(policy.getResourceId()); 394 user = updateAccountRoles(user, Collections.<Role>emptyList()); 395 deleteRole(role); 396 deleteAccount(user); 397 } 398 399 402 @Test 403 public void checkEditAssignAccessRightsViaRole() throws Exception { 404 User user = createAccount(); 405 Role role = createRole(); 406 user = updateAccountRoles(user, Collections.singleton(role)); 407 Realm realm = getDefaultRealm(); 408 Policy policy = createPolicy(realm); 409 T resource = createResource(); 410 getPolicyService().attachResourceToPolicy(resource, policy, 0, realm); 411 412 getPolicyService().grantPolicyToPrincipal(policy, role); 413 AccessRights accessRights = createEditAssignAccessRights(getResourceType().getPermissionClass()); 414 PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()}); 415 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo()); 416 417 Permission[] permissions = new Permission[] {PolicyConstants.PERM_EDIT_AND_ASSIGN}; 418 assertTrue("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 419 permissions = new Permission[] {PolicyConstants.PERM_DELETE}; 420 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 421 permissions = new Permission[] {PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN}; 422 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 423 permissions = new Permission[] {PolicyConstants.PERM_ASSIGN}; 424 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 425 426 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo()); 427 getPolicyService().deleteAccessRights(accessRights.getResourceId()); 428 deleteResource(resource); 429 getPolicyService().deletePolicy(policy.getResourceId()); 430 user = updateAccountRoles(user, Collections.<Role>emptyList()); 431 deleteRole(role); 432 deleteAccount(user); 433 } 434 435 438 @Test 439 public void checkAssignAccessRightsViaRole() throws Exception { 440 User user = createAccount(); 441 Role role = createRole(); 442 user = updateAccountRoles(user, Collections.singleton(role)); 443 Realm realm = getDefaultRealm(); 444 Policy policy = createPolicy(realm); 445 T resource = createResource(); 446 getPolicyService().attachResourceToPolicy(resource, policy, 0, realm); 447 448 getPolicyService().grantPolicyToPrincipal(policy, role); 449 AccessRights accessRights = createAssignAccessRights(getResourceType().getPermissionClass()); 450 PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()}); 451 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(accessRights, selectedPolicies, getSessionInfo()); 452 453 Permission[] permissions = new Permission[] {PolicyConstants.PERM_ASSIGN}; 454 assertTrue("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 455 permissions = new Permission[] {PolicyConstants.PERM_DELETE}; 456 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 457 permissions = new Permission[] {PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN}; 458 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 459 permissions = new Permission[] {PolicyConstants.PERM_EDIT_AND_ASSIGN}; 460 assertFalse("The permissions should be permitted.", getPolicyService().isPermitted(getResourceType(), permissions, user, false)); 461 462 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(accessRights, getSessionInfo()); 463 getPolicyService().deleteAccessRights(accessRights.getResourceId()); 464 deleteResource(resource); 465 getPolicyService().deletePolicy(policy.getResourceId()); 466 user = updateAccountRoles(user, Collections.<Role>emptyList()); 467 deleteRole(role); 468 deleteAccount(user); 469 } 470 471 474 @Test 475 public void testFavorites() throws Exception { 476 Realm realm = getDefaultRealm(); 477 Policy policy = createPolicy(realm); 478 T resource = createResource(); 479 User user = createAccount(); 480 PropertyList selectedPolicies = PropertyList.createFromArray(new int[] {policy.getResourceId()}); 481 PolicyDatabaseFactory.getInstance().attachResourceToPolicyList(resource, selectedPolicies, getSessionInfo()); 482 getPolicyService().grantPolicyToPrincipal(policy, user); 483 484 assertEquals("There should be no favorites", 0, SystemDatabaseFactory.getInstance().getFavorites(resource.getResourceType().getResourceTypeId(), user).size()); 485 SystemDatabaseFactory.getInstance().addFavorite(resource.getResourceType().getResourceTypeId(), resource.getResourceId(), user.getPrincipalName()); 486 assertEquals("There should now be one favorites", 1, SystemDatabaseFactory.getInstance().getFavorites(resource.getResourceType().getResourceTypeId(), user).size()); 487 488 Favorite favorite = SystemDatabaseFactory.getInstance().getFavorite(resource.getResourceType().getResourceTypeId(), user, resource.getResourceId()); 489 assertEquals("The favorite and resource id should match.", resource.getResourceId(), favorite.getFavoriteKey()); 490 assertEquals("The favorite username should match the users principle name.", user.getPrincipalName(), favorite.getUsername()); 491 assertEquals("The favorite type id and resource type id should match.", resource.getResourceType().getResourceTypeId(), favorite.getType()); 492 493 SystemDatabaseFactory.getInstance().removeFavorite(resource.getResourceType().getResourceTypeId(), resource.getResourceId(), user.getPrincipalName()); 494 assertEquals("There should be no favorites", 0, SystemDatabaseFactory.getInstance().getFavorites(resource.getResourceType().getResourceTypeId(), user).size()); 495 496 getPolicyService().revokePolicyFromPrincipal(policy, user); 497 PolicyDatabaseFactory.getInstance().detachResourceFromPolicyList(resource, getSessionInfo()); 498 deleteResource(resource); 499 getResource(resource); 500 getPolicyService().deletePolicy(policy.getResourceId()); 501 } 502 } | Popular Tags |