Skip to content
This repository has been archived by the owner on May 9, 2020. It is now read-only.

Commit

Permalink
Cleaned up some code that was adding the delegator/dispatcher/securit…
Browse files Browse the repository at this point in the history
…y/auth objects in the user session rather than the request;

1) removed the request-maps for changeDelegator from components' controller.xml files: they were not used
2) removed CoreEvents.changeDelegator(...): not used (apart from the request-maps removed at #1)
3) removed CoreEvents.changeDispatcher(...): not used
4) cleaned up some code (related to multitenant development): now the objects are set in the request rather than the session

PS: as a consequence this will also fix the issue reported in OFBIZ-4289


git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1353681 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
jacopoc committed Jun 25, 2012
1 parent ab3e6c7 commit ead8af3
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 175 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ under the License.
<response name="success" type="request" value="main"/>
</request-map>

<request-map uri="changeDelegator">
<event type="java" path="org.ofbiz.webapp.event.CoreEvents" invoke="changeDelegator"/>
<response name="success" type="view" value="main"/>
<response name="error" type="view" value="error"/>
</request-map>

<request-map uri="main">
<security https="true" auth="true"/>
<response name="success" type="view" value="main"/>
Expand Down
7 changes: 0 additions & 7 deletions applications/content/webapp/content/WEB-INF/controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,6 @@ under the License.
<response name="success" type="view" value="fonts.fo"/>
</request-map>

<request-map uri="changeDelegator">
<security https="true" auth="true"/>
<event type="java" path="org.ofbiz.webapp.event.CoreEvents" invoke="changeDelegator"/>
<response name="success" type="view" value="main"/>
<response name="error" type="view" value="error"/>
</request-map>

<!-- ================ Blog Requests ================= -->
<request-map uri="blogMain">
<security https="true" auth="true"/>
Expand Down
6 changes: 0 additions & 6 deletions applications/humanres/webapp/humanres/WEB-INF/controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ under the License.
<response name="success" type="request" value="main"/>
</request-map>

<request-map uri="changeDelegator">
<event type="java" path="org.ofbiz.webapp.event.CoreEvents" invoke="changeDelegator"/>
<response name="success" type="view" value="main"/>
<response name="error" type="view" value="error"/>
</request-map>

<request-map uri="main">
<security https="true" auth="true"/>
<response name="success" type="view" value="main"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ under the License.
<response name="success" type="request" value="main"/>
</request-map>

<request-map uri="changeDelegator">
<event type="java" path="org.ofbiz.webapp.event.CoreEvents" invoke="changeDelegator"/>
<response name="success" type="view" value="main"/>
<response name="error" type="view" value="error"/>
</request-map>

<request-map uri="main">
<security https="true" auth="true"/>
<response name="success" type="view" value="main"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ under the License.
<request-map uri="view"><security https="true" auth="false"/><response name="success" type="request" value="main"/></request-map>
<request-map uri="main"><security https="true" auth="true"/><response name="success" type="view" value="main"/></request-map>

<request-map uri="changeDelegator">
<security https="true" auth="true"/>
<event type="java" path="org.ofbiz.webapp.event.CoreEvents" invoke="changeDelegator"/>
<response name="success" type="view" value="main"/>
<response name="error" type="view" value="error"/>
</request-map>

<!-- =========== DataSource =========== -->
<request-map uri="FindDataSource"><security https="true" auth="true"/><response name="success" type="view" value="FindDataSource"/></request-map>
<request-map uri="EditDataSource"><security https="true" auth="true"/><response name="success" type="view" value="EditDataSource"/></request-map>
Expand Down
7 changes: 0 additions & 7 deletions applications/product/webapp/catalog/WEB-INF/controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ under the License.
<response name="success" type="view" value="FastLoadCache"/>
</request-map>

<request-map uri="changeDelegator">
<security https="true" auth="true"/>
<event type="java" path="org.ofbiz.webapp.event.CoreEvents" invoke="changeDelegator"/>
<response name="success" type="view" value="main"/>
<response name="error" type="view" value="error"/>
</request-map>

<request-map uri="advancedsearch">
<security https="true" auth="true"/>
<response name="success" type="view" value="advancedsearch"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ under the License.

<!-- Request Mappings -->

<request-map uri="changeDelegator">
<event type="java" path="org.ofbiz.webapp.event.CoreEvents" invoke="changeDelegator"/>
<response name="success" type="view" value="main"/>
<response name="error" type="view" value="error"/>
</request-map>

<request-map uri="view">
<security https="true" auth="true"/>
<response name="success" type="view" value="main"/>
Expand Down
6 changes: 0 additions & 6 deletions framework/bi/webapp/bi/WEB-INF/controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@
<response name="success" type="view" value="main"/>
</request-map>

<request-map uri="changeDelegator">
<event type="java" path="org.ofbiz.webapp.event.CoreEvents" invoke="changeDelegator"/>
<response name="success" type="view" value="main"/>
<response name="error" type="view" value="error"/>
</request-map>

<request-map uri="main">
<security https="true" auth="true"/>
<response name="success" type="view" value="main"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,10 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
LocalDispatcher dispatcher = getDispatcher(config.getServletContext());

// set web context objects
httpRequest.getSession().setAttribute("dispatcher", dispatcher);
httpRequest.getSession().setAttribute("security", security);
request.setAttribute("dispatcher", dispatcher);
request.setAttribute("security", security);

httpRequest.setAttribute("tenantId", tenantId);
request.setAttribute("tenantId", tenantId);
}

// NOTE DEJ20101130: do NOT always put the delegator name in the user's session because the user may
Expand Down
31 changes: 13 additions & 18 deletions framework/webapp/src/org/ofbiz/webapp/control/LoginWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,35 +474,30 @@ public static String login(HttpServletRequest request, HttpServletResponse respo
return "error";
}
}

