1 18 package org.apache.activemq.security; 19 20 import org.apache.activemq.command.ActiveMQQueue; 21 import org.apache.activemq.command.ActiveMQTempQueue; 22 import org.apache.activemq.jaas.GroupPrincipal; 23 24 import java.util.*; 25 26 import junit.framework.TestCase; 27 28 32 public class AuthorizationMapTest extends TestCase { 33 static final GroupPrincipal guests = new GroupPrincipal("guests"); 34 static final GroupPrincipal users = new GroupPrincipal("users"); 35 static final GroupPrincipal admins = new GroupPrincipal("admins"); 36 static final GroupPrincipal tempDestinationAdmins = new GroupPrincipal("tempDestAdmins"); 37 38 public void testAuthorizationMap() { 39 AuthorizationMap map = createAuthorizationMap(); 40 41 Set readACLs = map.getReadACLs(new ActiveMQQueue("USERS.FOO.BAR")); 42 assertEquals("set size: " + readACLs, 2, readACLs.size()); 43 assertTrue("Contains users group", readACLs.contains(admins)); 44 assertTrue("Contains users group", readACLs.contains(users)); 45 46 } 47 48 public void testAuthorizationMapWithTempDest() { 49 AuthorizationMap map = createAuthorizationMapWithTempDest(); 50 51 Set readACLs = map.getReadACLs(new ActiveMQQueue("USERS.FOO.BAR")); 52 assertEquals("set size: " + readACLs, 2, readACLs.size()); 53 assertTrue("Contains users group", readACLs.contains(admins)); 54 assertTrue("Contains users group", readACLs.contains(users)); 55 56 Set tempAdminACLs = map.getTempDestinationAdminACLs(); 57 assertEquals("set size: " + tempAdminACLs, 1, tempAdminACLs.size()); 58 assertTrue("Contains users group", tempAdminACLs.contains(tempDestinationAdmins)); 59 60 } 61 62 protected AuthorizationMap createAuthorizationMap() { 63 DefaultAuthorizationMap answer = new DefaultAuthorizationMap(); 64 65 List entries = new ArrayList(); 66 67 AuthorizationEntry entry = new AuthorizationEntry(); 68 entry.setGroupClass("org.apache.activemq.jaas.GroupPrincipal"); 69 entry.setQueue(">"); 70 try { 71 entry.setRead("admins"); 72 } catch (Exception e) { 73 fail(e.toString()); 74 } 75 76 77 entries.add(entry); 78 entry = new AuthorizationEntry(); 80 entry.setQueue("USERS.>"); 81 try { 82 entry.setRead("users"); 83 } catch (Exception e) { 84 fail(e.toString()); 85 } 86 entries.add(entry); 87 88 answer.setAuthorizationEntries(entries); 89 90 return answer; 91 } 92 93 protected AuthorizationMap createAuthorizationMapWithTempDest() { 94 DefaultAuthorizationMap answer = new DefaultAuthorizationMap(); 95 96 List entries = new ArrayList(); 97 98 AuthorizationEntry entry = new AuthorizationEntry(); 99 entry.setQueue(">"); 100 try { 101 entry.setRead("admins"); 102 } catch (Exception e) { 103 fail(e.toString()); 104 } 105 entries.add(entry); 106 107 entry = new AuthorizationEntry(); 108 entry.setQueue("USERS.>"); 109 try { 110 entry.setRead("users"); 111 } catch (Exception e) { 112 fail(e.toString()); 113 } 114 entries.add(entry); 115 116 answer.setAuthorizationEntries(entries); 117 118 TempDestinationAuthorizationEntry tEntry = new TempDestinationAuthorizationEntry(); 120 try { 121 tEntry.setAdmin("tempDestAdmins"); 122 } catch (Exception e) { 123 fail(e.toString()); 124 } 125 126 answer.setTempDestinationAuthorizationEntry(tEntry); 127 128 return answer; 129 } 130 131 } 132 | Popular Tags |