Search in sources :

Example 1 with SecurityConfigurationException

use of org.apache.ofbiz.security.SecurityConfigurationException in project ofbiz-framework by apache.

the class LoginWorker method setWebContextObjects.

protected 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 servletContext, only in the request and session
    // We also need to setup the security objects since they are dependent on the delegator
    Security security = null;
    try {
        security = SecurityFactory.getInstance(delegator);
    } catch (SecurityConfigurationException e) {
        Debug.logError(e, module);
    }
    request.setAttribute("delegator", delegator);
    request.setAttribute("dispatcher", dispatcher);
    request.setAttribute("security", security);
    session.setAttribute("delegatorName", delegator.getDelegatorName());
    session.setAttribute("delegator", delegator);
    session.setAttribute("dispatcher", dispatcher);
    session.setAttribute("security", security);
    // 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");
    VisitHandler.getVisitor(request, response);
    VisitHandler.getVisit(session);
}
Also used : SecurityConfigurationException(org.apache.ofbiz.security.SecurityConfigurationException) HttpSession(javax.servlet.http.HttpSession) Security(org.apache.ofbiz.security.Security)

Example 2 with SecurityConfigurationException

use of org.apache.ofbiz.security.SecurityConfigurationException in project ofbiz-framework by apache.

the class WebAppUtil method getSecurity.

public static Security getSecurity(ServletContext servletContext) {
    Security security = (Security) servletContext.getAttribute("security");
    if (security == null) {
        Delegator delegator = (Delegator) servletContext.getAttribute("delegator");
        if (delegator != null) {
            try {
                security = SecurityFactory.getInstance(delegator);
            } catch (SecurityConfigurationException e) {
                Debug.logError(e, "Unable to obtain an instance of the security object.", module);
            }
        }
        servletContext.setAttribute("security", security);
        if (security == null) {
            Debug.logError("An invalid (null) Security object has been set in the servlet context.", module);
        }
    }
    return security;
}
Also used : Delegator(org.apache.ofbiz.entity.Delegator) SecurityConfigurationException(org.apache.ofbiz.security.SecurityConfigurationException) Security(org.apache.ofbiz.security.Security)

Example 3 with SecurityConfigurationException

use of org.apache.ofbiz.security.SecurityConfigurationException in project ofbiz-framework by apache.

the class SimpleMethodTest method run.

@Override
public void run(TestResult result) {
    result.startTest(this);
    try {
        // define request
        Security security = SecurityFactory.getInstance(delegator);
        MockServletContext servletContext = new MockServletContext();
        request.setAttribute("security", security);
        request.setAttribute("servletContext", servletContext);
        request.setAttribute("delegator", delegator);
        request.setAttribute("dispatcher", dispatcher);
        Map<String, Object> serviceResult = SimpleMethod.runSimpleService(methodLocation, methodName, dispatcher.getDispatchContext(), UtilMisc.toMap("test", this, "testResult", result, "locale", Locale.getDefault(), "request", request, "response", response));
        // do something with the errorMessage
        String errorMessage = (String) serviceResult.get(ModelService.ERROR_MESSAGE);
        if (UtilValidate.isNotEmpty(errorMessage)) {
            result.addFailure(this, new AssertionFailedError(errorMessage));
        }
        // do something with the errorMessageList
        List<Object> errorMessageList = UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_LIST));
        if (UtilValidate.isNotEmpty(errorMessageList)) {
            for (Object message : errorMessageList) {
                result.addFailure(this, new AssertionFailedError(message.toString()));
            }
        }
        // do something with the errorMessageMap
        Map<String, Object> errorMessageMap = UtilGenerics.cast(serviceResult.get(ModelService.ERROR_MESSAGE_MAP));
        if (!UtilValidate.isEmpty(errorMessageMap)) {
            for (Map.Entry<String, Object> entry : errorMessageMap.entrySet()) {
                result.addFailure(this, new AssertionFailedError(entry.getKey() + ": " + entry.getValue()));
            }
        }
    } catch (MiniLangException e) {
        result.addError(this, e);
    } catch (SecurityConfigurationException e) {
        result.addError(this, e);
    }
    result.endTest(this);
}
Also used : SecurityConfigurationException(org.apache.ofbiz.security.SecurityConfigurationException) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) Security(org.apache.ofbiz.security.Security) AssertionFailedError(junit.framework.AssertionFailedError) Map(java.util.Map) MockServletContext(org.springframework.mock.web.MockServletContext)

Aggregations

Security (org.apache.ofbiz.security.Security)3 SecurityConfigurationException (org.apache.ofbiz.security.SecurityConfigurationException)3 Map (java.util.Map)1 HttpSession (javax.servlet.http.HttpSession)1 AssertionFailedError (junit.framework.AssertionFailedError)1 Delegator (org.apache.ofbiz.entity.Delegator)1 MiniLangException (org.apache.ofbiz.minilang.MiniLangException)1 MockServletContext (org.springframework.mock.web.MockServletContext)1