Skip to content

Commit 465de49

Browse files
authored
Split room scopes (docusign#9)
* set rooms scope conditionally based on api name * Resolved PR comments
1 parent d4d11f2 commit 465de49

7 files changed

Lines changed: 45 additions & 18 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Java Launcher Code Examples
22

3-
This GitHub repo includes code example for both the DocuSign eSignature REST API as well as the DocuSign Rooms API. To use the Rooms API code example, modify the **exampleAPI** settings at the end of the appsettings.json file from eSignature to rooms.
3+
This GitHub repo includes code example for both the DocuSign eSignature REST API as well as the DocuSign Rooms API. To use the Rooms API code examples, change the **DS_API_NAME** value to `ROOMS` in the application.json config file.
44

55
**Note:** to use the Rooms API you must also [create your DocuSign Developer Account for Rooms](https://developers.docusign.com/docs/rooms-api/rooms101/create-account).
66

@@ -265,6 +265,7 @@ browser to http://localhost:8080
265265
* Name the configuration `code-examples-java` (If You have downloaded the launcher via Quickstart, skip this step).
266266
* Put in the following value for your workspace in the Base Directory: `${workspace_loc:/code-examples-java}`.
267267
* Put in the following value for the Goals field: `spring-boot::run`.
268+
* Click the JRE tab and add in the paste in the following VM argument: `-Dfork=false` (This will allow Eclipse to gracefully terminate the Tomcat Webserver when also terminating the output console in Eclipse).
268269
* Click the JRE tab in the Run Configurations menu and make sure your have a Runtime JRE set to jdk-11 or higher.
269270
* Click apply to save. Finally, click `Run` to run it!
270271
* Open a browser to http://localhost:8080
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.docusign;
22

3+
import java.io.IOException;
4+
35
import org.springframework.boot.SpringApplication;
46
import org.springframework.boot.autoconfigure.SpringBootApplication;
57
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
@@ -8,7 +10,13 @@
810
@SpringBootApplication(exclude={JmxAutoConfiguration.class})
911
public class App {
1012

11-
public static void main(String[] args) {
13+
public static void main(String[] args) throws IOException {
1214
SpringApplication.run(App.class, args);
15+
openHomePage();
16+
}
17+
18+
private static void openHomePage() throws IOException {
19+
Runtime rt = Runtime.getRuntime();
20+
rt.exec("rundll32 url.dll,FileProtocolHandler " + "http://localhost:8080");
1321
}
1422
}

src/main/java/com/docusign/DSConfiguration.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ public class DSConfiguration {
2424
@Value("${DS_API_NAME}")
2525
private String apiName;
2626

27-
@Value("${DS_API_BASE_URL}")
28-
private String apiBaseUrl;
27+
@Value("${DS_BASE_PATH}")
28+
private String basePath;
29+
30+
@Value("${DS_ROOMS_BASE_PATH}")
31+
private String roomsBasePath;
2932

3033
@Value("${DS_SIGNER_EMAIL:{USER_EMAIL}}")
3134
private String signerEmail;
@@ -54,11 +57,5 @@ public String getDsReturnUrl() {
5457
public String getDsPingUrl() {
5558
return appUrl + "/";
5659
}
57-
public String getApiName(){
58-
if(apiName.contains("{")){
59-
apiName = "ESIGNATURE";
60-
apiBaseUrl = "https://demo.docusign.net";
61-
}
62-
return apiName;
63-
}
60+
6461
}

src/main/java/com/docusign/WebSecurityConfig.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package com.docusign;
2-
32
import com.docusign.core.security.OAuthProperties;
43
import com.docusign.core.security.jwt.JWTAuthorizationCodeResourceDetails;
54
import com.docusign.core.security.jwt.JWTOAuth2RestTemplate;
@@ -35,7 +34,13 @@
3534
@Configuration
3635
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
3736

37+
public String roomScopes[] = new String[] {"signature", "dtr.rooms.read", "dtr.rooms.write", "dtr.documents.read", "dtr.documents.write", "dtr.profile.read", "dtr.profile.write", "dtr.company.read", "dtr.company.write", "room_forms"};
38+
3839
@Autowired
40+
private DSConfiguration dsConfiguration;
41+
42+
43+
@Autowired
3944
private OAuth2ClientContext oAuth2ClientContext;
4045

4146
@Bean
@@ -53,6 +58,7 @@ public OAuthProperties jwtGrantSso() {
5358
@Bean
5459
@ConfigurationProperties("authorization.code.grant.client")
5560
public AuthorizationCodeResourceDetails authCodeGrantClient() {
61+
5662
return new AuthorizationCodeResourceDetails();
5763
}
5864

@@ -79,6 +85,13 @@ public FilterRegistrationBean<OAuth2ClientContextFilter> oAuth2ClientFilterRegis
7985
private OAuth2ClientAuthenticationProcessingFilter authCodeGrantFilter() {
8086
OAuth2SsoProperties authCodeGrantSso = authCodeGrantSso();
8187
AuthorizationCodeResourceDetails authCodeGrantClient = authCodeGrantClient();
88+
89+
90+
if (this.dsConfiguration.getApiName().equalsIgnoreCase("rooms")) {
91+
authCodeGrantClient.setScope(Arrays.asList(roomScopes));
92+
}
93+
94+
8295
ResourceServerProperties userInfoResource = userInfoResource();
8396
OAuth2ClientAuthenticationProcessingFilter filter =
8497
new OAuth2ClientAuthenticationProcessingFilter(authCodeGrantSso.getLoginPath());
@@ -93,6 +106,12 @@ private OAuth2ClientAuthenticationProcessingFilter authCodeGrantFilter() {
93106
private OAuth2ClientAuthenticationProcessingFilter jwtGrantFilter() {
94107
OAuth2SsoProperties authCodeGrantSso = jwtGrantSso();
95108
JWTAuthorizationCodeResourceDetails jwtCodeGrantClient = jwtCodeGrantClient();
109+
110+
if (this.dsConfiguration.getApiName().equalsIgnoreCase("rooms")) {
111+
jwtCodeGrantClient.setScope(Arrays.asList(roomScopes));
112+
113+
}
114+
96115
OAuth2ClientAuthenticationProcessingFilter filter =
97116
new OAuth2ClientAuthenticationProcessingFilter(authCodeGrantSso.getLoginPath());
98117
OAuth2RestTemplate restTemplate = new JWTOAuth2RestTemplate(jwtCodeGrantClient, oAuth2ClientContext);

src/main/java/com/docusign/core/controller/GlobalControllerAdvice.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ public Locals populateLocals() {
112112
OAuth.Account oauthAccount = account.orElseThrow(() -> new NoSuchElementException(ERROR_ACCOUNT_NOT_FOUND));
113113
session.setAccountId(oauthAccount.getAccountId());
114114
session.setAccountName(oauthAccount.getAccountName());
115-
116-
String baseUrl = !config.getApiBaseUrl().isEmpty() ? config.getApiBaseUrl() : oauthAccount.getBaseUri();
115+
//TODO set this more efficiently with more APIs as they're added in
116+
String baseUrl = config.getApiName().equalsIgnoreCase("rooms") ? config.getRoomsBasePath() : oauthAccount.getBaseUri();
117117
session.setBasePath(baseUrl + BASE_URI_SUFFIX);
118118
}
119119

src/main/java/com/docusign/core/model/Session.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class Session implements Serializable {
2121
private String accountId;
2222
private String accountName;
2323
private String basePath;
24+
private String roomsBasePath;
2425
private String envelopeId;
2526
private String templateName;
2627
private List<EnvelopeDocumentInfo> envelopeDocuments;

src/main/resources/application.example.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"DS_SIGNER_NAME": "{SIGNER_NAME}",
44
"DS_SIGNER_EMAIL": "{SIGNER_EMAIL}",
55
"DS_APP_URL": "http://localhost:8080",
6-
"DS_TARGET_ACCOUNT_ID": "{IMPERSONATED_USER_GUID}",
6+
"DS_TARGET_ACCOUNT_ID": "{IMPERSONATED_USER_ID}",
77
"DS_API_NAME": "{API_NAME:(ESIGNATURE|ROOMS)}",
8-
"DS_API_BASE_URL": "{API_BASE_URL:(https://demo.docusign.net|https://demo.rooms.docusign.com)}",
9-
8+
"DS_API_BASE_PATH": "https://demo.docusign.net",
9+
"DS_ROOMS_BASE_PATH": "https://demo.rooms.docusign.com",
10+
1011
"Gateway_Name": "{DS_PAYMENT_GATEWAY_NAME}",
1112
"Gateway_Account_Id": "{GATEWAY_ACCOUNT_ID}",
1213
"Gateway_Display_Name": "{DS_PAYMENT_GATEWAY_DISPLAY_NAME}",
@@ -21,7 +22,7 @@
2122
"jwt.grant.sso.redirect-url": "&type=jwt",
2223
"jwt.grant.client.scope": "signature impersonation",
2324
"jwt.grant.client.base-url": "account-d.docusign.com",
24-
"jwt.grant.client.client-id": "{JWT_API_ACCOUNT_ID}",
25+
"jwt.grant.client.client-id": "{INTEGRATION_KEY_JWT}",
2526
"jwt.grant.client.private-key-path": "src/main/resources/private.key",
2627
"jwt.grant.client.impersonated-user-guid": "{IMPERSONATED_USER_ID}",
2728

0 commit comments

Comments
 (0)