1 23 24 package com.rift.coad.lib.interceptor; 25 26 import junit.framework.*; 27 import java.util.Stack ; 28 import java.util.HashSet ; 29 import java.util.Set ; 30 import org.apache.log4j.Logger; 31 import com.rift.coad.lib.security.ThreadsPermissionContainer; 32 import com.rift.coad.lib.security.ThreadPermissionSession; 33 import com.rift.coad.lib.security.UserSession; 34 35 39 public class InterceptorPermissionStackTest extends TestCase { 40 41 public InterceptorPermissionStackTest(String testName) { 42 super(testName); 43 } 44 45 protected void setUp() throws Exception { 46 } 47 48 protected void tearDown() throws Exception { 49 } 50 51 public static Test suite() { 52 TestSuite suite = new TestSuite(InterceptorPermissionStackTest.class); 53 54 return suite; 55 } 56 57 60 public void testInterceptorPermissionStack() throws Exception { 61 System.out.println("InterceptorPermissionStack"); 62 63 ThreadsPermissionContainer permissionContainer = 65 new ThreadsPermissionContainer(); 66 67 InterceptorPermissionStack instance = new InterceptorPermissionStack( 68 permissionContainer); 69 70 Set set = new HashSet (); 71 set.add("test"); 72 UserSession user = new UserSession("testuser", set); 73 74 instance.push(user); 75 76 ThreadPermissionSession permissionSession = 78 permissionContainer.getSession(Thread.currentThread().getId()); 79 if (!permissionSession.getUser().getName().equals("testuser")) { 80 fail("Username is not testuser"); 81 } 82 83 Set currentPrincipalSet = permissionSession.getPrincipals(); 84 if (currentPrincipalSet.size() != 1) { 85 fail("The principal set is not the correct size"); 86 } 87 if (!currentPrincipalSet.contains("test")) { 88 fail("Principal set does not contain the test principal"); 89 } 90 91 Set newSet = new HashSet (); 92 newSet.add("fred"); 93 newSet.add("mary"); 94 UserSession newUser = new UserSession("fred", newSet); 95 UserSession newUser2 = (UserSession)newUser.clone(); 96 if (!newUser2.getName().equals(newUser.getName())) { 97 fail("The clone did not work"); 98 } 99 100 101 instance.push(newUser); 102 103 permissionSession = 104 permissionContainer.getSession(Thread.currentThread().getId()); 105 if (!permissionSession.getUser().getName().equals("fred")) { 106 fail("Username is not fred"); 107 } 108 109 currentPrincipalSet = permissionSession.getPrincipals(); 110 if (currentPrincipalSet.size() != 2) { 111 fail("Failed the principal sets are not equal"); 112 } 113 if (!currentPrincipalSet.contains("mary")) { 114 fail("Principal set does not contain the fred principal"); 115 } 116 117 118 instance.pop(); 119 120 permissionSession = 121 permissionContainer.getSession(Thread.currentThread().getId()); 122 if (!permissionSession.getUser().getName().equals("testuser")) { 123 fail("Username is not testuser"); 124 } 125 126 currentPrincipalSet = permissionSession.getPrincipals(); 127 if (currentPrincipalSet.size() != 1) { 128 fail("The principal set is not the correct size"); 129 } 130 if (!currentPrincipalSet.contains("test")) { 131 fail("Principal set does not contain the test principal"); 132 } 133 134 instance.pop(); 135 136 permissionSession = 137 permissionContainer.getSession(Thread.currentThread().getId()); 138 if (permissionSession != null) { 139 fail("The permissions were not removed"); 140 } 141 } 142 143 144 } 145 | Popular Tags |