@@ -68,7 +68,7 @@ public DbxTeamClientV2(DbxRequestConfig requestConfig, String accessToken, DbxHo
6868 * multi-Dropbox account use-case.
6969 */
7070 public DbxTeamClientV2 (DbxRequestConfig requestConfig , String accessToken , DbxHost host , String userId ) {
71- super (new DbxTeamRawClientV2 (requestConfig , host , accessToken , userId , null , null ));
71+ super (new DbxTeamRawClientV2 (requestConfig , host , accessToken , userId , null , null , null ));
7272 this .accessToken = accessToken ;
7373 }
7474
@@ -97,11 +97,43 @@ public DbxClientV2 asMember(String memberId) {
9797 accessToken ,
9898 _client .getUserId (),
9999 memberId ,
100+ null ,
100101 null
101102 );
102103 return new DbxClientV2 (asMemberClient );
103104 }
104105
106+ /**
107+ * Returns a {@link DbxClientV2} that performs requests against Dropbox API
108+ * user endpoints as the given team admin.
109+ *
110+ * <p> This method performs no validation of the team admin ID. </p>
111+ *
112+ * @param adminId Team member ID of the admin in client's team, never
113+ * {@code null}.
114+ *
115+ * @return Dropbox client that issues requests to user endpoints as the
116+ * given team Admin.
117+ *
118+ * @throws IllegalArgumentException If {@code adminId} is {@code null}
119+ */
120+ public DbxClientV2 asAdmin (String adminId ) {
121+ if (adminId == null ) {
122+ throw new IllegalArgumentException ("'adminId' should not be null" );
123+ }
124+
125+ DbxRawClientV2 asAdminClient = new DbxTeamRawClientV2 (
126+ _client .getRequestConfig (),
127+ _client .getHost (),
128+ accessToken ,
129+ _client .getUserId (),
130+ null ,
131+ adminId ,
132+ null
133+ );
134+ return new DbxClientV2 (asAdminClient );
135+ }
136+
105137 /**
106138 * {@link DbxRawClientV2} raw client that adds team OAuth2 auth headers to all requests. If a
107139 * member ID is specified, this client will also add select-user headers to all requests (used
@@ -110,18 +142,22 @@ public DbxClientV2 asMember(String memberId) {
110142 private static final class DbxTeamRawClientV2 extends DbxRawClientV2 {
111143 private final String accessToken ;
112144 private final String memberId ;
145+ private final String adminId ;
113146
114147 private DbxTeamRawClientV2 (DbxRequestConfig requestConfig , DbxHost host , String accessToken ) {
115- this (requestConfig , host , accessToken , null , null , null );
148+ this (requestConfig , host , accessToken , null , null , null , null );
116149 }
117150
118- private DbxTeamRawClientV2 (DbxRequestConfig requestConfig , DbxHost host , String accessToken , String userId , String memberId , PathRoot pathRoot ) {
151+ private DbxTeamRawClientV2 (
152+ DbxRequestConfig requestConfig , DbxHost host , String accessToken , String userId , String memberId ,
153+ String adminId , PathRoot pathRoot ) {
119154 super (requestConfig , host , userId , pathRoot );
120155
121156 if (accessToken == null ) throw new NullPointerException ("accessToken" );
122157
123158 this .accessToken = accessToken ;
124159 this .memberId = memberId ;
160+ this .adminId = adminId ;
125161 }
126162
127163 @ Override
@@ -130,6 +166,9 @@ protected void addAuthHeaders(List<HttpRequestor.Header> headers) {
130166 if (memberId != null ) {
131167 DbxRequestUtil .addSelectUserHeader (headers , memberId );
132168 }
169+ if (adminId != null ) {
170+ DbxRequestUtil .addSelectAdminHeader (headers , adminId );
171+ }
133172 }
134173
135174 @ Override
@@ -140,6 +179,7 @@ protected DbxRawClientV2 withPathRoot(PathRoot pathRoot) {
140179 this .accessToken ,
141180 this .getUserId (),
142181 this .memberId ,
182+ this .adminId ,
143183 pathRoot
144184 );
145185 }
0 commit comments