Search in sources :

Example 21 with ActivityContext

use of org.mifos.security.util.ActivityContext in project head by mifos.

the class FlowManagerHelperStrutsTest method setUp.

@Before
public void setUp() throws Exception {
    UserContext userContext = TestUtils.makeUserWithLocales();
    request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
    addRequestParameter("recordLoanOfficerId", "1");
    addRequestParameter("recordOfficeId", "1");
    ActivityContext ac = new ActivityContext((short) 0, userContext.getBranchId().shortValue(), userContext.getId().shortValue());
    request.getSession(false).setAttribute("ActivityContext", ac);
    flowKey = createFlow(request, FlowManagerHelperStrutsTest.class);
    addRequestParameter(Constants.CURRENTFLOWKEY, flowKey);
    request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
    flowManagerHelper = new FlowManagerHelper();
    SessionUtils.setAttribute("test", "test", request);
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) UserContext(org.mifos.security.util.UserContext) Before(org.junit.Before)

Example 22 with ActivityContext

use of org.mifos.security.util.ActivityContext in project head by mifos.

the class TestObjectFactory method getActivityContext.

public static ActivityContext getActivityContext() {
    if (activityContext == null) {
        UserContext uc = getContext();
        activityContext = new ActivityContext((short) 0, uc.getBranchId().shortValue(), uc.getId().shortValue());
    }
    return activityContext;
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) UserContext(org.mifos.security.util.UserContext)

Example 23 with ActivityContext

use of org.mifos.security.util.ActivityContext in project head by mifos.

the class MifosLegacyUsernamePasswordAuthenticationFilter method handleLegacySuccessfulAuthentication.

private void handleLegacySuccessfulAuthentication(HttpServletRequest request, HttpServletResponse response, final String username, final String password) {
    try {
        FlowManager flowManager = new FlowManager();
        String flowKey = String.valueOf(new DateTimeService().getCurrentDateTime().getMillis());
        flowManager.addFLow(flowKey, new Flow(), this.getFilterName());
        request.setAttribute(Constants.CURRENTFLOWKEY, flowKey);
        request.getSession(false).setAttribute(Constants.FLOWMANAGER, flowManager);
        request.getSession(false).setAttribute(Constants.RANDOMNUM, new Random().nextLong());
        boolean flag = AccountingRules.getSimpleAccountingStatus();
        request.getSession(false).setAttribute("accountingActivationStatus", flag);
        LoginDto loginActivity = loginServiceFacade.login(username, password);
        PersonnelBO user = ApplicationContextProvider.getBean(LegacyPersonnelDao.class).findPersonnelById(loginActivity.getUserId());
        SitePreferenceHelper sitePreferenceHelper = new SitePreferenceHelper();
        sitePreferenceHelper.setSitePreferenceCookie(SitePreferenceType.getSitePreference(user.getSitePreference()), response);
        ActivityContext activityContext = new ActivityContext(Short.valueOf("0"), user.getOffice().getOfficeId(), user.getPersonnelId());
        request.getSession(false).setAttribute(Constants.ACTIVITYCONTEXT, activityContext);
        request.setAttribute("activityDto", loginActivity);
        Short localeId = user.getPreferredLocale();
        Locale preferredLocale = Localization.getInstance().getLocaleById(localeId);
        UserContext userContext = new UserContext();
        userContext.setPreferredLocale(preferredLocale);
        userContext.setLocaleId(localeId);
        userContext.setId(user.getPersonnelId());
        userContext.setName(user.getDisplayName());
        userContext.setLevel(user.getLevelEnum());
        userContext.setRoles(user.getRoles());
        userContext.setLastLogin(user.getLastLogin());
        userContext.setPasswordChanged(user.getPasswordChanged());
        userContext.setBranchId(user.getOffice().getOfficeId());
        userContext.setBranchGlobalNum(user.getOffice().getGlobalOfficeNum());
        userContext.setOfficeLevelId(user.getOffice().getLevel().getId());
        request.setAttribute(Constants.USERCONTEXT, userContext);
        request.getSession(false).setAttribute(Constants.USERCONTEXT, userContext);
        request.removeAttribute("CURRENT_LOCALE_ID");
        request.setAttribute("CURRENT_LOCALE_ID", localeId);
        if (loginActivity.isPasswordChanged()) {
            HttpSession hs = request.getSession(false);
            hs.setAttribute(Constants.USERCONTEXT, userContext);
            hs.setAttribute(Globals.LOCALE_KEY, userContext.getCurrentLocale());
        } else {
            flowManager.addObjectToFlow(flowKey, Constants.TEMPUSERCONTEXT, userContext);
        }
        if (loginActivity.isPasswordChanged()) {
            flowManager.removeFlow((String) request.getAttribute(Constants.CURRENTFLOWKEY));
            request.setAttribute(Constants.CURRENTFLOWKEY, null);
        }
    } catch (ApplicationException e1) {
        throw new MifosRuntimeException(e1);
    }
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) Locale(java.util.Locale) FlowManager(org.mifos.framework.util.helpers.FlowManager) SitePreferenceHelper(org.mifos.ui.core.controller.util.helpers.SitePreferenceHelper) UserContext(org.mifos.security.util.UserContext) HttpSession(javax.servlet.http.HttpSession) LegacyPersonnelDao(org.mifos.customers.personnel.persistence.LegacyPersonnelDao) Flow(org.mifos.framework.util.helpers.Flow) ApplicationException(org.mifos.framework.exceptions.ApplicationException) Random(java.util.Random) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoginDto(org.mifos.dto.domain.LoginDto) DateTimeService(org.mifos.framework.util.DateTimeService) MifosRuntimeException(org.mifos.core.MifosRuntimeException)

