Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8625 awstechtogglz redirect token endpoint in puborcidorg to the root endpoint #6798

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions orcid-core/src/main/java/org/orcid/core/togglz/Features.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.togglz.core.context.FeatureContext;

public enum Features implements Feature {
@Label("Redirect PUT token actions from *.pub.orcid.org to *.orcid.org")
REDIRECT_PUT_TOKEN_ENDPOINT,

@Label("Stop sending notification if work has not been updated")
STOP_SENDING_NOTIFICATION_WORK_NOT_UPDATED,
Expand Down
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);
}
}
}
2 changes: 2 additions & 0 deletions orcid-pub-web/src/main/resources/orcid-t1-web-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

<bean id="sanitizeAuthenticationFilter" class="org.orcid.core.web.filters.SanitizeAuthenticationFilter" />

<bean id="putAuthTokenActionFilter" class="org.orcid.api.filters.PutAuthTokenActionFilter" />

<bean id="corsFilter" class="org.orcid.core.web.filters.CorsFilter" />

<bean id="jsonpCallbackFilter" class="org.orcid.core.web.filters.JsonpCallbackFilter" />
Expand Down
10 changes: 10 additions & 0 deletions orcid-pub-web/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@
<filter-name>sanitizeAuthenticationFilter</filter-name>
<url-pattern>*</url-pattern>
</filter-mapping>

<filter>
<filter-name>putAuthTokenActionFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
<filter-name>putAuthTokenActionFilter</filter-name>
<url-pattern>/oauth/token</url-pattern>
</filter-mapping>

<filter>
<filter-name>jsonpCallbackFilter</filter-name>
Expand Down