Skip to content

Commit b9963d0

Browse files
committed
Various updates
1 parent 7c46474 commit b9963d0

File tree

17 files changed

+157
-107
lines changed

17 files changed

+157
-107
lines changed

Quick_ACG/pom.xml

+11-1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
<includes>
159159
<include>Locals.java</include>
160160
<include>User.java</include>
161+
<include>EnvelopeDocumentInfo.java</include>
161162
</includes>
162163
</resource>
163164
<resource>
@@ -199,7 +200,16 @@
199200
<targetPath>${basedir}/src/main/java/com/docusign/core/security</targetPath>
200201
<directory>../src/main/java/com/docusign/core/security</directory>
201202
<includes>
202-
<include>OAuthProperties.java</include>
203+
<include>SecurityHelpers.java</include>
204+
<include>JWTOAuth2User.java</include>
205+
<include>CustomAuthenticationFailureHandler.java</include>
206+
</includes>
207+
</resource>
208+
<resource>
209+
<targetPath>${basedir}/src/main/java/com/docusign/core/security/acg</targetPath>
210+
<directory>../src/main/java/com/docusign/core/security/acg</directory>
211+
<includes>
212+
<include>ACGAuthenticationMethod.java</include>
203213
</includes>
204214
</resource>
205215
<resource>

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

+15-3
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,20 @@ public class DSConfiguration {
7878
@Value("${DS_ADMIN_BASE_PATH}")
7979
private String adminBasePath;
8080

81+
@Value("${spring.security.oauth2.client.registration.acg.client-secret}")
82+
private String secretUserId;
83+
84+
@Value("${spring.security.oauth2.client.provider.acg.token-uri}")
85+
private String tokenEndpoint;
86+
87+
@Value("${spring.security.oauth2.client.provider.acg.authorization-uri}")
88+
private String authorizationEndpoint;
89+
90+
@Value("${spring.security.oauth2.client.registration.jwt.client-id}")
91+
private String userId;
92+
8193
public String examplesApiPath = "examplesApi.json";
82-
94+
8395
public String apiTypeHeader = "ApiType";
8496

8597
@Value("${CodeExamplesManifest}")
@@ -94,14 +106,14 @@ public String getDsPingUrl() {
94106
}
95107

96108
public ManifestStructure getCodeExamplesText() {
97-
if (codeExamplesText != null){
109+
if (codeExamplesText != null) {
98110
return codeExamplesText;
99111
}
100112

101113
try {
102114
String json = loadFileData(codeExamplesManifest);
103115
codeExamplesText = new ObjectMapper().readValue(json, ManifestStructure.class);
104-
} catch (JSONException | IOException e){
116+
} catch (JSONException | IOException e) {
105117
e.printStackTrace();
106118
} catch (Exception e) {
107119
e.printStackTrace();

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

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
1010
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
1111
import org.springframework.security.web.savedrequest.RequestCache;
12+
import com.docusign.core.security.CustomAuthenticationFailureHandler;
1213

1314
@EnableWebSecurity
1415
public class WebSecurityConfig {
@@ -28,26 +29,24 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
2829
try {
2930
authorize
3031
.antMatchers("/", "/error**", "/assets/**", "/ds/mustAuthenticate**",
31-
"/ds/authenticate**", "/ds/selectApi**")
32+
"/ds/authenticate**", "/ds/selectApi**", "/pkce")
3233
.permitAll()
3334
.anyRequest().authenticated()
3435
.and()
3536
.exceptionHandling()
3637
.authenticationEntryPoint(
37-
new LoginUrlAuthenticationEntryPoint("/ds/mustAuthenticate")
38-
);
38+
new LoginUrlAuthenticationEntryPoint("/ds/mustAuthenticate"));
3939
} catch (Exception e) {
4040
throw new RuntimeException(e);
4141
}
4242
})
4343
.requestCache().requestCache(requestCache()).and()
44-
.oauth2Login(Customizer.withDefaults())
44+
.oauth2Login(login -> login.failureHandler(new CustomAuthenticationFailureHandler()))
4545
.oauth2Client(Customizer.withDefaults())
4646
.logout(logout -> logout
47-
.logoutSuccessUrl("/")
48-
)
47+
.logoutSuccessUrl("/"))
4948
.csrf().disable();
5049

51-
return http.build();
50+
return http.build();
5251
}
5352
}

Quick_ACG/src/main/java/com/docusign/core/controller/IndexController.java

+40-15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import com.docusign.core.model.User;
77
import java.io.IOException;
88
import java.util.*;
9+
import javax.servlet.http.HttpServletRequest;
10+
import javax.servlet.http.HttpServletResponse;
11+
import com.docusign.core.security.acg.ACGAuthenticationMethod;
912

1013
import com.docusign.core.utils.AccountsConverter;
1114
import org.apache.commons.lang3.StringUtils;
@@ -26,21 +29,16 @@
2629
import com.docusign.esign.client.auth.OAuth;
2730
import java.util.stream.Collectors;
2831
import org.springframework.security.core.Authentication;
29-
import org.springframework.web.bind.annotation.ControllerAdvice;
30-
import org.springframework.web.bind.annotation.ModelAttribute;
31-
import javax.servlet.http.HttpServletResponse;
3232

3333
@Controller
3434
@ControllerAdvice
3535
@Scope(WebApplicationContext.SCOPE_SESSION)
3636
public class IndexController {
37-
private static final String ATTR_ENVELOPE_ID = "qpEnvelopeId";
37+
private static final List<String> ESIGNATURE_SCOPES = Arrays.asList("signature");
3838
private static final String ATTR_STATE = "state";
3939
private static final String ATTR_EVENT = "event";
40-
private static final String ATTR_TITLE = "title";
4140

4241
private static final String ERROR_ACCOUNT_NOT_FOUND = "Could not find account information for the user";
43-
private static final String SELECTED_API_NOT_SUPPORTED = "Currently selected api is not supported by launcher. Please, check appsettings.json file.";
4442
private final DSConfiguration config;
4543
private final Session session;
4644
private final User user;
@@ -65,22 +63,45 @@ public String index(ModelMap model, HttpServletResponse response) throws IOExcep
6563
}
6664

6765
@GetMapping(path = "/ds/mustAuthenticate")
68-
public ModelAndView mustAuthenticateController(ModelMap model) throws IOException {
66+
public ModelAndView mustAuthenticateController(ModelMap model) throws IOException, Exception {
6967
return new ModelAndView(getRedirectView());
7068
}
7169

7270
@GetMapping(path = "/ds-return")
7371
public String returnController(@RequestParam(value = ATTR_STATE, required = false) String state,
7472
@RequestParam(value = ATTR_EVENT, required = false) String event,
75-
@RequestParam(required = false) String envelopeId, ModelMap model, HttpServletResponse response) throws IOException {
73+
@RequestParam(required = false) String envelopeId, ModelMap model, HttpServletResponse response)
74+
throws IOException {
7675
String site = "/eg001";
7776
response.setStatus(response.SC_MOVED_TEMPORARILY);
7877
response.setHeader("Location", site);
7978
return null;
8079
}
8180

82-
private RedirectView getRedirectView() {
83-
RedirectView redirect = new RedirectView(getLoginPath());
81+
@GetMapping("/pkce")
82+
public RedirectView pkce(String code, String state, HttpServletRequest req, HttpServletResponse resp)
83+
throws Exception {
84+
String redirectURL = "/";
85+
RedirectView redirect;
86+
try {
87+
redirect = new ACGAuthenticationMethod().exchangeCodeForToken(code, config, session, redirectURL,
88+
ESIGNATURE_SCOPES);
89+
} catch (Exception e) {
90+
redirect = new RedirectView(getLoginPath());
91+
this.session.setIsPKCEWorking(false);
92+
}
93+
94+
return redirect;
95+
}
96+
97+
private RedirectView getRedirectView() throws Exception {
98+
RedirectView redirect;
99+
if (this.session.getIsPKCEWorking()) {
100+
redirect = new ACGAuthenticationMethod().initiateAuthorization(config, ESIGNATURE_SCOPES);
101+
} else {
102+
redirect = new RedirectView(getLoginPath());
103+
}
104+
84105
redirect.setExposeModelAttributes(false);
85106
return redirect;
86107
}
@@ -111,12 +132,16 @@ public Object populateLocals() throws IOException {
111132
OAuth2User oauthUser = oauth.getPrincipal();
112133
OAuth2AuthorizedClient oauthClient = authorizedClientService.loadAuthorizedClient(
113134
oauth.getAuthorizedClientRegistrationId(),
114-
oauthUser.getName()
115-
);
135+
oauthUser.getName());
116136

117137
if (oauth.isAuthenticated()) {
118138
user.setName(oauthUser.getAttribute("name"));
119-
user.setAccessToken(oauthClient.getAccessToken().getTokenValue());
139+
140+
if (oauthClient != null) {
141+
user.setAccessToken(oauthClient.getAccessToken().getTokenValue());
142+
} else {
143+
user.setAccessToken(((OAuth.OAuthToken) oauthUser.getAttribute("access_token")).getAccessToken());
144+
}
120145

121146
if (account.isEmpty()) {
122147
account = Optional.ofNullable(getDefaultAccountInfo(getOAuthAccounts(oauthUser)));
@@ -139,7 +164,7 @@ private String getBaseUrl(OAuth.Account oauthAccount) {
139164

140165
private static List<OAuth.Account> getOAuthAccounts(OAuth2User user) {
141166
List<Map<String, Object>> oauthAccounts = user.getAttribute("accounts");
142-
if(oauthAccounts == null){
167+
if (oauthAccounts == null) {
143168
return new ArrayList<>();
144169
}
145170

@@ -152,7 +177,7 @@ private OAuth.Account getDefaultAccountInfo(List<OAuth.Account> accounts) {
152177
String targetAccountId = config.getTargetAccountId();
153178
if (StringUtils.isNotBlank(targetAccountId)) {
154179
OAuth.Account account = getAccountById(accounts, targetAccountId);
155-
if(account != null) {
180+
if (account != null) {
156181
return account;
157182
}
158183
}
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
11
package com.docusign.core.model;
22

3+
import com.docusign.esign.client.auth.OAuth;
34
import lombok.Data;
45
import org.springframework.context.annotation.Scope;
56
import org.springframework.context.annotation.ScopedProxyMode;
67
import org.springframework.stereotype.Component;
78
import org.springframework.web.context.WebApplicationContext;
89

910
import java.io.Serializable;
11+
import java.util.List;
1012
import java.util.UUID;
1113

1214
@Component
13-
@Scope(value = WebApplicationContext.SCOPE_SESSION,
14-
proxyMode = ScopedProxyMode.TARGET_CLASS)
15+
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
1516
@Data
1617
public class Session implements Serializable {
1718
private static final long serialVersionUID = 2695379118371574037L;
1819

20+
public Long tokenExpirationTime;
21+
1922
private String accountId;
23+
2024
private String accountName;
25+
2126
private String basePath;
22-
private String statusCFR;
23-
private String roomsBasePath;
27+
2428
private String envelopeId;
25-
private String templateId;
26-
private String templateName;
27-
private String permissionProfileId;
28-
private String permissionProfileName;
29-
private String apiIndexPath;
30-
private boolean refreshToken = false;
31-
private String clickwrapId;
32-
private String clickwrapVersionNumber;
33-
private String exportId;
34-
private String importId;
35-
private UUID orgId;
36-
public UUID bulkListId;
29+
30+
private String statusCFR;
31+
32+
private Boolean isPKCEWorking = true;
3733
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ For a list of code examples that use the Web Forms API, see the [How-to guides o
112112
1. Extract the Quickstart ZIP file or download or clone the code-examples-java repository.
113113
1. In your command-line environment, switch to the :
114114
`cd <Quickstart >` or `cd code-examples-java`
115-
1. Package the code: `mvn package`
115+
1. Package the code: `mvn package -Dmaven.test.skip=true`
116116
1. To configure the launcher for [Authorization Code Grant](https://developers.docusign.com/platform/auth/authcode/) authentication, create a copy of the file src/main/resources/application.example.json and save the copy as src/main/resources/application.json.
117117
1. Add your User ID. On the [Apps and Keys](https://admindemo.docusign.com/authenticate?goTo=apiIntegratorKey) page, under **My Account Information**, copy the **User ID** GUID and save it in application.json as your `DS_TARGET_ACCOUNT_ID`.
118118
1. Add your integration key. On the [Apps and Keys](https://admindemo.docusign.com/authenticate?goTo=apiIntegratorKey) page, under **Apps and Integration Keys**, choose the app to use, then select **Actions > Edit**. Under **General Info**, copy the **Integration Key** GUID and save it in application.json as your `authorization.code.grant.client.client-id`.

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
<maestro.version>2.0.0</maestro.version>
3636
<swagger-core-version>2.2.22</swagger-core-version>
3737
<jackson-version>2.17.2</jackson-version>
38-
<jersey2.version>3.1.8</jersey2.version>
38+
<jersey2.version>3.0.9</jersey2.version>
3939
</properties>
4040

4141
<dependencies>

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public ManifestStructure getCodeExamplesText() {
168168

169169
try {
170170
codeExamplesText = new ObjectMapper().readValue(loadFileData(codeExamplesManifest),
171-
ManifestStructure.class);
171+
ManifestStructure.class);
172172
} catch (Exception e) {
173173
e.printStackTrace();
174174
}
@@ -182,8 +182,8 @@ public String loadFileData(String linkToManifestFile) throws Exception {
182182
httpConnection.setRequestMethod(HttpMethod.GET);
183183

184184
httpConnection.setRequestProperty(
185-
HttpHeaders.CONTENT_TYPE,
186-
String.valueOf(MediaType.APPLICATION_JSON));
185+
HttpHeaders.CONTENT_TYPE,
186+
String.valueOf(MediaType.APPLICATION_JSON));
187187

188188
int responseCode = httpConnection.getResponseCode();
189189

src/main/java/com/docusign/controller/monitor/services/GetMonitoringDataService.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@
66
import org.json.JSONObject;
77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
9+
import java.time.LocalDate;
10+
import java.time.format.DateTimeFormatter;
911

1012
public final class GetMonitoringDataService {
1113
private static final Logger LOGGER = LoggerFactory.getLogger(GetMonitoringDataService.class);
1214

1315
public static JSONArray getMonitoringData(DataSetApi datasetApi) throws Exception {
1416
// Declare variables
1517
boolean complete = false;
16-
String cursorValue = "";
18+
LocalDate cursorDate = LocalDate.now().minusYears(1);
19+
String cursorValue = cursorDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "T00:00:00Z";
1720
JSONArray monitoringData = new JSONArray();
1821

1922
LOGGER.info("before optinos");
2023
DataSetApi.GetStreamOptions options = datasetApi.new GetStreamOptions();
24+
options.setLimit(2000);
2125

2226
// First call the endpoint with no cursor to get the first records.
2327
// After each call, save the cursor and use it to make the next

0 commit comments

Comments
 (0)