Skip to content

Commit f4787f6

Browse files
fix : Not implemented fixes on DefaultWebAuthenticationFailureHandlerImpl, but already implemented on CustomizedWebAuthenticationFailureHandlerImpl
1 parent 882958a commit f4787f6

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,10 @@ public class CommonDataSourceConfiguration {
250250
- PKCE (``code_challege, code_challege_METHOD``) is optional.
251251
- PKCE adds a Code Verifier and a Code Challenge to the flow, enhancing the Authorization Code Grant Flow by preventing the issuance of an Access Token if the Authorization Code is compromised.
252252
2. Login with ``[email protected] / 1234 ``
253-
3. You will be redirected to
253+
3. You will be redirected to
254254
``https://localhost:8081/callback1?code=215e9539-1dcb-4843-b1ea-b2d7be0a3c44&state=xxx``
255-
4. You can login with the API in the Postman
255+
- However, if ``patternhelloworld.securityhelper.authorization-code.consent=Y``is set in the``application.properties``, it will be redirected to the consent page.
256+
4. You can login with the API in the Postman
256257
- ![img4.png](reference/docs/img.png)
257258
- ``code_verifier`` sample : EAp91aanXdoMcoOc2Il55H3UDDIV909k9olEEcl6L24J6_9X
258259

lib/src/main/java/io/github/patternhelloworld/securityhelper/oauth2/api/config/security/response/auth/authentication/DefaultWebAuthenticationFailureHandlerImpl.java

+22-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
import java.io.IOException;
1717
import java.util.ArrayList;
18+
import java.util.HashMap;
1819
import java.util.List;
20+
import java.util.Map;
1921

2022

2123
@RequiredArgsConstructor
@@ -28,7 +30,7 @@ public class DefaultWebAuthenticationFailureHandlerImpl implements Authenticatio
2830
// SecurityEasyPlusExceptionHandler does NOT handle this error.
2931
@Override
3032
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
31-
33+
// SecurityEasyPlusExceptionHandler does NOT handle this error.
3234
logger.error("Authentication failed: ", exception);
3335

3436
String errorMessage = "An unexpected error occurred.";
@@ -45,6 +47,24 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
4547
return;
4648
}
4749
if(oauth2Exception.getError().getErrorCode().equals(ErrorCodeConstants.REDIRECT_TO_CONSENT)){
50+
// Construct full URL
51+
String fullURL = request.getRequestURL().toString();
52+
if (request.getQueryString() != null) {
53+
fullURL += "?" + request.getQueryString();
54+
}
55+
Map<String, String> consentAttributes = new HashMap<>();
56+
consentAttributes.put("clientId", request.getParameter("client_id"));
57+
consentAttributes.put("redirectUri", request.getParameter("redirect_uri"));
58+
consentAttributes.put("code", request.getParameter("code"));
59+
consentAttributes.put("state", request.getParameter("state"));
60+
consentAttributes.put("scope", request.getParameter("scope"));
61+
if(request.getParameter("code_challenge") == null || request.getParameter("code_challenge_method") == null) {
62+
consentAttributes.put("codeChallenge", request.getParameter("code_challenge"));
63+
consentAttributes.put("codeChallengeMethod", request.getParameter("code_challenge_method"));
64+
}
65+
consentAttributes.put("consentRequestURI", fullURL);
66+
67+
request.setAttribute("consentAttributes", consentAttributes);
4868
request.getRequestDispatcher("/consent").forward(request, response);
4969
return;
5070
}
@@ -53,5 +73,6 @@ public void onAuthenticationFailure(HttpServletRequest request, HttpServletRespo
5373
request.setAttribute("errorDetails", errorDetails);
5474

5575
request.getRequestDispatcher("/error").forward(request, response);
76+
5677
}
5778
}

0 commit comments

Comments
 (0)