Skip to content

Commit b0c2389

Browse files
authored
fix: Allow using As-User header with CCG Authentication (#1031)
1 parent 85bbf83 commit b0c2389

File tree

3 files changed

+0
-68
lines changed

3 files changed

+0
-68
lines changed

doc/authentication.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,18 +236,6 @@ Once you are done making calls on behalf of a managed user or app user you can s
236236
```java
237237
api.asSelf();
238238
```
239-
### Client Credentials Grant
240-
One important thing is that you can use user impersonation ony with service account API:
241-
```java
242-
BoxCCGAPIConnection api = BoxCCGAPIConnection.applicationServiceAccountConnection(
243-
"client_id",
244-
"client_secret",
245-
"enterprise_id"
246-
);
247-
api.asUser("user_id")
248-
```
249-
250-
Calling `asUser` or `asSelf` on user connection will fail with `IllegalStateException`.
251239

252240
## Token Exchange
253241

src/main/java/com/box/sdk/BoxCCGAPIConnection.java

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -112,36 +112,6 @@ public boolean canRefresh() {
112112
return true;
113113
}
114114

115-
/**
116-
* Set this API connection to make API calls on behalf of another users, impersonating them. This
117-
* functionality can only be used when using service connection, otherwise it will throw
118-
* IllegalStateException
119-
*
120-
* @param userID the ID of the user to act as.
121-
* @throws IllegalStateException when called on User connection
122-
*/
123-
@Override
124-
public void asUser(String userID) {
125-
if (isUserConnection()) {
126-
throw new IllegalStateException("Cannot add As-User header to connection created for a user.");
127-
}
128-
super.asUser(userID);
129-
}
130-
131-
/**
132-
* Removes impersonation and returns connection to a service one. This undoes any previous calls to asUser().
133-
*
134-
* @throws IllegalStateException when called on User connection
135-
* @see #asUser
136-
*/
137-
@Override
138-
public void asSelf() {
139-
if (isUserConnection()) {
140-
throw new IllegalStateException("Cannot remove As-User header from connection created for a user.");
141-
}
142-
super.asSelf();
143-
}
144-
145115
public boolean isUserConnection() {
146116
return subjectType.equals(USER_SUBJECT_TYPE);
147117
}

src/test/java/com/box/sdk/BoxCCGAPIConnectionTest.java

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import static org.hamcrest.Matchers.containsInAnyOrder;
1818
import static org.hamcrest.Matchers.hasSize;
1919
import static org.hamcrest.Matchers.is;
20-
import static org.junit.Assert.assertThrows;
2120

2221
import com.github.tomakehurst.wiremock.junit.WireMockRule;
2322
import java.io.BufferedReader;
@@ -246,31 +245,6 @@ public void applicationConnectionAllowsToRemoveAsUserHeader() {
246245
api.refresh();
247246
}
248247

249-
250-
@Test
251-
public void userConnectionDoesNotAllowToSetAsUserHeader() {
252-
// given
253-
BoxAPIConnection api = createDefaultUserConnection();
254-
255-
// expect
256-
assertThrows("Cannot set As-User header connection created for user.",
257-
IllegalStateException.class,
258-
() -> api.asUser("some_user_id")
259-
);
260-
}
261-
262-
@Test
263-
public void userConnectionDoesNotAllowToRemoveAsUserHeader() {
264-
// given
265-
BoxAPIConnection api = createDefaultUserConnection();
266-
267-
// expect
268-
assertThrows("Cannot remove As-User header connection created for user.",
269-
IllegalStateException.class,
270-
api::asSelf
271-
);
272-
}
273-
274248
@Test
275249
public void allowsToRevokeToken() {
276250
// given

0 commit comments

Comments
 (0)