Skip to content

Commit 0f7eb68

Browse files
committed
changing the project configuration
1 parent f1385c4 commit 0f7eb68

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,24 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
2828
try {
2929
authorize
3030
.antMatchers("/", "/error**", "/assets/**", "/ds/mustAuthenticate**",
31-
"/ds/authenticate**", "/ds/selectApi**")
31+
"/ds/authenticate**", "/ds/selectApi**", "/pkce")
3232
.permitAll()
3333
.anyRequest().authenticated()
3434
.and()
3535
.exceptionHandling()
3636
.authenticationEntryPoint(
37-
new LoginUrlAuthenticationEntryPoint("/ds/mustAuthenticate")
38-
);
37+
new LoginUrlAuthenticationEntryPoint("/ds/mustAuthenticate"));
3938
} catch (Exception e) {
4039
throw new RuntimeException(e);
4140
}
4241
})
4342
.requestCache().requestCache(requestCache()).and()
44-
.oauth2Login(Customizer.withDefaults())
43+
.oauth2Login(login -> login.failureHandler(new CustomAuthenticationFailureHandler()))
4544
.oauth2Client(Customizer.withDefaults())
4645
.logout(logout -> logout
47-
.logoutSuccessUrl("/")
48-
)
46+
.logoutSuccessUrl("/"))
4947
.csrf().disable();
5048

51-
return http.build();
49+
return http.build();
5250
}
5351
}

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,38 @@ public ModelAndView mustAuthenticateController(ModelMap model) throws IOExceptio
7272
@GetMapping(path = "/ds-return")
7373
public String returnController(@RequestParam(value = ATTR_STATE, required = false) String state,
7474
@RequestParam(value = ATTR_EVENT, required = false) String event,
75-
@RequestParam(required = false) String envelopeId, ModelMap model, HttpServletResponse response) throws IOException {
75+
@RequestParam(required = false) String envelopeId, ModelMap model, HttpServletResponse response)
76+
throws IOException {
7677
String site = "/eg001";
7778
response.setStatus(response.SC_MOVED_TEMPORARILY);
7879
response.setHeader("Location", site);
7980
return null;
8081
}
8182

83+
@GetMapping("/pkce")
84+
public RedirectView pkce(String code, String state, HttpServletRequest req, HttpServletResponse resp)
85+
throws Exception {
86+
String redirectURL = getRedirectURLForJWTAuthentication(req, resp);
87+
RedirectView redirect;
88+
try {
89+
redirect = new ACGAuthenticationMethod().exchangeCodeForToken(code, config, session, redirectURL,
90+
"signature");
91+
} catch (Exception e) {
92+
redirect = getRedirectView(getLoginPath());
93+
this.session.setIsPKCEWorking(false);
94+
}
95+
96+
return redirect;
97+
}
98+
8299
private RedirectView getRedirectView() {
83-
RedirectView redirect = new RedirectView(getLoginPath());
100+
this.session.setAuthTypeSelected(AuthType.AGC);
101+
if (this.session.getIsPKCEWorking()) {
102+
RedirectView redirect = new ACGAuthenticationMethod().initiateAuthorization(config, "signature");
103+
} else {
104+
RedirectView redirect = getRedirectView(getLoginPath());
105+
}
106+
84107
redirect.setExposeModelAttributes(false);
85108
return redirect;
86109
}
@@ -111,8 +134,7 @@ public Object populateLocals() throws IOException {
111134
OAuth2User oauthUser = oauth.getPrincipal();
112135
OAuth2AuthorizedClient oauthClient = authorizedClientService.loadAuthorizedClient(
113136
oauth.getAuthorizedClientRegistrationId(),
114-
oauthUser.getName()
115-
);
137+
oauthUser.getName());
116138

117139
if (oauth.isAuthenticated()) {
118140
user.setName(oauthUser.getAttribute("name"));
@@ -139,7 +161,7 @@ private String getBaseUrl(OAuth.Account oauthAccount) {
139161

140162
private static List<OAuth.Account> getOAuthAccounts(OAuth2User user) {
141163
List<Map<String, Object>> oauthAccounts = user.getAttribute("accounts");
142-
if(oauthAccounts == null){
164+
if (oauthAccounts == null) {
143165
return new ArrayList<>();
144166
}
145167

@@ -152,7 +174,7 @@ private OAuth.Account getDefaultAccountInfo(List<OAuth.Account> accounts) {
152174
String targetAccountId = config.getTargetAccountId();
153175
if (StringUtils.isNotBlank(targetAccountId)) {
154176
OAuth.Account account = getAccountById(accounts, targetAccountId);
155-
if(account != null) {
177+
if (account != null) {
156178
return account;
157179
}
158180
}

0 commit comments

Comments
 (0)