-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6798 from ORCID/8625-awstechtogglz-redirect-token…
…-endpoint-in-puborcidorg-to-the-root-endpoint 8625 awstechtogglz redirect token endpoint in puborcidorg to the root endpoint
- Loading branch information
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
orcid-pub-web/src/main/java/org/orcid/api/filters/PutAuthTokenActionFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.orcid.api.filters; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.FilterChain; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import javax.ws.rs.core.Context; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
import org.orcid.core.togglz.Features; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
|
||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.filter.OncePerRequestFilter; | ||
|
||
import liquibase.repackaged.org.apache.commons.lang3.StringUtils; | ||
|
||
@Provider | ||
@Component | ||
public class PutAuthTokenActionFilter extends OncePerRequestFilter { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(PutAuthTokenActionFilter.class); | ||
|
||
private static final String OAUTH_TOKEN_PATH = "/oauth/token"; | ||
|
||
@Context | ||
private HttpServletRequest httpServletRequest; | ||
|
||
@Value("${org.orcid.papi.http.redirect.code:307}") | ||
private int httpRedirectCode; | ||
|
||
@Value("${org.orcid.core.baseUri}") | ||
private String rootLocation; | ||
|
||
@Override | ||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { | ||
if (Features.REDIRECT_PUT_TOKEN_ENDPOINT.isActive() && request.getRequestURI().contains(OAUTH_TOKEN_PATH)) { | ||
response.setStatus(httpRedirectCode); | ||
response.setHeader("Location", rootLocation); | ||
LOGGER.debug("Redirecting PUT token request to root"); | ||
} | ||
else { | ||
filterChain.doFilter(request, response); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters