commit
5f5a275be9
@ -0,0 +1,9 @@
|
||||
package au.com.royalpay.payment.manage.shopify.support;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||
public @interface ShopifyEndpoint {
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package au.com.royalpay.payment.manage.shopify.support;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ShopifyRequestInfoInterceptor extends HandlerInterceptorAdapter {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
Method method = ((HandlerMethod) handler).getMethod();
|
||||
|
||||
if(HttpMethod.GET.matches(request.getMethod())) {
|
||||
if (AnnotatedElementUtils.isAnnotated(method, ShopifyEndpoint.class)) {
|
||||
String shop = request.getParameter("shop");
|
||||
if (StringUtils.isNotBlank(shop)) {
|
||||
response.addHeader("Content-Security-Policy", "frame-ancestors 'none'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (HttpMethod.POST.matches(request.getMethod())) {
|
||||
if (AnnotatedElementUtils.isAnnotated(method, ShopifyEndpoint.class)) {
|
||||
String requestBody = ShopifyHttpUtils.getRequestBody(request);
|
||||
JSONObject body = JSONObject.parseObject(requestBody);
|
||||
String shop = body.getString("shop_domain");
|
||||
if (StringUtils.isNotBlank(shop)) {
|
||||
response.addHeader("Content-Security-Policy", "frame-ancestors 'none'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return super.preHandle(request, response, handler);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in new issue