Skip to content

Commit 04e71ce

Browse files
committed
Catch SAML CredentialsExpiredException
1 parent b4ed1b8 commit 04e71ce

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/main/java/eu/openanalytics/containerproxy/auth/impl/saml/AuthenticationFailureHandler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020
*/
2121
package eu.openanalytics.containerproxy.auth.impl.saml;
2222

23+
import org.apache.logging.log4j.LogManager;
24+
import org.apache.logging.log4j.Logger;
2325
import org.opensaml.common.SAMLException;
26+
import org.springframework.security.authentication.CredentialsExpiredException;
2427
import org.springframework.security.core.Authentication;
2528
import org.springframework.security.core.AuthenticationException;
2629
import org.springframework.security.core.context.SecurityContext;
@@ -34,11 +37,14 @@
3437
import javax.servlet.http.HttpServletResponse;
3538
import javax.servlet.http.HttpSession;
3639
import java.io.IOException;
40+
import java.util.Objects;
3741

3842
import static eu.openanalytics.containerproxy.auth.impl.saml.AlreadyLoggedInFilter.REQ_PROP_AUTH_BEFORE_SSO;
3943

4044
public class AuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
4145

46+
private final Logger logger = LogManager.getLogger(getClass());
47+
4248
public void onAuthenticationFailure(HttpServletRequest request,
4349
HttpServletResponse response, AuthenticationException exception)
4450
throws IOException, ServletException {
@@ -59,6 +65,11 @@ public void onAuthenticationFailure(HttpServletRequest request,
5965
|| samlException.getMessage().startsWith("InResponseToField of the Response doesn't correspond to sent message"))
6066
|| samlException.getMessage().equals("Unsupported request")) {
6167
response.sendRedirect(ServletUriComponentsBuilder.fromCurrentContextPath().path("/").build().toUriString());
68+
return;
69+
} else if (samlException.getCause() instanceof CredentialsExpiredException) {
70+
logger.warn("The credentials of the user has expired, this typically indicates a misconfiguration, see https://shinyproxy.io/faq/#the-credentials-of-the-user-expire-when-using-saml for more information!");
71+
response.sendRedirect(ServletUriComponentsBuilder.fromCurrentContextPath().path("/auth-error").build().toUriString());
72+
return;
6273
}
6374
}
6475

src/main/resources/templates/auth-error.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939
<body>
4040
<div class="container">
4141
<h2>An error occurred during the authentication procedure.</h2>
42-
<p><b>If you are a user of <span th:text="${application_name}"></span>:</b> please report this issue to your administrator.</p>
43-
<p><b>If you are an administrator of <span th:text="${application_name}"></span>:</b> this error page is typically shown because of an configuration error in the OpenID setup. See the ShinyProxy logs for more information.</p>
42+
<p><b>If you are a user of <span th:text="${application_name}"></span>:</b> please report this issue to your administrator and try to log out from your Identity Provider.</p>
43+
<p><b>If you are an administrator of <span th:text="${application_name}"></span>:</b> this error page is typically shown because of an configuration error in the authentication setup. See the ShinyProxy logs for more information.</p>
4444
</div>
4545

4646
<style>

0 commit comments

Comments
 (0)