Skip to content

Commit 7c47842

Browse files
authored
Merge pull request #7259 from ORCID/lmendoza/404-redirects
404-redirects
2 parents c3ac1e6 + f2bc406 commit 7c47842

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

orcid-web/src/main/java/org/orcid/frontend/spring/OrcidAccessDeniedHandler.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@
22

33
import java.io.IOException;
44

5+
import javax.annotation.Resource;
56
import javax.servlet.ServletException;
67
import javax.servlet.http.HttpServletRequest;
78
import javax.servlet.http.HttpServletResponse;
89

10+
import org.orcid.core.manager.impl.OrcidUrlManager;
911
import org.slf4j.Logger;
1012
import org.slf4j.LoggerFactory;
1113
import org.springframework.security.access.AccessDeniedException;
14+
import org.springframework.security.core.Authentication;
1215
import org.springframework.security.web.access.AccessDeniedHandlerImpl;
1316
import org.springframework.security.web.csrf.CsrfException;
1417
import org.springframework.web.context.request.RequestContextHolder;
18+
import org.springframework.security.core.context.SecurityContextHolder;
1519

1620
public class OrcidAccessDeniedHandler extends AccessDeniedHandlerImpl {
1721

22+
@Resource
23+
private OrcidUrlManager orcidUrlManager;
24+
1825
private static final Logger LOGGER = LoggerFactory.getLogger(OrcidAccessDeniedHandler.class);
1926

2027
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
@@ -36,6 +43,13 @@ public void handle(HttpServletRequest request, HttpServletResponse response, Acc
3643
}
3744
}
3845

46+
// Check if the current user is authenticated
47+
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
48+
if (auth != null && auth.isAuthenticated()) {
49+
response.sendRedirect(orcidUrlManager.getBaseUrl() + "/404");
50+
return;
51+
}
52+
3953
super.handle(request, response, accessDeniedException);
4054
}
4155
}

orcid-web/src/main/resources/orcid-frontend-security.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,9 +419,9 @@
419419
<sec:intercept-url pattern="/2FA/authenticationCode.json(\?.*)?"
420420
access="ROLE_USER" />
421421
<sec:intercept-url pattern="/2FA/submitCode.json(\?.*)?"
422-
access="ROLE_USER" />
422+
access="ROLE_USER" />
423+
<sec:intercept-url pattern="/.*" method="POST" access="ROLE_USER"/>
423424

424-
<sec:intercept-url pattern="/.*" access="ROLE_USER"/>
425425

426426
<sec:form-login login-processing-url="/signin/auth.json" authentication-details-source-ref="authenticationDetailsSource"
427427
login-page="${org.orcid.core.baseUri}/signin" authentication-success-handler-ref="ajaxAuthenticationSuccessHandler"

0 commit comments

Comments
 (0)