com.formkiq.server.config.OAuthRequestedMatcher Maven / Gradle / Ivy
package com.formkiq.server.config;
import static com.formkiq.server.api.SystemController.API_SYSTEM_PING;
import static com.formkiq.server.api.SystemController.API_SYSTEM_SETUP;
import static com.formkiq.server.api.UsersController.API_USER_CREATE;
import static com.formkiq.server.api.UsersController.API_USER_LOST_PASSWORD;
import static com.formkiq.server.api.UsersController.API_USER_RESET_PASSWORD;
import javax.servlet.http.HttpServletRequest;
import org.springframework.security.web.util.matcher.RequestMatcher;
import org.springframework.util.StringUtils;
/**
* Matches custom OAuth Requests matcher to support both
* OAuth authentication and basic authentication on the /api path.
*
*/
public class OAuthRequestedMatcher implements RequestMatcher {
@Override
public boolean matches(final HttpServletRequest request) {
String uri = request.getRequestURI();
boolean matchAPIURL = uri.startsWith("/api/")
&& StringUtils.isEmpty(request.getHeader("cookie"));
if (API_SYSTEM_SETUP.equals(uri)
|| API_USER_LOST_PASSWORD.equals(uri)
|| API_USER_RESET_PASSWORD.equals(uri)
|| API_USER_CREATE.equals(uri)
|| API_SYSTEM_PING.equals(uri)) {
matchAPIURL = false;
}
return matchAPIURL;
}
}