Skip to content

Commit

Permalink
Updated the path param extracting mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
rnavagamuwa committed Apr 1, 2019
1 parent 2447f39 commit 3499b52
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,4 @@ static Map<String, String> extractValuesFromCookies(Cookie[] cookies) {
}
return cookieValues;
}

static String[] splitContextPath(String contextPath){
return contextPath.split("/");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import org.json.JSONObject;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.HandlerMapping;
import org.wso2.spring.security.abac.cache.Cache;
import org.wso2.spring.security.abac.cache.EhCacheManager;
import org.wso2.spring.security.abac.exception.AttributeEvaluatorException;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.util.Base64;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -117,7 +117,7 @@ private Map<String, Object> generateFreemakeTemplateData(String jsonKeyValuePair
value = httpServletRequest.getParameter(value);
break;
case PATH_PARAM:
value = GeneralUtils.splitContextPath(httpServletRequest.getContextPath())[Integer.parseInt(value)];
value = extractPathParam(httpServletRequest,value);
break;
}
templateData.put(key, value);
Expand All @@ -126,6 +126,11 @@ private Map<String, Object> generateFreemakeTemplateData(String jsonKeyValuePair
return templateData;
}

private String extractPathParam(HttpServletRequest httpServletRequest, String key) {
Map paramsMap = (Map) httpServletRequest.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);
return (String) paramsMap.get(key);
}

private String getTemplateDataAsAString(Map<String, Object> templateData) {

StringBuilder stringBuilder = new StringBuilder();
Expand Down

0 comments on commit 3499b52

Please sign in to comment.