Project:
View Issue Details[ Jump to Notes ] | [ Issue History ] [ Print ] | |||||||
ID | ||||||||
0012594 | ||||||||
Type | Category | Severity | Reproducibility | Date Submitted | Last Update | |||
defect | [Openbravo ERP] A. Platform | minor | have not tried | 2010-03-08 13:30 | 2010-05-19 00:00 | |||
Reporter | mtaal | View Status | public | |||||
Assigned To | mtaal | |||||||
Priority | normal | Resolution | fixed | Fixed in Version | ||||
Status | closed | Fix in branch | pi | Fixed in SCM revision | 573900290738 | |||
Projection | none | ETA | none | Target Version | pi | |||
OS | Any | Database | Any | Java version | ||||
OS Version | Database version | Ant version | ||||||
Product Version | pi | SCM revision | ||||||
Merge Request Status | ||||||||
Review Assigned To | ||||||||
OBNetwork customer | No | |||||||
Web browser | ||||||||
Modules | Core | |||||||
Support ticket | ||||||||
Regression level | ||||||||
Regression date | ||||||||
Regression introduced in release | ||||||||
Regression introduced by commit | ||||||||
Triggers an Emergency Pack | No | |||||||
Summary | 0012594: Make setting of administrator mode less vulnerable for wrong usage | |||||||
Description | Make setting of administrator mode less vulnerable for wrong usage. The current approach is this: bool oldMode = ...setAdminMode(true) try { }finally { setAdminMode(oldMode) } If one forgets to use the oldMode variable and instead does: setAdminMode(false) then this gives unpredictable results. The following api is less vulnerable: setInAdminMode(); try { } finally { restorePreviousAdminMode(); } | |||||||
Tags | No tags attached. | |||||||
Attached Files | ![]() diff --git a/src-test/org/openbravo/test/base/BaseTest.java b/src-test/org/openbravo/test/base/BaseTest.java --- a/src-test/org/openbravo/test/base/BaseTest.java +++ b/src-test/org/openbravo/test/base/BaseTest.java @@ -173,6 +173,13 @@ */ @Override protected void tearDown() throws Exception { + // if not an administrator but still admin mode set throw an exception + if (!OBContext.getOBContext().getUser().getId().equals("0") + && !OBContext.getOBContext().getRole().getId().equals("0") + && OBContext.getOBContext().isInAdministratorMode()) { + throw new IllegalStateException( + "Test case should take care of reseting admin mode correctly in a finally block, use OBContext.resetAsAdminContext"); + } try { if (SessionHandler.isSessionHandlerPresent()) { if (SessionHandler.getInstance().getDoRollback()) { diff --git a/src-test/org/openbravo/test/dal/OBContextTest.java b/src-test/org/openbravo/test/dal/OBContextTest.java --- a/src-test/org/openbravo/test/dal/OBContextTest.java +++ b/src-test/org/openbravo/test/dal/OBContextTest.java @@ -31,8 +31,9 @@ public class OBContextTest extends BaseTest { /** - * Tests if the {@link OBContext#setInAdministratorMode(boolean)} works correctly if the same - * OBContext is used by multiple threads. This is possible in case of simultaneous ajax requests. + * Tests if the {@link OBContext#setAdminMode()} and + * {@link OBContext#restorePreviousMode()} work correctly if the same OBContext is used by + * multiple threads. This is possible in case of simultaneous ajax requests. * * See: https://issues.openbravo.com/view.php?id=8853 */ @@ -52,7 +53,7 @@ // also tests if this thread influences the other two! // main thread is true - OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { t1.start(); @@ -130,6 +131,7 @@ t2.setFirstStep(true); t1.setNextStep(true); t2.setNextStep(true); + OBContext.restorePreviousMode(); } } @@ -160,13 +162,13 @@ while (!firstStep) { adminMode = OBContext.getOBContext().isInAdministratorMode(); } - prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); adminMode = OBContext.getOBContext().isInAdministratorMode(); firstStepDone = true; while (!nextStep) { adminMode = OBContext.getOBContext().isInAdministratorMode(); } - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); adminMode = OBContext.getOBContext().isInAdministratorMode(); nextStepDone = true; } catch (Exception e) { diff --git a/src-test/org/openbravo/test/model/UtilsTest.java b/src-test/org/openbravo/test/model/UtilsTest.java --- a/src-test/org/openbravo/test/model/UtilsTest.java +++ b/src-test/org/openbravo/test/model/UtilsTest.java @@ -92,7 +92,7 @@ // as we read all entities, be an administrator to prevent // security exceptions - OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); // iterate over all entities for (Entity entity : ModelProvider.getInstance().getModel()) { diff --git a/src-test/org/openbravo/test/xml/EntityXMLImportTestBusinessObject.java b/src-test/org/openbravo/test/xml/EntityXMLImportTestBusinessObject.java --- a/src-test/org/openbravo/test/xml/EntityXMLImportTestBusinessObject.java +++ b/src-test/org/openbravo/test/xml/EntityXMLImportTestBusinessObject.java @@ -203,21 +203,25 @@ setUserContext("1000019"); // a payment term line is not deletable, but for this test it should be done anyway // force this by being admin - OBContext.getOBContext().setInAdministratorMode(true); - final ImportResult ir = DataImportService.getInstance().importDataFromXML( - OBDal.getInstance().get(Client.class, "1000001"), - OBDal.getInstance().get(Organization.class, "1000001"), xml); - if (ir.getException() != null) { - ir.getException().printStackTrace(System.err); - fail(ir.getException().getMessage()); - } + OBContext.setAdminMode(); + try { + final ImportResult ir = DataImportService.getInstance().importDataFromXML( + OBDal.getInstance().get(Client.class, "1000001"), + OBDal.getInstance().get(Organization.class, "1000001"), xml); + if (ir.getException() != null) { + ir.getException().printStackTrace(System.err); + fail(ir.getException().getMessage()); + } - assertEquals(0, ir.getInsertedObjects().size()); - // name of paymentterm has changed - // overduepaymentrule of paymenttermline is set back to 1 - assertEquals(2, ir.getUpdatedObjects().size()); - for (final Object o : ir.getUpdatedObjects()) { - assertTrue(o instanceof PaymentTerm || o instanceof PaymentTermLine); + assertEquals(0, ir.getInsertedObjects().size()); + // name of paymentterm has changed + // overduepaymentrule of paymenttermline is set back to 1 + assertEquals(2, ir.getUpdatedObjects().size()); + for (final Object o : ir.getUpdatedObjects()) { + assertTrue(o instanceof PaymentTerm || o instanceof PaymentTermLine); + } + } finally { + OBContext.restorePreviousMode(); } } @@ -308,21 +312,24 @@ final List<PaymentTerm> pts = getPaymentTerms(); // financialmanagementpaymenttermline is not deletable, but as we are cleaning up // force delete by being the admin - OBContext.getOBContext().setInAdministratorMode(true); - for (final PaymentTerm pt : pts) { - OBDal.getInstance().remove(pt); + OBContext.setAdminMode(); + try { + for (final PaymentTerm pt : pts) { + OBDal.getInstance().remove(pt); + } + commitTransaction(); + + setUserContext("1000019"); + final List<PaymentTerm> pts2 = getPaymentTerms(); + // financialmanagementpaymenttermline is not deletable, but as we are cleaning up + // force delete by being the admin + for (final PaymentTerm pt : pts2) { + OBDal.getInstance().remove(pt); + } + commitTransaction(); + } finally { + OBContext.restorePreviousMode(); } - commitTransaction(); - - setUserContext("1000019"); - final List<PaymentTerm> pts2 = getPaymentTerms(); - // financialmanagementpaymenttermline is not deletable, but as we are cleaning up - // force delete by being the admin - OBContext.getOBContext().setInAdministratorMode(true); - for (final PaymentTerm pt : pts2) { - OBDal.getInstance().remove(pt); - } - commitTransaction(); } private void createSavePaymentTerm() { diff --git a/src-test/org/openbravo/test/xml/EntityXMLImportTestReference.java b/src-test/org/openbravo/test/xml/EntityXMLImportTestReference.java --- a/src-test/org/openbravo/test/xml/EntityXMLImportTestReference.java +++ b/src-test/org/openbravo/test/xml/EntityXMLImportTestReference.java @@ -86,8 +86,12 @@ setUserContext("1000019"); // a warehouse is not deletable, but as we are cleaning up, they should be // deleted, force this by being admin - OBContext.getOBContext().setInAdministratorMode(true); - removeAll(Warehouse.class, 2, Expression.ne("id", "1000002")); + OBContext.setAdminMode(); + try { + removeAll(Warehouse.class, 2, Expression.ne("id", "1000002")); + } finally { + OBContext.restorePreviousMode(); + } } /** @@ -126,10 +130,14 @@ setUserContext("1000019"); // a warehouse is not deletable, but as we are cleaning up, they should be // deleted, force this by being admin - OBContext.getOBContext().setInAdministratorMode(true); - removeAll(Warehouse.class, 2, Expression.ne("id", "1000002")); - removeAll(Location.class, 2, Expression.not(Expression.in("id", new String[] { "1000048", - "1000049", "1000050" }))); + OBContext.setAdminMode(); + try { + removeAll(Warehouse.class, 2, Expression.ne("id", "1000002")); + removeAll(Location.class, 2, Expression.not(Expression.in("id", new String[] { "1000048", + "1000049", "1000050" }))); + } finally { + OBContext.restorePreviousMode(); + } } private <T extends BaseOBObject> void removeAll(Class<T> clz, int expectCount, Criterion c) { diff --git a/src/org/openbravo/base/secureApp/HttpSecureAppServlet.java b/src/org/openbravo/base/secureApp/HttpSecureAppServlet.java --- a/src/org/openbravo/base/secureApp/HttpSecureAppServlet.java +++ b/src/org/openbravo/base/secureApp/HttpSecureAppServlet.java @@ -198,7 +198,7 @@ try { - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); strUserAuth = m_AuthManager.authenticate(request, response); @@ -343,7 +343,7 @@ logout(request, response); return; } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } try { diff --git a/src/org/openbravo/base/secureApp/LoginHandler.java b/src/org/openbravo/base/secureApp/LoginHandler.java --- a/src/org/openbravo/base/secureApp/LoginHandler.java +++ b/src/org/openbravo/base/secureApp/LoginHandler.java @@ -56,7 +56,7 @@ final String strUser = vars.getStringParameter("user"); - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); try { Client systemClient = OBDal.getInstance().get(Client.class, "0"); @@ -98,7 +98,7 @@ } } } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } } @@ -130,7 +130,7 @@ private void checkLicenseAndGo(HttpServletResponse res, VariablesSecureApp vars, String strUserAuth, String sessionId) throws IOException { - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); try { ActivationKey ak = new ActivationKey(); boolean hasSystem = false; @@ -212,14 +212,14 @@ goToRetry(res, vars, msg, title, msgType, action); } } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } } private void updateDBSession(String sessionId, boolean sessionActive, String status) { try { - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); Session session = OBDal.getInstance().get(Session.class, sessionId); session.setSessionActive(sessionActive); session.setLoginStatus(status); @@ -227,7 +227,7 @@ } catch (Exception e) { log4j.error("Error updating session in DB", e); } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } } diff --git a/src/org/openbravo/base/secureApp/LoginUtils.java b/src/org/openbravo/base/secureApp/LoginUtils.java --- a/src/org/openbravo/base/secureApp/LoginUtils.java +++ b/src/org/openbravo/base/secureApp/LoginUtils.java @@ -141,7 +141,7 @@ // Organizations tree // enable admin mode, as normal non admin-role // has no read-access to i.e. AD_OrgType - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); try { OrgTree tree = new OrgTree(conn, strCliente); @@ -152,7 +152,7 @@ log4j.warn("Error while setting Organzation tree to session " + e); return false; } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } try { diff --git a/src/org/openbravo/base/secureApp/UserLock.java b/src/org/openbravo/base/secureApp/UserLock.java --- a/src/org/openbravo/base/secureApp/UserLock.java +++ b/src/org/openbravo/base/secureApp/UserLock.java @@ -128,7 +128,7 @@ } private void setUser() { - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); try { OBCriteria<User> obCriteria = OBDal.getInstance().createCriteria(User.class); obCriteria.add(Expression.eq(User.PROPERTY_USERNAME, userName)); @@ -137,7 +137,7 @@ user = (User) obCriteria.uniqueResult(); } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } } @@ -154,14 +154,14 @@ delay = 0; if (user != null) { try { - OBContext.setAdminContext(); + OBContext.setAdminMode(); user.setLocked(true); OBDal.getInstance().flush(); log4j.warn(userName + " is locked after " + numberOfFails + " failed logins."); return; } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } } } diff --git a/src/org/openbravo/base/secureApp/VariablesSecureApp.java b/src/org/openbravo/base/secureApp/VariablesSecureApp.java --- a/src/org/openbravo/base/secureApp/VariablesSecureApp.java +++ b/src/org/openbravo/base/secureApp/VariablesSecureApp.java @@ -206,7 +206,7 @@ Client systemClient = OBDal.getInstance().get(Client.class, "0"); // Get theme (skin) - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); try { org.openbravo.model.ad.system.System sys = OBDal.getInstance().get( org.openbravo.model.ad.system.System.class, "0"); @@ -219,7 +219,7 @@ // set default theme and ignore exception strTheme = ""; } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } } } finally { diff --git a/src/org/openbravo/dal/core/DalInitializingTask.java b/src/org/openbravo/dal/core/DalInitializingTask.java --- a/src/org/openbravo/dal/core/DalInitializingTask.java +++ b/src/org/openbravo/dal/core/DalInitializingTask.java @@ -115,7 +115,7 @@ log.debug("Setting user context to user " + getUserId()); OBContext.setOBContext(getUserId()); if (isAdminMode()) { - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); } doExecute(); errorOccured = false; @@ -126,7 +126,7 @@ OBDal.getInstance().commitAndClose(); } if (isAdminMode()) { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } } } diff --git a/src/org/openbravo/dal/core/DalRequestFilter.java b/src/org/openbravo/dal/core/DalRequestFilter.java --- a/src/org/openbravo/dal/core/DalRequestFilter.java +++ b/src/org/openbravo/dal/core/DalRequestFilter.java @@ -92,6 +92,8 @@ // set to null all the session info SessionInfo.init(); + OBContext.clearAdminModeStack(); + super.doFinal(errorOccured); } }; diff --git a/src/org/openbravo/dal/core/OBContext.java b/src/org/openbravo/dal/core/OBContext.java --- a/src/org/openbravo/dal/core/OBContext.java +++ b/src/org/openbravo/dal/core/OBContext.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Stack; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; @@ -81,18 +82,16 @@ private static ThreadLocal<OBContext> adminModeSet = new ThreadLocal<OBContext>(); + private static ThreadLocal<Stack<Boolean>> adminModeStack = new ThreadLocal<Stack<Boolean>>(); + public static final String CONTEXT_PARAM = "#OBContext"; private static OBContext adminContext = null; /** - * Sets the context to the 0 (SystemAdmin) user. - * - * Note overwrites the current OBContext! This method should be used in case there is no real user - * context yet because the user still has to login (for example). - * - * In all other cases use the method {@link #setInAdministratorMode(boolean)}. + * @deprecated use {@link #setAdminMode()} */ + @Deprecated public static void setAdminContext() { if (adminContext == null) { setOBContext("0", "0", "0", "0"); @@ -102,41 +101,91 @@ } } - /** - * Checks if there is a context set. If not then sets the Admin Context. If yes then set the admin - * mode of the existing context. - * - * @see OBContext#resetAsAdminContext() - */ - public static void enableAsAdminContext() { - if (OBContext.getOBContext() == null) { - OBContext.setAdminContext(); - } else if (OBContext.getOBContext() == adminContext) { - return; + private static void setAdminContextLocally() { + if (adminContext == null) { + setOBContext("0", "0", "0", "0"); + adminContext = getOBContext(); } else { - OBContext.getOBContext().setInAdministratorMode(true); + setOBContext(adminContext); } } /** - * Sets the context state back. If the current context is the Admin Context then the current - * context is set to null. In the other cases the method {@link #setInAdministratorMode(boolean)} - * is called with the parameter false. + * @deprecated use {@link #setAdminMode()} + */ + @Deprecated + public static void enableAsAdminContext() { + setAdminMode(); + } + + /** + * Let's the current user run with Administrator privileges. If there is no current user then the + * special Administrator context is used. * - * @see OBContext#enableAsAdminContext() + * To restore the previous privileges call the {@link #restorePreviousMode()}. + * + * @see OBContext#restorePreviousMode() */ + public static void setAdminMode() { + getAdminModeStack().push(Boolean.TRUE); + if (OBContext.getOBContext() == null) { + OBContext.setAdminContextLocally(); + } else if (OBContext.getOBContext() == adminContext) { + return; + } + } + + private static Stack<Boolean> getAdminModeStack() { + if (adminModeStack.get() == null) { + adminModeStack.set(new Stack<Boolean>()); + } + return adminModeStack.get(); + } + + /** + * @deprecated use {@link #restorePreviousMode()} + */ + @Deprecated public static void resetAsAdminContext() { + restorePreviousMode(); + } + + /** + * Is used to restore the previous privileges after enabling Administrator privileges by calling + * {@link #setAdminMode()}. + * + * @see OBContext#setAdminMode() + */ + public static void restorePreviousMode() { + // remove the last admin mode from the stack + final Stack<Boolean> stack = getAdminModeStack(); + if (stack.size() > 0) { + stack.pop(); + } else { + log.warn("Unbalanced calls to enableAsAdminContext and resetAsAdminContext", + new IllegalStateException()); + } + if (OBContext.getOBContext() == null) { return; } - if (OBContext.getOBContext() == adminContext) { + if (stack.isEmpty() && OBContext.getOBContext() == adminContext) { OBContext.setOBContext((OBContext) null); - } else { - OBContext.getOBContext().setInAdministratorMode(false); } } /** + * Clears the admin context stack. + */ + static void clearAdminModeStack() { + if (getAdminModeStack().size() > 0) { + log.warn("Unbalanced calls to enableAsAdminContext and resetAsAdminContext", + new IllegalStateException()); + } + getAdminModeStack().clear(); + } + + /** * Sets the OBContext through the information stored in the http session of the request (mainly * the authenticated user). Note will not set the context in the http session if the session is * not present. @@ -541,7 +590,11 @@ return false; } setInitialized(false); - setInAdministratorMode(true); + + // can't use enableAsAdminContext here otherwise there is a danger of + // recursive/infinite calls. + // enableAsAdminContext(); + getAdminModeStack().push(Boolean.TRUE); try { setUser(u); Hibernate.initialize(getUser().getClient()); @@ -678,7 +731,10 @@ // TODO: add logging of all context information } finally { - setInAdministratorMode(false); + // can't use resetAsAdminContext here otherwise there is a danger of + // recursive/infinite calls. + // resetAsAdminContext(); + getAdminModeStack().pop(); setInitialized(true); } return true; @@ -775,6 +831,9 @@ } public boolean isInAdministratorMode() { + if (getAdminModeStack().size() > 0 && getAdminModeStack().peek()) { + return true; + } return adminModeSet.get() != null || isAdministrator; } @@ -782,6 +841,10 @@ return this == adminContext; } + /** + * @deprecated use {@link #setAdminMode()} and {@link #restorePreviousMode()}. + */ + @Deprecated public boolean setInAdministratorMode(boolean inAdministratorMode) { final boolean prevMode = isInAdministratorMode(); if (inAdministratorMode) { diff --git a/src/org/openbravo/dal/core/TriggerHandler.java b/src/org/openbravo/dal/core/TriggerHandler.java --- a/src/org/openbravo/dal/core/TriggerHandler.java +++ b/src/org/openbravo/dal/core/TriggerHandler.java @@ -59,7 +59,7 @@ log.debug("Disabling triggers"); Check.isNull(sessionStatus.get(), "There is already a ADSessionStatus present in this thread, " + "call enable before calling disable again"); - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { final SessionStatus localSessionStatus = OBProvider.getInstance().get(SessionStatus.class); localSessionStatus.setImporting(true); @@ -70,7 +70,7 @@ Check.isNotNull(localSessionStatus.getId(), "The id is not set after insert"); sessionStatus.set(localSessionStatus); } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } } @@ -96,13 +96,13 @@ log.debug("Enabling triggers"); Check.isNotNull(sessionStatus.get(), "SessionStatus not set, call disable " + "before calling this method"); - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { OBDal.getInstance().remove(sessionStatus.get()); OBDal.getInstance().flush(); } finally { sessionStatus.set(null); - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } } } \ No newline at end of file diff --git a/src/org/openbravo/dal/security/EntityAccessChecker.java b/src/org/openbravo/dal/security/EntityAccessChecker.java --- a/src/org/openbravo/dal/security/EntityAccessChecker.java +++ b/src/org/openbravo/dal/security/EntityAccessChecker.java @@ -155,6 +155,14 @@ writableEntities.remove(e); readableEntities.add(e); nonReadableEntities.remove(e); + } else { + if (!writableEntities.contains(e)) { + writableEntities.add(e); + } + if (!readableEntities.contains(e)) { + readableEntities.add(e); + } + nonReadableEntities.remove(e); } } diff --git a/src/org/openbravo/dal/xml/EntityResolver.java b/src/org/openbravo/dal/xml/EntityResolver.java --- a/src/org/openbravo/dal/xml/EntityResolver.java +++ b/src/org/openbravo/dal/xml/EntityResolver.java @@ -316,8 +316,7 @@ // and then re-imported that it occurs multiple times. private List<String> getId(String id, Entity entity, String orgId) { final String[] searchOrgIds = getOrgIds(orgId); - final boolean adminMode = OBContext.getOBContext().isInAdministratorMode(); - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { final OBCriteria<ReferenceDataStore> rdlCriteria = OBDal.getInstance().createCriteria( ReferenceDataStore.class); @@ -339,10 +338,7 @@ } return result; } finally { - // only set back if the previous was false - if (!adminMode) { - OBContext.getOBContext().setInAdministratorMode(prevMode); - } + OBContext.restorePreviousMode(); } } @@ -367,12 +363,12 @@ if (clientZero != null) { return; } - final boolean oldSetting = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { clientZero = OBDal.getInstance().get(Client.class, "0"); organizationZero = OBDal.getInstance().get(Organization.class, "0"); } finally { - OBContext.getOBContext().setInAdministratorMode(oldSetting); + OBContext.restorePreviousMode(); } } diff --git a/src/org/openbravo/dal/xml/EntityXMLConverter.java b/src/org/openbravo/dal/xml/EntityXMLConverter.java --- a/src/org/openbravo/dal/xml/EntityXMLConverter.java +++ b/src/org/openbravo/dal/xml/EntityXMLConverter.java @@ -577,9 +577,8 @@ if (!isAddSystemAttributes()) { return; } - final boolean adminMode = OBContext.getOBContext().isInAdministratorMode(); try { - OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); final List<SystemInformation> sis = OBDal.getInstance().createCriteria( SystemInformation.class).list(); Check.isTrue(sis.size() > 0, "There should be at least one SystemInfo record but there are " @@ -592,7 +591,7 @@ .getCodeRevision() + ""); } finally { - OBContext.getOBContext().setInAdministratorMode(adminMode); + OBContext.restorePreviousMode(); } } diff --git a/src/org/openbravo/erpCommon/ad_callouts/SL_GlobalUse_Product.java b/src/org/openbravo/erpCommon/ad_callouts/SL_GlobalUse_Product.java --- a/src/org/openbravo/erpCommon/ad_callouts/SL_GlobalUse_Product.java +++ b/src/org/openbravo/erpCommon/ad_callouts/SL_GlobalUse_Product.java @@ -91,7 +91,7 @@ + FormatUtilities.replaceJS(SLInOutLineProductData.attribute(this, strPAttr)) + "\"),\n"); String strAttrSet, strAttrSetValueType; strAttrSet = strAttrSetValueType = ""; - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { final Product product = OBDal.getInstance().get(Product.class, strMProductID); if (product != null) { @@ -101,7 +101,7 @@ strAttrSetValueType = product.getUseAttributeSetValueAs(); } } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } resultado.append("new Array(\"inpattributeset\", \"" + FormatUtilities.replaceJS(strAttrSet) + "\"),\n"); diff --git a/src/org/openbravo/erpCommon/ad_callouts/SL_InOutLine_Product.java b/src/org/openbravo/erpCommon/ad_callouts/SL_InOutLine_Product.java --- a/src/org/openbravo/erpCommon/ad_callouts/SL_InOutLine_Product.java +++ b/src/org/openbravo/erpCommon/ad_callouts/SL_InOutLine_Product.java @@ -112,7 +112,7 @@ + "\"),\n"); String strAttrSet, strAttrSetValueType; strAttrSet = strAttrSetValueType = ""; - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { final Product product = OBDal.getInstance().get(Product.class, strMProductID); if (product != null) { @@ -122,7 +122,7 @@ strAttrSetValueType = product.getUseAttributeSetValueAs(); } } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } resultado.append("new Array(\"inpattributeset\", \"" + FormatUtilities.replaceJS(strAttrSet) + "\"),\n"); diff --git a/src/org/openbravo/erpCommon/ad_callouts/SL_Internal_Consumption_Product.java b/src/org/openbravo/erpCommon/ad_callouts/SL_Internal_Consumption_Product.java --- a/src/org/openbravo/erpCommon/ad_callouts/SL_Internal_Consumption_Product.java +++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Internal_Consumption_Product.java @@ -100,7 +100,7 @@ + FormatUtilities.replaceJS(SLInOutLineProductData.attribute(this, strPAttr)) + "\"),\n"); String strAttrSet, strAttrSetValueType; strAttrSet = strAttrSetValueType = ""; - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { final Product product = OBDal.getInstance().get(Product.class, strProduct); if (product != null) { @@ -110,7 +110,7 @@ strAttrSetValueType = product.getUseAttributeSetValueAs(); } } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } resultado.append("new Array(\"inpattributeset\", \"" + FormatUtilities.replaceJS(strAttrSet) + "\"),\n"); diff --git a/src/org/openbravo/erpCommon/ad_callouts/SL_Inventory_Product.java b/src/org/openbravo/erpCommon/ad_callouts/SL_Inventory_Product.java --- a/src/org/openbravo/erpCommon/ad_callouts/SL_Inventory_Product.java +++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Inventory_Product.java @@ -98,7 +98,7 @@ + FormatUtilities.replaceJS(SLInOutLineProductData.attribute(this, strAttribute)) + "\"),"); String strAttrSet, strAttrSetValueType; strAttrSet = strAttrSetValueType = ""; - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { final Product product = OBDal.getInstance().get(Product.class, strProduct); if (product != null) { @@ -108,7 +108,7 @@ strAttrSetValueType = product.getUseAttributeSetValueAs(); } } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } resultado.append("new Array(\"inpattributeset\", \"" + FormatUtilities.replaceJS(strAttrSet) + "\"),\n"); diff --git a/src/org/openbravo/erpCommon/ad_callouts/SL_Movement_Product.java b/src/org/openbravo/erpCommon/ad_callouts/SL_Movement_Product.java --- a/src/org/openbravo/erpCommon/ad_callouts/SL_Movement_Product.java +++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Movement_Product.java @@ -101,7 +101,7 @@ + FormatUtilities.replaceJS(SLInOutLineProductData.attribute(this, strAttribute)) + "\"),"); String strAttrSet, strAttrSetValueType; strAttrSet = strAttrSetValueType = ""; - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { final Product product = OBDal.getInstance().get(Product.class, strMProductID); if (product != null) { @@ -111,7 +111,7 @@ strAttrSetValueType = product.getUseAttributeSetValueAs(); } } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } resultado.append("new Array(\"inpattributeset\", \"" + FormatUtilities.replaceJS(strAttrSet) + "\"),\n"); diff --git a/src/org/openbravo/erpCommon/ad_callouts/SL_PC_Case_Product.java b/src/org/openbravo/erpCommon/ad_callouts/SL_PC_Case_Product.java --- a/src/org/openbravo/erpCommon/ad_callouts/SL_PC_Case_Product.java +++ b/src/org/openbravo/erpCommon/ad_callouts/SL_PC_Case_Product.java @@ -84,7 +84,7 @@ + FormatUtilities.replaceJS(strattrsetvaluesdescr) + "\"),\n"); String strAttrSet, strAttrSetValueType; strAttrSet = strAttrSetValueType = ""; - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { final Product product = OBDal.getInstance().get(Product.class, strMProductID); if (product != null) { @@ -94,7 +94,7 @@ strAttrSetValueType = product.getUseAttributeSetValueAs(); } } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } result.append("new Array(\"inpattributeset\", \"" + FormatUtilities.replaceJS(strAttrSet) + "\"),\n"); diff --git a/src/org/openbravo/erpCommon/ad_callouts/SL_Production_Product.java b/src/org/openbravo/erpCommon/ad_callouts/SL_Production_Product.java --- a/src/org/openbravo/erpCommon/ad_callouts/SL_Production_Product.java +++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Production_Product.java @@ -100,7 +100,7 @@ + FormatUtilities.replaceJS(SLInOutLineProductData.attribute(this, strPAttr)) + "\"),\n"); String strAttrSet, strAttrSetValueType; strAttrSet = strAttrSetValueType = ""; - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { final Product product = OBDal.getInstance().get(Product.class, strProduct); if (product != null) { @@ -110,7 +110,7 @@ strAttrSetValueType = product.getUseAttributeSetValueAs(); } } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } resultado.append("new Array(\"inpattributeset\", \"" + FormatUtilities.replaceJS(strAttrSet) + "\"),\n"); diff --git a/src/org/openbravo/erpCommon/ad_callouts/SL_RequisitionLine_Product.java b/src/org/openbravo/erpCommon/ad_callouts/SL_RequisitionLine_Product.java --- a/src/org/openbravo/erpCommon/ad_callouts/SL_RequisitionLine_Product.java +++ b/src/org/openbravo/erpCommon/ad_callouts/SL_RequisitionLine_Product.java @@ -145,7 +145,7 @@ + "\"),\n"); String strAttrSet, strAttrSetValueType; strAttrSet = strAttrSetValueType = ""; - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { final Product product = OBDal.getInstance().get(Product.class, strMProductID); if (product != null) { @@ -155,7 +155,7 @@ strAttrSetValueType = product.getUseAttributeSetValueAs(); } } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } resultado.append("new Array(\"inpattributeset\", \"" + FormatUtilities.replaceJS(strAttrSet) + "\"),\n"); diff --git a/src/org/openbravo/erpCommon/ad_forms/About.java b/src/org/openbravo/erpCommon/ad_forms/About.java --- a/src/org/openbravo/erpCommon/ad_forms/About.java +++ b/src/org/openbravo/erpCommon/ad_forms/About.java @@ -51,7 +51,7 @@ if (log4j.isDebugEnabled()) log4j.debug("Output: dataSheet"); - boolean adminMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { ActivationKey ak = new ActivationKey(); response.setContentType("text/html; charset=UTF-8"); @@ -96,7 +96,7 @@ out.println(xmlDocument.print()); out.close(); } finally { - OBContext.getOBContext().setInAdministratorMode(adminMode); + OBContext.restorePreviousMode(); } } diff --git a/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java b/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java --- a/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java +++ b/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java @@ -96,7 +96,7 @@ transaction.getFinPayment().getId()); List<FIN_PaymentDetail> paymentDetails = payment.getFINPaymentDetailList(); FieldProviderFactory[] data = new FieldProviderFactory[paymentDetails.size()]; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { for (int i = 0; i < data.length; i++) { data[i] = new FieldProviderFactory(new HashMap()); @@ -140,14 +140,14 @@ FieldProviderFactory.setField(data[0], "lineno", transaction.getLineNo().toString()); } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return data; } public FieldProviderFactory[] loadLinesGLItemFieldProvider(FIN_FinaccTransaction transaction) { FieldProviderFactory[] data = new FieldProviderFactory[1]; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { data[0] = new FieldProviderFactory(new HashMap()); FieldProviderFactory.setField(data[0], "FIN_Finacc_Transaction_ID", transaction.getId()); @@ -174,7 +174,7 @@ .getId()); FieldProviderFactory.setField(data[0], "lineno", transaction.getLineNo().toString()); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return data; } @@ -212,7 +212,7 @@ // Select specific definition String strClassname = ""; final StringBuilder whereClause = new StringBuilder(); - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { whereClause.append(" as astdt "); whereClause.append(" where astdt.acctschemaTable.accountingSchema.id = '" @@ -252,7 +252,7 @@ } } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } Fact fact = new Fact(this, as, Fact.POST_Actual); for (int i = 0; p_lines != null && i < p_lines.length; i++) { @@ -360,7 +360,7 @@ // Checks if this step (Reconciliation) is configured to generate accounting for the // selected financial account boolean confirmation = false; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { List<FIN_FinancialAccountAccounting> accounts = financialAccount .getFINFinancialAccountAcctList(); @@ -369,7 +369,7 @@ confirmation = true; } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return confirmation; } @@ -378,7 +378,7 @@ // Checks if this step (Make receive payment) is configured to generate accounting for the // selected financial account boolean confirmation = false; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { List<FIN_FinancialAccountAccounting> accounts = payment.getAccount() .getFINFinancialAccountAcctList(); @@ -388,7 +388,7 @@ confirmation = true; } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return confirmation; } @@ -396,7 +396,7 @@ public boolean getDocumentConfirmation(ConnectionProvider conn, String strRecordId) { // Checks if this step is configured to generate accounting for the selected financial account boolean confirmation = false; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class, strRecordId); @@ -412,7 +412,7 @@ confirmation = true; } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } if (!confirmation) setStatus(STATUS_DocumentDisabled); @@ -424,7 +424,7 @@ FIN_FinaccTransaction transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class, Id); FieldProviderFactory[] data = new FieldProviderFactory[1]; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { data[0] = new FieldProviderFactory(new HashMap()); FieldProviderFactory.setField(data[0], "AD_Client_ID", transaction.getClient().getId()); @@ -461,14 +461,14 @@ FieldProviderFactory.setField(data[0], "Processed", transaction.isProcessed() ? "Y" : "N"); FieldProviderFactory.setField(data[0], "Processing", transaction.isProcessNow() ? "Y" : "N"); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } setObjectFieldProvider(data); } public Account getAccountGLItem(GLItem glItem, AcctSchema as, boolean bIsReceipt, ConnectionProvider conn) throws ServletException { - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); Account account = null; try { OBCriteria<GLItemAccounts> accounts = OBDal.getInstance() @@ -489,7 +489,7 @@ else account = new Account(conn, accountList.get(0).getGlitemDebitAcct().getId()); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return account; } @@ -497,7 +497,7 @@ public Account getAccountFee(AcctSchema as, FIN_FinancialAccount finAccount, ConnectionProvider conn) throws ServletException { Account account = null; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { OBCriteria<FIN_FinancialAccountAccounting> accounts = OBDal.getInstance().createCriteria( FIN_FinancialAccountAccounting.class); @@ -513,7 +513,7 @@ return null; account = new Account(conn, accountList.get(0).getFINBankfeeAcct().getId()); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return account; } @@ -531,7 +531,7 @@ public Account getAccount(ConnectionProvider conn, FIN_FinancialAccount finAccount, AcctSchema as, boolean bIsReceipt) throws ServletException { Account account = null; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { OBCriteria<FIN_FinancialAccountAccounting> accounts = OBDal.getInstance().createCriteria( FIN_FinancialAccountAccounting.class); @@ -550,14 +550,14 @@ else account = new Account(conn, accountList.get(0).getWithdrawalAccount().getId()); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return account; } public Account getAccountPayment(ConnectionProvider conn, FIN_FinancialAccount finAccount, AcctSchema as, boolean bIsReceipt) throws ServletException { - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); Account account = null; try { OBCriteria<FIN_FinancialAccountAccounting> accounts = OBDal.getInstance().createCriteria( @@ -577,14 +577,14 @@ else account = new Account(conn, accountList.get(0).getMakePaymentAccount().getId()); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return account; } public Account getAccountReconciliation(ConnectionProvider conn, FIN_FinancialAccount finAccount, AcctSchema as) throws ServletException { - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); Account account = null; try { OBCriteria<FIN_FinancialAccountAccounting> accounts = OBDal.getInstance().createCriteria( @@ -601,7 +601,7 @@ return null; account = new Account(conn, accountList.get(0).getDebitAccount().getId()); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return account; } diff --git a/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java b/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java --- a/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java +++ b/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java @@ -75,7 +75,7 @@ return null; FieldProviderFactory[] data = new FieldProviderFactory[paymentDetails.size()]; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { for (int i = 0; i < data.length; i++) { data[i] = new FieldProviderFactory(new HashMap()); @@ -100,7 +100,7 @@ paymentDetails.get(i).isPrepayment() ? "Y" : "N"); } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return data; } @@ -132,7 +132,7 @@ final StringBuilder whereClause = new StringBuilder(); Fact fact = new Fact(this, as, Fact.POST_Actual); String Fact_Acct_Group_ID = SequenceIdData.getUUID(); - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { whereClause.append(" as astdt "); whereClause.append(" where astdt.acctschemaTable.accountingSchema.id = '" @@ -196,7 +196,7 @@ Fact_Acct_Group_ID, "999999", DocumentType, conn); } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } SeqNo = "0"; @@ -216,7 +216,7 @@ public boolean getDocumentConfirmation(ConnectionProvider conn, String strRecordId) { // Checks if this step is configured to generate accounting for the selected financial account boolean confirmation = false; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { FIN_Payment payment = OBDal.getInstance().get(FIN_Payment.class, strRecordId); List<FIN_FinancialAccountAccounting> accounts = payment.getAccount() @@ -227,7 +227,7 @@ confirmation = true; } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } if (!confirmation) setStatus(STATUS_DocumentDisabled); @@ -262,7 +262,7 @@ public Account getAccount(ConnectionProvider conn, FIN_FinancialAccount finAccount, AcctSchema as, boolean bIsReceipt) throws ServletException { - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); Account account = null; try { OBCriteria<FIN_FinancialAccountAccounting> accounts = OBDal.getInstance().createCriteria( @@ -282,7 +282,7 @@ else account = new Account(conn, accountList.get(0).getMakePaymentAccount().getId()); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return account; } diff --git a/src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java b/src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java --- a/src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java +++ b/src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java @@ -75,14 +75,14 @@ DateDoc = data[0].getField("statementDate"); C_DocType_ID = data[0].getField("C_Doctype_ID"); DocumentNo = data[0].getField("DocumentNo"); - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { FIN_Reconciliation reconciliation = OBDal.getInstance().get(FIN_Reconciliation.class, Record_ID); Amounts[0] = reconciliation.getEndingBalance().subtract(reconciliation.getStartingbalance()) .toString(); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } loadDocumentType(); p_lines = loadLines(); @@ -91,7 +91,7 @@ public FieldProviderFactory[] loadLinesFieldProvider(String Id) { FieldProviderFactory[] linesInfo = null; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { FIN_Reconciliation reconciliation = OBDal.getInstance().get(FIN_Reconciliation.class, Id); List<FIN_FinaccTransaction> transactions = getTransactionList(reconciliation); @@ -104,7 +104,7 @@ linesInfo = add(linesInfo, loadLinesGLItemFieldProvider(transaction)); } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return linesInfo; } @@ -127,7 +127,7 @@ } public List<FIN_FinaccTransaction> getTransactionList(FIN_Reconciliation reconciliation) { - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); List<FIN_FinaccTransaction> transactions = null; try { OBCriteria<FIN_FinaccTransaction> trans = OBDal.getInstance().createCriteria( @@ -137,7 +137,7 @@ trans.setFilterOnReadableOrganization(false); transactions = trans.list(); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return transactions; } @@ -148,7 +148,7 @@ transaction.getFinPayment().getId()); List<FIN_PaymentDetail> paymentDetails = payment.getFINPaymentDetailList(); FieldProviderFactory[] data = new FieldProviderFactory[paymentDetails.size()]; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { for (int i = 0; i < data.length; i++) { data[i] = new FieldProviderFactory(new HashMap()); @@ -194,14 +194,14 @@ FieldProviderFactory.setField(data[0], "lineno", transaction.getLineNo().toString()); } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return data; } public FieldProviderFactory[] loadLinesGLItemFieldProvider(FIN_FinaccTransaction transaction) { FieldProviderFactory[] data = new FieldProviderFactory[1]; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { data[0] = new FieldProviderFactory(new HashMap()); FieldProviderFactory.setField(data[0], "FIN_Reconciliation_ID", transaction @@ -229,7 +229,7 @@ .getId()); FieldProviderFactory.setField(data[0], "lineno", transaction.getLineNo().toString()); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return data; } @@ -239,7 +239,7 @@ FieldProviderFactory[] data = loadLinesFieldProvider(Record_ID); if (data == null || data.length == 0) return null; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { for (int i = 0; i < data.length; i++) { String Line_ID = data[i].getField("FIN_Finacc_Transaction_ID"); @@ -260,7 +260,7 @@ list.add(docLine); } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } // Return Array DocLine_FINReconciliation[] dl = new DocLine_FINReconciliation[list.size()]; @@ -274,7 +274,7 @@ String strClassname = ""; final StringBuilder whereClause = new StringBuilder(); Fact fact = new Fact(this, as, Fact.POST_Actual); - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { whereClause.append(" as astdt "); whereClause.append(" where astdt.acctschemaTable.accountingSchema.id = '" @@ -326,7 +326,7 @@ fact = createFactGLItem(line, as, conn, fact, Fact_Acct_Group_ID); } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return fact; } @@ -407,7 +407,7 @@ // Checks if this step (Make receive payment) is configured to generate accounting for the // selected financial account boolean confirmation = false; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { List<FIN_FinancialAccountAccounting> accounts = payment.getAccount() .getFINFinancialAccountAcctList(); @@ -417,7 +417,7 @@ confirmation = true; } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return confirmation; } @@ -427,7 +427,7 @@ // Checks if this step (deposit or withdrawal) is configured to generate accounting for the // selected financial account boolean confirmation = false; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { List<FIN_FinancialAccountAccounting> accounts = transaction.getAccount() .getFINFinancialAccountAcctList(); @@ -441,7 +441,7 @@ confirmation = true; } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } if (!confirmation) setStatus(STATUS_DocumentDisabled); @@ -452,7 +452,7 @@ // Checks if this step (Reconciliation) is configured to generate accounting for the selected // financial account boolean confirmation = false; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { FIN_Reconciliation reconciliation = OBDal.getInstance().get(FIN_Reconciliation.class, strRecordId); @@ -463,7 +463,7 @@ confirmation = true; } } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } if (!confirmation) setStatus(STATUS_DocumentDisabled); @@ -475,7 +475,7 @@ FIN_Reconciliation reconciliation = OBDal.getInstance().get(FIN_Reconciliation.class, Id); FieldProviderFactory[] data = new FieldProviderFactory[1]; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { data[0] = new FieldProviderFactory(new HashMap()); FieldProviderFactory.setField(data[0], "AD_Client_ID", reconciliation.getClient().getId()); @@ -496,14 +496,14 @@ FieldProviderFactory.setField(data[0], "Processing", reconciliation.isProcessNow() ? "Y" : "N"); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } setObjectFieldProvider(data); } public Account getAccountGLItem(GLItem glItem, AcctSchema as, boolean bIsReceipt, ConnectionProvider conn) throws ServletException { - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); Account account = null; try { OBCriteria<GLItemAccounts> accounts = OBDal.getInstance() @@ -524,7 +524,7 @@ else account = new Account(conn, accountList.get(0).getGlitemDebitAcct().getId()); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return account; } @@ -532,7 +532,7 @@ public Account getAccountFee(AcctSchema as, FIN_FinancialAccount finAccount, ConnectionProvider conn) throws ServletException { Account account = null; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { OBCriteria<FIN_FinancialAccountAccounting> accounts = OBDal.getInstance().createCriteria( FIN_FinancialAccountAccounting.class); @@ -548,7 +548,7 @@ return null; account = new Account(conn, accountList.get(0).getFINBankfeeAcct().getId()); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return account; } @@ -566,7 +566,7 @@ public Account getAccountTransaction(ConnectionProvider conn, FIN_FinancialAccount finAccount, AcctSchema as, boolean bIsReceipt) throws ServletException { Account account = null; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { OBCriteria<FIN_FinancialAccountAccounting> accounts = OBDal.getInstance().createCriteria( FIN_FinancialAccountAccounting.class); @@ -585,7 +585,7 @@ else account = new Account(conn, accountList.get(0).getWithdrawalAccount().getId()); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return account; } @@ -603,7 +603,7 @@ public Account getAccount(ConnectionProvider conn, FIN_FinancialAccount finAccount, AcctSchema as, boolean bIsReceipt) throws ServletException { Account account = null; - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { OBCriteria<FIN_FinancialAccountAccounting> accounts = OBDal.getInstance().createCriteria( FIN_FinancialAccountAccounting.class); @@ -622,14 +622,14 @@ else account = new Account(conn, accountList.get(0).getCreditAccount().getId()); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return account; } public Account getAccountPayment(ConnectionProvider conn, FIN_FinancialAccount finAccount, AcctSchema as, boolean bIsReceipt) throws ServletException { - boolean wasAdministrator = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); Account account = null; try { OBCriteria<FIN_FinancialAccountAccounting> accounts = OBDal.getInstance().createCriteria( @@ -649,7 +649,7 @@ else account = new Account(conn, accountList.get(0).getMakePaymentAccount().getId()); } finally { - OBContext.getOBContext().setInAdministratorMode(wasAdministrator); + OBContext.restorePreviousMode(); } return account; } diff --git a/src/org/openbravo/erpCommon/ad_forms/InitialOrgSetup.java b/src/org/openbravo/erpCommon/ad_forms/InitialOrgSetup.java --- a/src/org/openbravo/erpCommon/ad_forms/InitialOrgSetup.java +++ b/src/org/openbravo/erpCommon/ad_forms/InitialOrgSetup.java @@ -279,7 +279,7 @@ .append(SALTO_LINEA); m_info.append(SALTO_LINEA).append(Utility.messageBD(this, "StartingOrg", vars.getLanguage())) .append(SALTO_LINEA); - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { if (!createOrg(request, vars, strOrganization, strOrgType, strParentOrg, strOrgUser, strcLocationId)) { @@ -292,7 +292,7 @@ return m_info.toString(); } } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } } catch (final Exception err) { m_info.append(SALTO_LINEA).append( @@ -367,13 +367,13 @@ m_info.append(SALTO_LINEA).append( Utility.messageBD(this, "StartingReferenceData", vars.getLanguage())).append( SALTO_LINEA); - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); String strReferenceData = ""; try { strReferenceData = createReferenceData(vars, strOrganization, AD_Client_ID, strModules, bProduct, bBPartner, bProject, bCampaign, bSalesRegion, strCreateAccounting); } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } if (!strReferenceData.equals("")) { releaseRollbackConnection(conn); diff --git a/src/org/openbravo/erpCommon/ad_forms/Role.java b/src/org/openbravo/erpCommon/ad_forms/Role.java --- a/src/org/openbravo/erpCommon/ad_forms/Role.java +++ b/src/org/openbravo/erpCommon/ad_forms/Role.java @@ -188,7 +188,7 @@ xmlDocument.setData("structureLang", LanguageComboData.select(this)); // Role - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); RoleComboData[] datarole = null; try { // We check if there is a Openbravo Professional Subscription restriction in the license, @@ -210,7 +210,7 @@ datarole = RoleComboData.select(this, vars.getUser()); } } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } // Client diff --git a/src/org/openbravo/erpCommon/ad_process/ApplyModules.java b/src/org/openbravo/erpCommon/ad_process/ApplyModules.java --- a/src/org/openbravo/erpCommon/ad_process/ApplyModules.java +++ b/src/org/openbravo/erpCommon/ad_process/ApplyModules.java @@ -201,7 +201,7 @@ throws IOException, ServletException { User currentUser = OBContext.getOBContext().getUser(); vars.setSessionValue("ApplyModules|Last_Line_Number_Log", "-1"); - boolean admin = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); PreparedStatement ps = null; PreparedStatement ps2 = null; PreparedStatement ps3 = null; @@ -301,7 +301,7 @@ releasePreparedStatement(updateSession); } catch (SQLException e) { } - OBContext.getOBContext().setInAdministratorMode(admin); + OBContext.restorePreviousMode(); } } diff --git a/src/org/openbravo/erpCommon/ad_process/CreateCustomModule.java b/src/org/openbravo/erpCommon/ad_process/CreateCustomModule.java --- a/src/org/openbravo/erpCommon/ad_process/CreateCustomModule.java +++ b/src/org/openbravo/erpCommon/ad_process/CreateCustomModule.java @@ -43,7 +43,7 @@ @Override public void execute(ProcessBundle bundle) throws Exception { - boolean admin = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { OBCriteria<Module> modCriteria = OBDal.getInstance().createCriteria(Module.class); modCriteria.add(Expression.ilike(Module.PROPERTY_NAME, MODULE_NAME)); @@ -97,7 +97,7 @@ msg.setMessage("@Success@"); bundle.setResult(msg); } finally { - OBContext.getOBContext().setInAdministratorMode(admin); + OBContext.restorePreviousMode(); } } } diff --git a/src/org/openbravo/erpCommon/ad_process/PaymentMonitor.java b/src/org/openbravo/erpCommon/ad_process/PaymentMonitor.java --- a/src/org/openbravo/erpCommon/ad_process/PaymentMonitor.java +++ b/src/org/openbravo/erpCommon/ad_process/PaymentMonitor.java @@ -41,7 +41,7 @@ } catch (PropertyException e) { return; } - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { List<DebtPayment> payments = invoice.getFinancialMgmtDebtPaymentList(); BigDecimal paidAmount = BigDecimal.ZERO; @@ -76,7 +76,7 @@ OBDal.getInstance().save(invoice); OBDal.getInstance().flush(); } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } return; } diff --git a/src/org/openbravo/erpCommon/businessUtility/AuditTrailPopup.java b/src/org/openbravo/erpCommon/businessUtility/AuditTrailPopup.java --- a/src/org/openbravo/erpCommon/businessUtility/AuditTrailPopup.java +++ b/src/org/openbravo/erpCommon/businessUtility/AuditTrailPopup.java @@ -116,7 +116,7 @@ } // all code runs in adminMode to get read access to i.e. Tab,TabTrl,AD_Audit_Trail entities - boolean oldAdminMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { if (vars.commandIn("POPUP_HISTORY")) { @@ -223,7 +223,7 @@ pageError(response); } } finally { - OBContext.getOBContext().setInAdministratorMode(oldAdminMode); + OBContext.restorePreviousMode(); } } diff --git a/src/org/openbravo/erpCommon/info/AttributeSetInstance.java b/src/org/openbravo/erpCommon/info/AttributeSetInstance.java --- a/src/org/openbravo/erpCommon/info/AttributeSetInstance.java +++ b/src/org/openbravo/erpCommon/info/AttributeSetInstance.java @@ -98,14 +98,14 @@ if (log4j.isDebugEnabled()) log4j.debug("strNameValue: " + strNameValue); String strAttrSetValueType = ""; - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { final Product product = OBDal.getInstance().get(Product.class, strProduct); if (product != null) { strAttrSetValueType = product.getUseAttributeSetValueAs(); } } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } if (!strAttributeSet.equals("")) { if ("F".equals(strAttrSetValueType)) diff --git a/src/org/openbravo/erpCommon/info/ImageInfoBLOB.java b/src/org/openbravo/erpCommon/info/ImageInfoBLOB.java --- a/src/org/openbravo/erpCommon/info/ImageInfoBLOB.java +++ b/src/org/openbravo/erpCommon/info/ImageInfoBLOB.java @@ -74,7 +74,7 @@ String parentObjectId = vars.getStringParameter("parentObjectId"); if (parentObjectId == null || parentObjectId.equals("")) { - boolean adminMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { Table table = OBDal.getInstance().get(Table.class, vars.getStringParameter("inpTableId")); if (table != null) { @@ -93,7 +93,7 @@ parentObjectId = vars.getStringParameter("inp" + Sqlc.TransformaNombreColumna(keyCol)); } } finally { - OBContext.getOBContext().setInAdministratorMode(adminMode); + OBContext.restorePreviousMode(); } } @@ -101,7 +101,7 @@ printPageFrame(response, vars, imageID, tableId, columnName, parentObjectId, orgId); } else if (vars.commandIn("SAVE")) { - boolean adminMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { final FileItem fi = vars.getMultiFile("inpFile"); byte[] bytea = fi.get(); @@ -128,11 +128,11 @@ PrintWriter writer = response.getWriter(); writeRedirect(writer, image.getId(), columnName); } finally { - OBContext.getOBContext().setInAdministratorMode(adminMode); + OBContext.restorePreviousMode(); } } else if (vars.commandIn("DELETE")) { if (imageID != null && !imageID.equals("")) { - boolean adminMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { Image image = OBDal.getInstance().get(Image.class, imageID); Table table = OBDal.getInstance().get(Table.class, tableId); @@ -152,7 +152,7 @@ log4j.error("Class for table not found", e); } } finally { - OBContext.getOBContext().setInAdministratorMode(adminMode); + OBContext.restorePreviousMode(); } response.setContentType("text/html; charset=UTF-8"); PrintWriter writer = response.getWriter(); diff --git a/src/org/openbravo/erpCommon/modules/ModuleUtiltiy.java b/src/org/openbravo/erpCommon/modules/ModuleUtiltiy.java --- a/src/org/openbravo/erpCommon/modules/ModuleUtiltiy.java +++ b/src/org/openbravo/erpCommon/modules/ModuleUtiltiy.java @@ -91,8 +91,7 @@ * @throws Exception */ public static void orderModuleByDependency(FieldProvider[] modules) throws Exception { - boolean adminMode = OBContext.getOBContext().isInAdministratorMode(); - OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { List<Module> allModules = OBDal.getInstance().createCriteria(Module.class).list(); ArrayList<String> allMdoulesId = new ArrayList<String>(); @@ -116,7 +115,7 @@ modules[j] = fpModulesOrder[j]; } } finally { - OBContext.getOBContext().setInAdministratorMode(adminMode); + OBContext.restorePreviousMode(); } } diff --git a/src/org/openbravo/erpCommon/obps/ActivationKey.java b/src/org/openbravo/erpCommon/obps/ActivationKey.java --- a/src/org/openbravo/erpCommon/obps/ActivationKey.java +++ b/src/org/openbravo/erpCommon/obps/ActivationKey.java @@ -352,7 +352,7 @@ // maxUsers==0 is unlimited concurrent users if (maxUsers != 0) { - boolean adminMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); int activeSessions = 0; try { activeSessions = getActiveSessions(currentSession); @@ -368,7 +368,7 @@ } catch (Exception e) { log4j.error("Error checking sessions", e); } finally { - OBContext.getOBContext().setInAdministratorMode(adminMode); + OBContext.restorePreviousMode(); } if (activeSessions >= maxUsers) { return LicenseRestriction.NUMBER_OF_CONCURRENT_USERS_REACHED; diff --git a/src/org/openbravo/erpCommon/obps/CheckCleanCache.java b/src/org/openbravo/erpCommon/obps/CheckCleanCache.java --- a/src/org/openbravo/erpCommon/obps/CheckCleanCache.java +++ b/src/org/openbravo/erpCommon/obps/CheckCleanCache.java @@ -62,13 +62,13 @@ // get instance active status from db boolean active = false; - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); try { ActivationKey ak = new ActivationKey(); active = ak.isActive(); log4j.debug("Instance activate: " + active); } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } PrintWriter pw = response.getWriter(); diff --git a/src/org/openbravo/erpCommon/obps/GetOpenbravoLogo.java b/src/org/openbravo/erpCommon/obps/GetOpenbravoLogo.java --- a/src/org/openbravo/erpCommon/obps/GetOpenbravoLogo.java +++ b/src/org/openbravo/erpCommon/obps/GetOpenbravoLogo.java @@ -47,13 +47,13 @@ // get instance active status from db boolean active = false; - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); try { ActivationKey ak = new ActivationKey(); active = ak.isActive(); log4j.debug("GetOpsLogo: activated: " + active); } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } String activeLogo; diff --git a/src/org/openbravo/erpCommon/security/Login.java b/src/org/openbravo/erpCommon/security/Login.java --- a/src/org/openbravo/erpCommon/security/Login.java +++ b/src/org/openbravo/erpCommon/security/Login.java @@ -45,19 +45,20 @@ String strTheme = vars.getTheme(); vars.clearSession(false); - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); + try { + Client systemClient = OBDal.getInstance().get(Client.class, "0"); + String cacheMsg = Utility.messageBD(this, "OUTDATED_FILES_CACHED", systemClient + .getLanguage().getLanguage()); + String browserMsg = Utility.messageBD(this, "BROWSER_NOT_SUPPORTED", systemClient + .getLanguage().getLanguage()); + String orHigherMsg = Utility.messageBD(this, "OR_HIGHER_TEXT", systemClient.getLanguage() + .getLanguage()); - Client systemClient = OBDal.getInstance().get(Client.class, "0"); - String cacheMsg = Utility.messageBD(this, "OUTDATED_FILES_CACHED", systemClient.getLanguage() - .getLanguage()); - String browserMsg = Utility.messageBD(this, "BROWSER_NOT_SUPPORTED", systemClient - .getLanguage().getLanguage()); - String orHigherMsg = Utility.messageBD(this, "OR_HIGHER_TEXT", systemClient.getLanguage() - .getLanguage()); - - OBContext.resetAsAdminContext(); - - printPageIdentificacion(response, strTheme, cacheMsg, browserMsg, orHigherMsg); + printPageIdentificacion(response, strTheme, cacheMsg, browserMsg, orHigherMsg); + } finally { + OBContext.restorePreviousMode(); + } } else if (vars.commandIn("BLANK")) { printPageBlank(response, vars); diff --git a/src/org/openbravo/erpCommon/security/Menu.java b/src/org/openbravo/erpCommon/security/Menu.java --- a/src/org/openbravo/erpCommon/security/Menu.java +++ b/src/org/openbravo/erpCommon/security/Menu.java @@ -149,7 +149,7 @@ try { // Trying to deep-link using tabId - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); final String tabId = vars.getStringParameter("tabId", IsIDFilter.instance); String windowId = vars.getStringParameter("windowId", IsIDFilter.instance); @@ -231,7 +231,7 @@ log4j.error("Error in deep-linking: " + e.getMessage(), e); throw new ServletException(e.getMessage()); } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } return targetmenu; diff --git a/src/org/openbravo/erpCommon/security/SessionLogin.java b/src/org/openbravo/erpCommon/security/SessionLogin.java --- a/src/org/openbravo/erpCommon/security/SessionLogin.java +++ b/src/org/openbravo/erpCommon/security/SessionLogin.java @@ -113,7 +113,7 @@ setSessionID(key); } try { - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); Session session = OBProvider.getInstance().get(Session.class); session.setCreationDate(new Date()); @@ -142,7 +142,7 @@ log4j.error("Error saving session in DB", e); return 0; } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } } @@ -155,7 +155,7 @@ public void update(ConnectionProvider conn) throws ServletException { try { - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); Session session = OBDal.getInstance().get(Session.class, getSessionID()); session.setActive(getIsActive()); User user1 = OBDal.getInstance().get(User.class, getUser()); @@ -168,7 +168,7 @@ } catch (Exception e) { log4j.error("Error updating session in DB", e); } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } } diff --git a/src/org/openbravo/erpCommon/utility/ImageToDatabaseLoader.java b/src/org/openbravo/erpCommon/utility/ImageToDatabaseLoader.java --- a/src/org/openbravo/erpCommon/utility/ImageToDatabaseLoader.java +++ b/src/org/openbravo/erpCommon/utility/ImageToDatabaseLoader.java @@ -25,7 +25,7 @@ @Override public void doExecute() { - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); try { String paths[] = imagePaths.split(","); String properties[] = propertyNames.split(","); @@ -60,7 +60,7 @@ } catch (Exception e) { getLog().error(e); } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } } diff --git a/src/org/openbravo/erpCommon/utility/ShowImage.java b/src/org/openbravo/erpCommon/utility/ShowImage.java --- a/src/org/openbravo/erpCommon/utility/ShowImage.java +++ b/src/org/openbravo/erpCommon/utility/ShowImage.java @@ -47,7 +47,7 @@ */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - boolean adminMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { VariablesSecureApp vars = new VariablesSecureApp(request); String id = vars.getStringParameter("id"); @@ -81,7 +81,7 @@ response.getOutputStream().close(); } } finally { - OBContext.getOBContext().setInAdministratorMode(adminMode); + OBContext.restorePreviousMode(); } } } diff --git a/src/org/openbravo/erpCommon/utility/ShowImageLogo.java b/src/org/openbravo/erpCommon/utility/ShowImageLogo.java --- a/src/org/openbravo/erpCommon/utility/ShowImageLogo.java +++ b/src/org/openbravo/erpCommon/utility/ShowImageLogo.java @@ -55,7 +55,7 @@ if (logo == null || logo.equals("")) return; - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); try { Image img = null; if (logo.equals("yourcompanylogin")) { @@ -114,7 +114,7 @@ } } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } } } diff --git a/src/org/openbravo/erpCommon/utility/ToolBar.java b/src/org/openbravo/erpCommon/utility/ToolBar.java --- a/src/org/openbravo/erpCommon/utility/ToolBar.java +++ b/src/org/openbravo/erpCommon/utility/ToolBar.java @@ -369,7 +369,7 @@ return; } if (tabId != null) { - boolean oldAdminMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { // ActivationKey already initialized in i.e. HSAS, so just take static info if (ActivationKey.isActiveInstance()) { @@ -381,7 +381,7 @@ } } } finally { - OBContext.getOBContext().setInAdministratorMode(oldAdminMode); + OBContext.restorePreviousMode(); } } } diff --git a/src/org/openbravo/erpCommon/utility/UsedByLink.java b/src/org/openbravo/erpCommon/utility/UsedByLink.java --- a/src/org/openbravo/erpCommon/utility/UsedByLink.java +++ b/src/org/openbravo/erpCommon/utility/UsedByLink.java @@ -380,8 +380,7 @@ * */ private List<LinkedTable> getLinkedTables(String tableId) { - boolean adminMode = OBContext.getOBContext().isInAdministratorMode(); - OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { Table table = OBDal.getInstance().get(Table.class, tableId); String tableName = table.getDBTableName(); @@ -402,7 +401,7 @@ } return linkedTables; } finally { - OBContext.getOBContext().setInAdministratorMode(adminMode); + OBContext.restorePreviousMode(); } } diff --git a/src/org/openbravo/erpCommon/utility/Utility.java b/src/org/openbravo/erpCommon/utility/Utility.java --- a/src/org/openbravo/erpCommon/utility/Utility.java +++ b/src/org/openbravo/erpCommon/utility/Utility.java @@ -466,7 +466,7 @@ return "'0'"; // force to be org * Window window; - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { window = org.openbravo.dal.service.OBDal.getInstance().get(Window.class, strWindow); if (window.getWindowType().equals("T")) { @@ -502,7 +502,7 @@ } } } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } } diff --git a/src/org/openbravo/erpCommon/utility/VerticalMenu.java b/src/org/openbravo/erpCommon/utility/VerticalMenu.java --- a/src/org/openbravo/erpCommon/utility/VerticalMenu.java +++ b/src/org/openbravo/erpCommon/utility/VerticalMenu.java @@ -81,7 +81,7 @@ Date now = new Date(); log4j.debug("ping session:" + sessionId + " - time" + now); if (sessionId != null && !sessionId.isEmpty()) { - boolean adminMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { Session session = OBDal.getInstance().get(Session.class, sessionId); session.setLastPing(now); @@ -90,7 +90,7 @@ } catch (Exception e) { log4j.error("Error in session ping", e); } finally { - OBContext.getOBContext().setInAdministratorMode(adminMode); + OBContext.restorePreviousMode(); } } } diff --git a/src/org/openbravo/reference/Reference.java b/src/org/openbravo/reference/Reference.java --- a/src/org/openbravo/reference/Reference.java +++ b/src/org/openbravo/reference/Reference.java @@ -33,8 +33,7 @@ String implemenationClass; org.openbravo.model.ad.domain.Reference ref = null; - boolean adminMode = OBContext.getOBContext().isInAdministratorMode(); - OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { if (subreferenceID != null && !subreferenceID.equals("")) { ref = OBDal.getInstance() @@ -72,7 +71,7 @@ return new UIReference(referenceId, subreferenceID); } } finally { - OBContext.getOBContext().setInAdministratorMode(adminMode); + OBContext.restorePreviousMode(); } } } diff --git a/src/org/openbravo/reference/ui/UIList.java b/src/org/openbravo/reference/ui/UIList.java --- a/src/org/openbravo/reference/ui/UIList.java +++ b/src/org/openbravo/reference/ui/UIList.java @@ -52,7 +52,7 @@ // Check whether value must boolean showValue = false; - boolean adminMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { org.openbravo.model.ad.domain.Reference ref = OBDal.getInstance().get( org.openbravo.model.ad.domain.Reference.class, subReference); @@ -60,7 +60,7 @@ showValue = ref.isDisplayedValue(); } } finally { - OBContext.getOBContext().setInAdministratorMode(adminMode); + OBContext.restorePreviousMode(); } String fieldName = field.getProperty("ColumnName"); diff --git a/src/org/openbravo/service/dataset/DataSetService.java b/src/org/openbravo/service/dataset/DataSetService.java --- a/src/org/openbravo/service/dataset/DataSetService.java +++ b/src/org/openbravo/service/dataset/DataSetService.java @@ -248,50 +248,55 @@ // do the part which can be done as super user separately from the // actual read of the db - OBContext.getOBContext().setInAdministratorMode(true); - final String entityName = dataSetTable.getTable().getName(); - final Entity entity = ModelProvider.getInstance().getEntity(entityName); + OBContext.setAdminMode(); + try { + final String entityName = dataSetTable.getTable().getName(); + final Entity entity = ModelProvider.getInstance().getEntity(entityName); - if (entity == null) { - log.error("Entity not found using table name " + entityName); - return new ArrayList<BaseOBObject>(); - } + if (entity == null) { + log.error("Entity not found using table name " + entityName); + return new ArrayList<BaseOBObject>(); + } - String whereClause = dataSetTable.getSQLWhereClause(); + String whereClause = dataSetTable.getSQLWhereClause(); - final Map<String, Object> existingParams = new HashMap<String, Object>(); - if (whereClause != null) { - if (parameters != null) { - for (final String name : parameters.keySet()) { - if (whereClause.indexOf(":" + name) != -1) { - existingParams.put(name, parameters.get(name)); + final Map<String, Object> existingParams = new HashMap<String, Object>(); + if (whereClause != null) { + if (parameters != null) { + for (final String name : parameters.keySet()) { + if (whereClause.indexOf(":" + name) != -1) { + existingParams.put(name, parameters.get(name)); + } } } } + + if (moduleId != null && whereClause != null) { + while (whereClause.indexOf("@moduleid@") != -1) { + whereClause = whereClause.replace("@moduleid@", "'" + moduleId + "'"); + } + if (whereClause.indexOf(":moduleid") != -1 && parameters.get("moduleid") == null) { + existingParams.put("moduleid", moduleId); + } + } + + final OBQuery<BaseOBObject> oq = OBDal.getInstance().createQuery(entity.getName(), + whereClause); + oq.setFilterOnActive(false); + oq.setNamedParameters(existingParams); + + if (OBContext.getOBContext().getRole().getId().equals("0") + && OBContext.getOBContext().getCurrentClient().getId().equals("0")) { + oq.setFilterOnReadableOrganization(false); + oq.setFilterOnReadableClients(false); + } + + final List<?> list = oq.list(); + Collections.sort(list, new BaseOBIDHexComparator()); + return (List<BaseOBObject>) list; + } finally { + OBContext.restorePreviousMode(); } - - if (moduleId != null && whereClause != null) { - while (whereClause.indexOf("@moduleid@") != -1) { - whereClause = whereClause.replace("@moduleid@", "'" + moduleId + "'"); - } - if (whereClause.indexOf(":moduleid") != -1 && parameters.get("moduleid") == null) { - existingParams.put("moduleid", moduleId); - } - } - - final OBQuery<BaseOBObject> oq = OBDal.getInstance().createQuery(entity.getName(), whereClause); - oq.setFilterOnActive(false); - oq.setNamedParameters(existingParams); - - if (OBContext.getOBContext().getRole().getId().equals("0") - && OBContext.getOBContext().getCurrentClient().getId().equals("0")) { - oq.setFilterOnReadableOrganization(false); - oq.setFilterOnReadableClients(false); - } - - final List<?> list = oq.list(); - Collections.sort(list, new BaseOBIDHexComparator()); - return (List<BaseOBObject>) list; } /** diff --git a/src/org/openbravo/service/db/CallProcess.java b/src/org/openbravo/service/db/CallProcess.java --- a/src/org/openbravo/service/db/CallProcess.java +++ b/src/org/openbravo/service/db/CallProcess.java @@ -102,7 +102,7 @@ public ProcessInstance call(org.openbravo.model.ad.ui.Process process, String recordID, Map<String, String> parameters) { - final boolean currentAdminMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { // Create the pInstance final ProcessInstance pInstance = OBProvider.getInstance().get(ProcessInstance.class); @@ -167,7 +167,7 @@ OBDal.getInstance().getSession().refresh(pInstance); return pInstance; } finally { - OBContext.getOBContext().setInAdministratorMode(currentAdminMode); + OBContext.restorePreviousMode(); } } } diff --git a/src/org/openbravo/service/db/DataExportService.java b/src/org/openbravo/service/db/DataExportService.java --- a/src/org/openbravo/service/db/DataExportService.java +++ b/src/org/openbravo/service/db/DataExportService.java @@ -117,7 +117,7 @@ */ public void exportClientToXML(Map<String, Object> parameters, boolean exportAuditInfo, Writer out) { DataSet dataSet = null; - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { final OBCriteria<DataSet> obc = OBDal.getInstance().createCriteria(DataSet.class); obc.add(Expression.eq("name", CLIENT_DATA_SET_NAME)); @@ -158,7 +158,7 @@ } } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } } diff --git a/src/org/openbravo/service/db/DataImportService.java b/src/org/openbravo/service/db/DataImportService.java --- a/src/org/openbravo/service/db/DataImportService.java +++ b/src/org/openbravo/service/db/DataImportService.java @@ -152,7 +152,7 @@ final ImportResult ir = new ImportResult(); boolean rolledBack = false; - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { // disable the triggers to prevent unexpected extra db actions // during import @@ -255,7 +255,7 @@ log.error(realThrowable.getMessage(), realThrowable); ir.setException(realThrowable); } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); if (rolledBack) { TriggerHandler.getInstance().clear(); } else if (TriggerHandler.getInstance().isDisabled()) { @@ -547,7 +547,7 @@ // store the ad_ref_data_loaded if (!isClientImport) { - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { for (final BaseOBObject ins : xec.getToInsert()) { final String originalId = xec.getEntityResolver().getOriginalId(ins); @@ -572,7 +572,7 @@ } OBDal.getInstance().flush(); } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } } } diff --git a/src/org/openbravo/service/system/SystemService.java b/src/org/openbravo/service/system/SystemService.java --- a/src/org/openbravo/service/system/SystemService.java +++ b/src/org/openbravo/service/system/SystemService.java @@ -178,7 +178,7 @@ // currently this does not work yet because step 1 fails because there are constraints // defined in the database which means that certain fields are conditionally mandatory. - final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true); + OBContext.setAdminMode(); try { TriggerHandler.getInstance().disable(); final Client client = OBDal.getInstance().get(Client.class, clientId); @@ -207,7 +207,7 @@ TriggerHandler.getInstance().enable(); OBDal.getInstance().commitAndClose(); } finally { - OBContext.getOBContext().setInAdministratorMode(prevMode); + OBContext.restorePreviousMode(); } } diff --git a/src/org/openbravo/service/web/UserContextCache.java b/src/org/openbravo/service/web/UserContextCache.java --- a/src/org/openbravo/service/web/UserContextCache.java +++ b/src/org/openbravo/service/web/UserContextCache.java @@ -110,13 +110,13 @@ public boolean hasExpired() { try { - OBContext.enableAsAdminContext(); + OBContext.setAdminMode(); final User user = OBDal.getInstance().get(User.class, userId); if (user == null || user.getUpdated().getTime() > lastUpdated) { return true; } } finally { - OBContext.resetAsAdminContext(); + OBContext.restorePreviousMode(); } return getLastUsed() < (System.currentTimeMillis() - EXPIRES_IN); } | |||||||
![]() |
|
![]() |
|
(0025626) hgbot (developer) 2010-03-19 19:37 |
Repository: erp/devel/pi Changeset: 9fb31e4618ba3b4893f68d0920e28e580207a1a8 Author: Martin Taal <martin.taal <at> openbravo.com> Date: Fri Mar 19 19:45:23 2010 +0100 URL: http://code.openbravo.com/erp/devel/pi/rev/9fb31e4618ba3b4893f68d0920e28e580207a1a8 [^] Removed test for issue 12594, unintentionally committed --- M src-test/org/openbravo/test/dal/IssuesTest.java --- |
(0026358) hudsonbot (viewer) 2010-04-19 21:10 |
A changeset related to this issue has been promoted to main after passing a series of tests and an OBX has been generated: Changeset: http://code.openbravo.com/erp/devel/main/rev/9fb31e4618ba [^] Merge Changeset: http://code.openbravo.com/erp/devel/main/rev/91d98bda46c1 [^] Tests: http://builds.openbravo.com/view/devel-int/ [^] OBX: http://builds.openbravo.com/erp/core/obx/OpenbravoERP-2.50CI.17088.obx [^] |
(0026957) hgbot (developer) 2010-05-05 14:18 |
Repository: erp/devel/pi Changeset: 57390029073861fd9eef7115fa83812d18d6cc09 Author: Martin Taal <martin.taal <at> openbravo.com> Date: Wed May 05 14:18:16 2010 +0200 URL: http://code.openbravo.com/erp/devel/pi/rev/57390029073861fd9eef7115fa83812d18d6cc09 [^] fixes issue 12594: Make setting of administrator mode less vulnerable for wrong usage fixes issue 12660: OBContext enableAsAdminContext - resetAsAdminContext should use an stack --- M src-test/org/openbravo/test/base/BaseTest.java M src-test/org/openbravo/test/dal/OBContextTest.java M src-test/org/openbravo/test/model/UtilsTest.java M src-test/org/openbravo/test/xml/EntityXMLImportTestBusinessObject.java M src-test/org/openbravo/test/xml/EntityXMLImportTestReference.java M src/org/openbravo/base/secureApp/HttpSecureAppServlet.java M src/org/openbravo/base/secureApp/LoginHandler.java M src/org/openbravo/base/secureApp/LoginUtils.java M src/org/openbravo/base/secureApp/UserLock.java M src/org/openbravo/base/secureApp/VariablesSecureApp.java M src/org/openbravo/dal/core/DalInitializingTask.java M src/org/openbravo/dal/core/DalRequestFilter.java M src/org/openbravo/dal/core/OBContext.java M src/org/openbravo/dal/core/TriggerHandler.java M src/org/openbravo/dal/security/EntityAccessChecker.java M src/org/openbravo/dal/xml/EntityResolver.java M src/org/openbravo/dal/xml/EntityXMLConverter.java M src/org/openbravo/erpCommon/ad_callouts/SL_GlobalUse_Product.java M src/org/openbravo/erpCommon/ad_callouts/SL_InOutLine_Product.java M src/org/openbravo/erpCommon/ad_callouts/SL_Internal_Consumption_Product.java M src/org/openbravo/erpCommon/ad_callouts/SL_Inventory_Product.java M src/org/openbravo/erpCommon/ad_callouts/SL_Movement_Product.java M src/org/openbravo/erpCommon/ad_callouts/SL_PC_Case_Product.java M src/org/openbravo/erpCommon/ad_callouts/SL_Production_Product.java M src/org/openbravo/erpCommon/ad_callouts/SL_RequisitionLine_Product.java M src/org/openbravo/erpCommon/ad_forms/About.java M src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java M src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java M src/org/openbravo/erpCommon/ad_forms/DocFINReconciliation.java M src/org/openbravo/erpCommon/ad_forms/InitialOrgSetup.java M src/org/openbravo/erpCommon/ad_forms/Role.java M src/org/openbravo/erpCommon/ad_process/ApplyModules.java M src/org/openbravo/erpCommon/ad_process/CreateCustomModule.java M src/org/openbravo/erpCommon/ad_process/PaymentMonitor.java M src/org/openbravo/erpCommon/businessUtility/AuditTrailPopup.java M src/org/openbravo/erpCommon/info/AttributeSetInstance.java M src/org/openbravo/erpCommon/info/ImageInfoBLOB.java M src/org/openbravo/erpCommon/modules/ModuleUtiltiy.java M src/org/openbravo/erpCommon/obps/ActivationKey.java M src/org/openbravo/erpCommon/obps/CheckCleanCache.java M src/org/openbravo/erpCommon/obps/GetOpenbravoLogo.java M src/org/openbravo/erpCommon/security/Login.java M src/org/openbravo/erpCommon/security/Menu.java M src/org/openbravo/erpCommon/security/SessionLogin.java M src/org/openbravo/erpCommon/utility/ImageToDatabaseLoader.java M src/org/openbravo/erpCommon/utility/ShowImage.java M src/org/openbravo/erpCommon/utility/ShowImageLogo.java M src/org/openbravo/erpCommon/utility/ToolBar.java M src/org/openbravo/erpCommon/utility/UsedByLink.java M src/org/openbravo/erpCommon/utility/Utility.java M src/org/openbravo/erpCommon/utility/VerticalMenu.java M src/org/openbravo/reference/Reference.java M src/org/openbravo/reference/ui/UIList.java M src/org/openbravo/service/dataset/DataSetService.java M src/org/openbravo/service/db/CallProcess.java M src/org/openbravo/service/db/DataExportService.java M src/org/openbravo/service/db/DataImportService.java M src/org/openbravo/service/system/SystemService.java M src/org/openbravo/service/web/UserContextCache.java --- |
(0027420) shuehner (administrator) 2010-05-18 13:34 |
Tested in pi/pg working fine. New/consistent api is introduced for enabling/disabling admin mode. All older api's for the same are deprecated. All core callers are already updated to use the new api. The deprecation warnings which will be shown by using non-updated code (in i.e. modules) will be hidden by default in the rebuild-popup but shown in the console and eclipse builds. |
(0027481) hudsonbot (viewer) 2010-05-18 21:43 |
A changeset related to this issue has been promoted to main after passing a series of tests and an OBX has been generated: Changeset: http://code.openbravo.com/erp/devel/main/rev/573900290738 [^] Merge Changeset: http://code.openbravo.com/erp/devel/main/rev/aa11838d5f80 [^] Tests: http://builds.openbravo.com/view/devel-int/ [^] OBX: http://builds.openbravo.com/erp/core/obx/OpenbravoERP-2.50CI.17380.obx [^] |
![]() |
|||
Date Modified | Username | Field | Change |
2010-03-08 13:30 | mtaal | New Issue | |
2010-03-08 13:30 | mtaal | Assigned To | => mtaal |
2010-03-08 13:30 | mtaal | OBNetwork customer | => No |
2010-03-08 14:29 | shuehner | Issue Monitored: shuehner | |
2010-03-08 15:35 | alostale | Status | new => scheduled |
2010-03-08 15:35 | alostale | fix_in_branch | => pi |
2010-03-19 19:37 | hgbot | Checkin | |
2010-03-19 19:37 | hgbot | Note Added: 0025626 | |
2010-04-19 21:10 | hudsonbot | Checkin | |
2010-04-19 21:10 | hudsonbot | Note Added: 0026358 | |
2010-05-03 10:13 | mtaal | File Added: adminmode.patch | |
2010-05-03 17:44 | mtaal | File Deleted: adminmode.patch | |
2010-05-03 17:44 | mtaal | File Added: adminmode2.patch | |
2010-05-03 21:58 | mtaal | File Deleted: adminmode2.patch | |
2010-05-03 21:58 | mtaal | File Added: adminmode3.patch | |
2010-05-05 14:18 | hgbot | Checkin | |
2010-05-05 14:18 | hgbot | Note Added: 0026957 | |
2010-05-05 14:18 | hgbot | Status | scheduled => resolved |
2010-05-05 14:18 | hgbot | Resolution | open => fixed |
2010-05-05 14:18 | hgbot | Fixed in SCM revision | => http://code.openbravo.com/erp/devel/pi/rev/57390029073861fd9eef7115fa83812d18d6cc09 [^] |
2010-05-18 13:34 | shuehner | Note Added: 0027420 | |
2010-05-18 13:34 | shuehner | Status | resolved => closed |
2010-05-18 21:43 | hudsonbot | Checkin | |
2010-05-18 21:43 | hudsonbot | Note Added: 0027481 | |
2010-05-19 00:00 | anonymous | sf_bug_id | 0 => 3003669 |
Copyright © 2000 - 2009 MantisBT Group |