use of org.broadleafcommerce.common.admin.domain.TypedEntity in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafAdminTypedEntityRequestFilter method isRequestForTypedEntity.
@SuppressWarnings("unchecked")
public boolean isRequestForTypedEntity(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
String servletPath = request.getServletPath();
if (!servletPath.contains(":")) {
return false;
}
// Find the Admin Section for the typed entity.
String sectionKey = getSectionKeyFromRequest(request);
AdminSection typedEntitySection = adminNavigationService.findAdminSectionByURI(sectionKey);
// If the Typed Entity Section does not exist, continue with the filter chain.
if (typedEntitySection == null) {
return false;
}
// Check if the item requested matches the item section
TypedEntity typedEntity = getTypedEntityFromServletPathId(servletPath, typedEntitySection.getCeilingEntity());
if (typedEntity != null && !typeMatchesAdminSection(typedEntity, sectionKey)) {
String redirectUrl = getTypeAdminSectionMismatchUrl(typedEntity, typedEntitySection.getCeilingEntity(), request.getRequestURI(), sectionKey);
response.sendRedirect(redirectUrl);
return true;
}
// Check if admin user has access to this section.
if (!adminUserHasAccess(typedEntitySection)) {
response.sendError(HttpServletResponse.SC_FORBIDDEN, "Access is denied");
return true;
}
// Add the typed entity admin section to the request.
request.setAttribute("typedEntitySection", typedEntitySection);
// Find the type and build the new path.
String type = getEntityTypeFromRequest(request);
final String forwardPath = servletPath.replace(type, "");
// Get the type field name on the Entity for the given section.
String typedFieldName = getTypeFieldName(typedEntitySection);
// Build out the new parameter map to be forwarded.
final Map parameters = new LinkedHashMap(request.getParameterMap());
if (typedFieldName != null) {
parameters.put(typedFieldName, new String[] { type.substring(1).toUpperCase() });
}
// Build our request wrapper.
final HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request) {
@Override
public String getParameter(String name) {
String[] response = (String[]) parameters.get(name);
if (ArrayUtils.isEmpty(response)) {
return null;
} else {
return response[0];
}
}
@Override
public Map getParameterMap() {
return parameters;
}
@Override
public Enumeration getParameterNames() {
return new IteratorEnumeration(parameters.keySet().iterator());
}
@Override
public String[] getParameterValues(String name) {
return (String[]) parameters.get(name);
}
@Override
public String getServletPath() {
return forwardPath;
}
};
requestProcessor.process(new ServletWebRequest(wrapper, response));
// Forward the wrapper to the appropriate path
wrapper.getRequestDispatcher(wrapper.getServletPath()).forward(wrapper, response);
return true;
}
use of org.broadleafcommerce.common.admin.domain.TypedEntity in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafAdminTypedEntityRequestFilter method getTypeFieldName.
protected String getTypeFieldName(AdminSection adminSection) {
try {
DynamicEntityDao dynamicEntityDao = getDynamicEntityDao(adminSection.getCeilingEntity());
Class<?> implClass = dynamicEntityDao.getCeilingImplClass(adminSection.getCeilingEntity());
return ((TypedEntity) implClass.newInstance()).getTypeFieldName();
} catch (Exception e) {
return null;
}
}
Aggregations