public void test(Thread runnable) throws InterruptedException { // While the realm's lock is held by this thread user definitions cannot be processed // Obtain the realm's locks USERS_LOCK.writeLock().lock(); try { runnable.start(); Thread.sleep(500); // No account until lock is released and user definitions are processed assertFalse("account exists when it shouldn't", realm.accountExists("user1")); } finally { USERS_LOCK.writeLock().unlock(); } } };
public void test(Thread runnable) throws InterruptedException { // Obtain the realm's locks USERS_LOCK.writeLock().lock(); try { ROLES_LOCK.writeLock().lock(); try { // Any read threads attempting to obtain the realms lock will block runnable.start(); Thread.sleep(500); // Process role and user definitions realm.onInit(); } finally { ROLES_LOCK.writeLock().unlock(); } } finally { USERS_LOCK.writeLock().unlock(); } } };
setUsers(); Thread testTask = new Thread(testThread); realm.test(testTask); testTask.join(500); assertTrue("account doesn't exist when it should", realm.accountExists("user1")); testThread.test();
public void run() { PrincipalCollection principalCollection = new SimplePrincipalCollection("user1", "realm1"); assertTrue("permission not permitted when it should be", realm.isPermitted(principalCollection, "role1_permission1")); assertTrue("permission not permitted when it should be", realm.isPermittedAll(principalCollection, new String[]{"role1_permission1", "role2_permission2"})); } });
public void run() { try { realm.processRoleDefinitions(); } catch (ParseException e) { fail("Unable to parse role definitions"); } } });
public void run() { assertTrue("role not found when it was expected", realm.roleExists("role1")); assertTrue("user not found when it was expected", realm.accountExists("user1")); } });
public void run() { PrincipalCollection principalCollection = new SimplePrincipalCollection("user1", "realm1"); try { realm.checkPermission(principalCollection, "role1_permission1"); realm.checkPermissions(principalCollection, new String[]{"role1_permission1", "role2_permission2"}); } catch (AuthorizationException ae) { fail("principal doesn't have permission when it should"); } } });
public void run() { PrincipalCollection principalCollection = new SimplePrincipalCollection("user1", "realm1"); try { realm.checkRoles(principalCollection, new String[]{"role1", "role2"}); } catch (AuthorizationException ae) { fail("principal doesn't have all roles when it should"); } } });
public void run() { PrincipalCollection principalCollection = new SimplePrincipalCollection("user1", "realm1"); assertTrue("principal doesn't have role when it should", realm.hasRole(principalCollection, "role2")); assertTrue("principal doesn't have all roles when it should", realm.hasAllRoles(principalCollection, Arrays.asList(new String[]{"role1", "role2"}))); } });