private static void setWebContextObjects(HttpServletRequest request, HttpServletResponse response, Delegator delegator, LocalDispatcher dispatcher) {
HttpSession session = request.getSession();

// NOTE: we do NOT want to set this in the servletContet, only in the request and session
session.setAttribute("delegatorName", delegator.getDelegatorName());

request.setAttribute("delegator", delegator);
session.setAttribute("delegator", delegator);

request.setAttribute("dispatcher", dispatcher);
session.setAttribute("dispatcher", dispatcher);

// we also need to setup the security and authz objects since they are dependent on the delegator
// NOTE: we do NOT want to set this in the servletContext, only in the request and session
// We also need to setup the security and authz objects since they are dependent on the delegator
Security security = null;
try {
Security security = SecurityFactory.getInstance(delegator);
request.setAttribute("security", security);
session.setAttribute("security", security);
security = SecurityFactory.getInstance(delegator);
} catch (SecurityConfigurationException e) {
Debug.logError(e, module);
}

Authorization authz = null;
try {
Authorization authz = AuthorizationFactory.getInstance(delegator);
request.setAttribute("authz", authz);
session.setAttribute("authz", authz);
authz = AuthorizationFactory.getInstance(delegator);
} catch (SecurityConfigurationException e) {
Debug.logError(e, module);
}

session.setAttribute("delegatorName", delegator.getDelegatorName());
request.setAttribute("delegator", delegator);
request.setAttribute("dispatcher", dispatcher);
request.setAttribute("security", security);
request.setAttribute("authz", authz);

// get rid of the visit info since it was pointing to the previous database, and get a new one
session.removeAttribute("visitor");
session.removeAttribute("visit");
Expand Down
90 changes: 0 additions & 90 deletions framework/webapp/src/org/ofbiz/webapp/event/CoreEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,96 +96,6 @@ public static String returnNull(HttpServletRequest request, HttpServletResponse
return null;
}

/**
* Change delegator event. Changes the delegator for the current session
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return Response code string
*/
public static String changeDelegator(HttpServletRequest request, HttpServletResponse response) {
String delegatorName = request.getParameter("delegator");
Authorization authz = (Authorization) request.getAttribute("authz");
Locale locale = UtilHttp.getLocale(request);

if (!authz.hasPermission(request.getSession(), "ENTITY_MAINT", null)) {
String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.not_authorized_use_fct", locale);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
if (delegatorName == null) {
String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.delegator_not_passed", locale);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}

Delegator delegator = DelegatorFactory.getDelegator(delegatorName);

if (delegator == null) {
String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.no_delegator_name_defined", locale);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}

// now change the dispatcher to use this delegator
LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher");
DispatchContext dctx = dispatcher.getDispatchContext();
String dispatcherName = dispatcher.getName();

if (dispatcherName == null) {
String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.dispatcher_name_null", locale);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
if (dctx == null) {
String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.dispatcher_context_null", locale);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}

dispatcher = GenericDispatcher.getLocalDispatcher(dispatcherName, delegator);

request.getSession().setAttribute("delegator", delegator);
request.getSession().setAttribute("dispatcher", dispatcher);

return "success";
}

/**
* Change dispatcher event. Changes the dispatch for the current session
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return Response code string
*/
public static String changeDispatcher(HttpServletRequest request, HttpServletResponse response) {
String dispatcherName = request.getParameter("dispatcher");
Authorization authz = (Authorization) request.getAttribute("authz");
Locale locale = UtilHttp.getLocale(request);

if (!authz.hasPermission(request.getSession(), "ENTITY_MAINT", null)) {
String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.not_authorized_use_fct", locale);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
if (dispatcherName == null) {
String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.dispatcher_not_passed", locale);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}

Delegator delegator = (Delegator) request.getAttribute("delegator");
ServiceDispatcher sd = ServiceDispatcher.getInstance(dispatcherName, delegator);

if (sd == null) {
String errMsg = UtilProperties.getMessage(CoreEvents.err_resource, "coreEvents.no_dispachter_name_registered", locale);
request.setAttribute("_ERROR_MESSAGE_", errMsg);
return "error";
}
LocalDispatcher dispatcher = sd.getLocalContext(dispatcherName).getDispatcher();

request.getSession().setAttribute("dispatcher", dispatcher);
return "success";
}

/**
* Schedule a service for a specific time or recurrence
* Request Parameters which are used for this service:
Expand Down
6 changes: 0 additions & 6 deletions framework/webtools/webapp/webtools/WEB-INF/controller.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,6 @@ under the License.
<response name="success" type="url" value="http://www.yahoo.com"/>
</request-map>

<request-map uri="changeDelegator">
<event type="java" path="org.ofbiz.webapp.event.CoreEvents" invoke="changeDelegator"/>
<response name="success" type="view" value="main"/>
<response name="error" type="view" value="main"/>
</request-map>

<request-map uri="view">
<security https="true" auth="false"/>
<response name="success" type="view" value="main"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1193,13 +1193,6 @@ under the License.
<response name="error" type="view" value="login"/>
</request-map>

<request-map uri="changeDelegator">
<security https="false" auth="false"/>
<event type="java" path="org.ofbiz.webapp.event.CoreEvents" invoke="changeDelegator"/>
<response name="success" type="view" value="main"/>
<response name="error" type="view" value="error"/>
</request-map>

<request-map uri="tellafriend"><security https="false" auth="false"/><response name="success" type="view" value="tellafriend"/></request-map>
<request-map uri="emailFriend">
<security https="false" auth="false"/>
Expand Down

0 comments on commit ead8af3

Please sign in to comment.