1 25 26 package org.objectweb.jonas.jtests.clients.security; 27 28 29 import org.objectweb.jonas.jtests.beans.secured.BaseS; 30 import org.objectweb.jonas.jtests.util.JTestCase; 31 import org.objectweb.security.context.SecurityContext; 32 import org.objectweb.security.context.SecurityCurrent; 33 34 35 41 42 public abstract class B_AccessControl extends JTestCase { 43 44 protected static String PRINCIPAL1_NAME = "principal1"; 45 protected static String PRINCIPAL3_NAME = "principal3"; 46 protected static String ROLE1_NAME = "baserole1"; 47 protected static String ROLE2_NAME = "baserole2"; 48 49 protected static SecurityCurrent current = null; 50 protected static SecurityContext principal1 = null; 51 protected static SecurityContext principal2 = null; 52 protected static SecurityContext principal3 = null; 53 protected static SecurityContext principal4 = null; 54 55 56 public B_AccessControl(String name) { 57 super(name); 58 } 59 60 64 protected void setUp() { 65 super.setUp(); 66 if (current == null) { 67 current = SecurityCurrent.getCurrent(); 68 principal1 = new SecurityContext("principal1"); 69 principal2 = new SecurityContext("principal2"); 70 String [] roles3 = new String []{"role1", "role3"}; 71 principal3 = new SecurityContext(PRINCIPAL3_NAME, roles3); 72 String [] roles4 = new String []{"role2"}; 73 principal4 = new SecurityContext("principal4", roles4); 74 } 75 } 76 77 public abstract BaseS getBaseS(String name) throws Exception ; 78 79 83 public void testGetCallerPrincipal() throws Exception { 84 current.setSecurityContext(principal1); 85 BaseS sl = getBaseS("un"); 86 assertEquals(PRINCIPAL1_NAME, sl.getPrincipalName()); 87 sl.remove(); 88 } 89 90 95 public void testIsCallerInRole() throws Exception { 96 current.setSecurityContext(principal1); 97 BaseS sl = getBaseS("deux"); 98 assertTrue(sl.isCallerInRole(ROLE1_NAME) == true); 99 assertTrue(sl.isCallerInRole(ROLE2_NAME) == false); 100 sl.remove(); 101 } 102 103 104 105 106 109 public void testBasicMethodAccept() throws Exception { 110 current.setSecurityContext(principal2); 111 BaseS sl = getBaseS("quatre"); 112 sl.simpleMethod(); 113 sl.remove(); 114 } 115 116 117 118 119 122 public void testBeanToBeanPropagation() throws Exception { 123 current.setSecurityContext(principal1); 124 BaseS sl = getBaseS("sept"); 125 assertEquals(PRINCIPAL1_NAME, sl.getPrincipalNameOfAnotherBean()); 126 sl.remove(); 127 } 128 129 130 131 132 } 133 | Popular Tags |