Example 24 with ActivityContext

use of org.mifos.security.util.ActivityContext in project head by mifos.

the class MifosRequestProcessor method processRoles.

@Override
protected boolean processRoles(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping) throws IOException, ServletException {
    HttpSession session = request.getSession();
    PreviousRequestValues previousRequestValues = (PreviousRequestValues) session.getAttribute(Constants.PREVIOUS_REQUEST);
    if (null == previousRequestValues) {
        previousRequestValues = new PreviousRequestValues();
        session.setAttribute(Constants.PREVIOUS_REQUEST, previousRequestValues);
    }
    if (!checkProcessRoles(request, response, mapping)) {
        ActionErrors error = new ActionErrors();
        error.add(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED, new ActionMessage(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED));
        request.setAttribute(Globals.ERROR_KEY, error);
        ActivityContext activityContext = (ActivityContext) request.getSession().getAttribute("ActivityContext");
        populateTheRequestFromPreviousValues(request, previousRequestValues);
        processForwardConfig(request, response, activityContext.getLastForward());
        return false;
    }
    return true;
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) PreviousRequestValues(org.mifos.framework.util.helpers.PreviousRequestValues) HttpSession(javax.servlet.http.HttpSession) ActionMessage(org.apache.struts.action.ActionMessage) ActionErrors(org.apache.struts.action.ActionErrors)

Aggregations

ActivityContext (org.mifos.security.util.ActivityContext)24 Before (org.junit.Before)13 UserContext (org.mifos.security.util.UserContext)12 HttpSession (javax.servlet.http.HttpSession)5 Test (org.junit.Test)3 PersonnelBusinessService (org.mifos.customers.personnel.business.service.PersonnelBusinessService)3 ActivityEntity (org.mifos.security.rolesandpermission.business.ActivityEntity)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MifosRuntimeException (org.mifos.core.MifosRuntimeException)2 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)2 FieldConfig (org.mifos.framework.components.fieldConfiguration.util.helpers.FieldConfig)2 PreviousRequestValues (org.mifos.framework.util.helpers.PreviousRequestValues)2 Enumeration (java.util.Enumeration)1 Locale (java.util.Locale)1 Random (java.util.Random)1 ServletException (javax.servlet.ServletException)1 ActionErrors (org.apache.struts.action.ActionErrors)1 ActionForward (org.apache.struts.action.ActionForward)1 ActionMessage (org.apache.struts.action.ActionMessage)1