1717
1818package com .zimbra .cs .service .admin ;
1919
20+ import java .util .Arrays ;
2021import java .util .Iterator ;
2122import java .util .List ;
2223import java .util .Map ;
2324
2425import com .zimbra .common .account .Key ;
25- import com .zimbra .common .account .Key .DomainBy ;
2626import com .zimbra .common .service .ServiceException ;
2727import com .zimbra .common .soap .AdminConstants ;
2828import com .zimbra .common .soap .Element ;
29+ import com .zimbra .cs .account .AccessManager .AttrRightChecker ;
2930import com .zimbra .cs .account .AccountServiceException ;
3031import com .zimbra .cs .account .DistributionList ;
3132import com .zimbra .cs .account .Domain ;
33+ import com .zimbra .cs .account .DynamicGroup ;
3234import com .zimbra .cs .account .Group ;
3335import com .zimbra .cs .account .Provisioning ;
3436import com .zimbra .cs .account .accesscontrol .AdminRight ;
@@ -48,7 +50,7 @@ public boolean domainAuthSufficient(Map context) {
4850 }
4951
5052 public Element handle (Element request , Map <String , Object > context ) throws ServiceException {
51-
53+
5254 ZimbraSoapContext zsc = getZimbraSoapContext (context );
5355 Provisioning prov = Provisioning .getInstance ();
5456
@@ -69,7 +71,7 @@ public Element handle(Element request, Map<String, Object> context) throws Servi
6971 throw ServiceException .INVALID_REQUEST ("unknown value for by: " +key , null );
7072 }
7173 if (domain == null )
72- throw AccountServiceException .NO_SUCH_DOMAIN (value );
74+ throw AccountServiceException .NO_SUCH_DOMAIN (value );
7375 }
7476
7577 if (isDomainAdminOnly (zsc )) {
@@ -79,40 +81,68 @@ public Element handle(Element request, Map<String, Object> context) throws Servi
7981 domain = getAuthTokenAccountDomain (zsc );
8082 }
8183
82- AdminAccessControl aac = AdminAccessControl .getAdminAccessControl (zsc );
83-
8484 if (domain != null ) {
8585 response = zsc .createElement (AdminConstants .GET_ALL_DISTRIBUTION_LISTS_RESPONSE );
86- doDomain (zsc , response , domain , aac );
86+ doDomain (zsc , response , domain );
8787 } else {
8888 response = zsc .createElement (AdminConstants .GET_ALL_DISTRIBUTION_LISTS_RESPONSE );
8989 List domains = prov .getAllDomains ();
9090 for (Iterator dit =domains .iterator (); dit .hasNext (); ) {
9191 Domain dm = (Domain ) dit .next ();
92- doDomain (zsc , response , dm , aac );
92+ doDomain (zsc , response , dm );
9393 }
9494 }
95- return response ;
95+ return response ;
9696 }
97-
98- private void doDomain (ZimbraSoapContext zsc , Element e , Domain d , AdminAccessControl aac ) throws ServiceException {
97+
98+ private void doDomain (ZimbraSoapContext zsc , Element e , Domain d ) throws ServiceException {
9999 List dls = Provisioning .getInstance ().getAllGroups (d );
100+ Element eDL = null ;
101+ AdminAccessControl aac = null ;
102+ AttrRightChecker arc = null ;
100103 for (Iterator it = dls .iterator (); it .hasNext (); ) {
101104 Group dl = (Group ) it .next ();
102105 boolean hasRightToList = true ;
106+ boolean allowMembers = true ;
107+
103108 if (dl .isDynamic ()) {
104- // TODO: fix me
109+ aac = checkDynamicGroupRight (zsc , (DynamicGroup ) dl , AdminRight .PR_ALWAYS_ALLOW );
110+ arc = aac .getAttrRightChecker (dl );
105111 hasRightToList = true ;
112+ allowMembers = arc == null ? true : arc .allowAttr (Provisioning .A_member );
106113 } else {
114+ aac = checkDistributionListRight (zsc ,
115+ (DistributionList ) dl , AdminRight .PR_ALWAYS_ALLOW );
116+ arc = aac .getAttrRightChecker (dl );
117+ allowMembers = arc == null ? true : arc .allowAttr (Provisioning .A_zimbraMailForwardingAddress );
107118 hasRightToList = aac .hasRightsToList (dl , Admin .R_listDistributionList , null );
108119 }
109-
110120 if (hasRightToList ) {
111- GetDistributionList .encodeDistributionList (e , dl , false , false , null , aac .getAttrRightChecker (dl ));
121+ eDL = GetDistributionList .encodeDistributionList (e , dl , true , false , null , arc );
122+ }
123+ if (allowMembers ) {
124+ encodeMembers (e , eDL , dl );
112125 }
113- }
126+ }
114127 }
115-
128+
129+ private void encodeMembers (Element response , Element dlElement , Group group )
130+ throws ServiceException {
131+ String [] members ;
132+ if (group instanceof DynamicGroup ) {
133+ members = ((DynamicGroup )group ).getAllMembers (true );
134+ } else {
135+ members = group .getAllMembers ();
136+ }
137+
138+ Arrays .sort (members );
139+ for (int i = 0 ; i < members .length ; i ++) {
140+ dlElement .addElement (AdminConstants .E_DLM ).setText (members [i ]);
141+ }
142+
143+ response .addAttribute (AdminConstants .A_TOTAL , members .length );
144+ }
145+
116146 @ Override
117147 public void docRights (List <AdminRight > relatedRights , List <String > notes ) {
118148 relatedRights .add (Admin .R_listDistributionList );
0 commit comments