Search in sources :

Example 1 with ActivityContext

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

the class MifosRequestProcessor method processActionPerform.

/**
     * This method is overridden because in case of exception we need to
     * populate the request with the old values so that when the user goes back
     * to the previous page it has all the values in the request.For this we
     * create an object which will store the values of previous request in case
     * the request is successful and if there is an exception it reads values
     * from that object and context and dups all in the request.
     */
@Override
protected ActionForward processActionPerform(HttpServletRequest request, HttpServletResponse response, Action action, ActionForm form, ActionMapping mapping) throws IOException, ServletException {
    ActivityContext activityContext = null;
    ActionForward forward = null;
    HttpSession session = request.getSession();
    // gets the object where we will store values from request.
    PreviousRequestValues previousRequestValues = (PreviousRequestValues) session.getAttribute(Constants.PREVIOUS_REQUEST);
    if (null == previousRequestValues) {
        previousRequestValues = new PreviousRequestValues();
        session.setAttribute(Constants.PREVIOUS_REQUEST, previousRequestValues);
    }
    // getting the activity context from the session
    activityContext = (ActivityContext) session.getAttribute("ActivityContext");
    try {
        String currentFlowKey = request.getParameter(Constants.CURRENTFLOWKEY);
        if (currentFlowKey != null) {
            previousRequestValues.getPreviousRequestValueMap().put(Constants.CURRENTFLOWKEY, currentFlowKey);
        }
        forward = (action.execute(mapping, form, request, response));
        String method = request.getParameter("method");
        if (method.equals(ClientConstants.METHOD_RETRIEVE_PICTURE)) {
            forward = mapping.findForward("get_success");
        }
        // set the last forward in the activity context
        if (activityContext != null) {
            activityContext.setLastForward(forward);
        }
        // read the request and add the values to the PreviousRequestValues
        // object. this will set every thing in the request apart from
        // context and value object.
        Enumeration requestAttributes = request.getAttributeNames();
        while (requestAttributes.hasMoreElements()) {
            String nextName = (String) requestAttributes.nextElement();
            if (nextName.startsWith(Constants.STORE_ATTRIBUTE) || nextName.equalsIgnoreCase(Constants.CURRENTFLOWKEY)) {
                logger.debug(nextName + "=" + request.getAttribute(nextName));
                previousRequestValues.getPreviousRequestValueMap().put(nextName, request.getAttribute(nextName));
            }
        }
    } catch (Exception e) {
        // processException logs an error (see MifosExceptionHandler)
        forward = (processException(request, response, e, form, mapping));
        // set the last forward in the activity context
        if (activityContext != null) {
            activityContext.setLastForward(forward);
        }
        populateTheRequestFromPreviousValues(request, previousRequestValues);
    } finally {
        try {
            session.removeAttribute(SecurityConstants.SECURITY_PARAM);
        } catch (Exception e) {
        // FIXME: yikes, what is being swallowed here?
        }
    }
    if (null != forward) {
        logger.info("forward.path=" + forward.getPath());
    }
    return forward;
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) Enumeration(java.util.Enumeration) PreviousRequestValues(org.mifos.framework.util.helpers.PreviousRequestValues) HttpSession(javax.servlet.http.HttpSession) ActionForward(org.apache.struts.action.ActionForward) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 2 with ActivityContext

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

the class MifosRequestProcessor method setActivityContextFromRequest.

private ActivityContext setActivityContextFromRequest(HttpServletRequest request, Short activityId) {
    HttpSession session = request.getSession();
    ActivityContext activityContext = (ActivityContext) session.getAttribute("ActivityContext");
    if (activityContext != null) {
        // get the values from the request
        String recordOfficeId = request.getParameter("recordOfficeId");
        String recordLoanOfficerId = request.getParameter("recordLoanOfficerId");
        short recordOffId = -1;
        short recordLoOffId = -1;
        try {
            /*
                 * The null case is if one or both parameters was omitted.
                 * What's the difference between supplying these as parameters
                 * versus the UserContext, versus just using what is in the
                 * ActivityContext?
                 */
            if (recordOfficeId != null) {
                recordOffId = Short.valueOf(recordOfficeId).shortValue();
            }
            if (recordLoanOfficerId != null) {
                recordLoOffId = Short.valueOf(recordLoanOfficerId).shortValue();
            }
        } catch (NumberFormatException e) {
            throw new RuntimeException(e);
        }
        if (recordOffId > 0 && recordLoOffId > 0) {
            activityContext.setRecordOfficeId(recordOffId);
            activityContext.setRecordLoanOfficer(recordLoOffId);
        } else if (recordOffId == 0 && recordLoOffId == 0) {
            if (session.getAttribute("UserContext") != null) {
                UserContext uc = (UserContext) session.getAttribute("UserContext");
                activityContext.setRecordOfficeId(uc.getBranchId());
                activityContext.setRecordLoanOfficer(uc.getId());
            }
        }
        activityContext.setActivityId(activityId);
        return activityContext;
    } else {
        // TODO: Can this happen? Why? Is null right?
        return null;
    }
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) HttpSession(javax.servlet.http.HttpSession) UserContext(org.mifos.security.util.UserContext)

Example 3 with ActivityContext

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

the class FeeActionStrutsTest method setUp.

@Before
public void setUp() throws Exception {
    UserContext userContext = TestUtils.makeUser();
    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, FeeAction.class);
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) UserContext(org.mifos.security.util.UserContext) Before(org.junit.Before)

Example 4 with ActivityContext

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

the class ShutdownServiceFacadeWebTier method getLoggedUsers.

@Override
public List<LoggedUserDto> getLoggedUsers(HttpServletRequest request) {
    ShutdownManager shutdownManager = (ShutdownManager) ServletUtils.getGlobal(request, ShutdownManager.class.getName());
    Collection<HttpSession> sessions = shutdownManager.getActiveSessions();
    List<PersonnelInfo> personnelInfos = new ArrayList<PersonnelInfo>();
    UserContext userContext = (UserContext) SessionUtils.getAttribute(Constants.USER_CONTEXT_KEY, request.getSession());
    if (ActivityMapper.getInstance().isViewActiveSessionsPermitted(userContext, userContext.getBranchId())) {
        PersonnelBusinessService personnelBusinessService = new PersonnelBusinessService();
        for (HttpSession session : sessions) {
            UserContext userContextFromSession = (UserContext) session.getAttribute(LoginConstants.USERCONTEXT);
            if (userContextFromSession == null) {
                continue;
            }
            PersonnelBO personnel;
            try {
                personnel = personnelBusinessService.getPersonnel(userContextFromSession.getId());
            } catch (ServiceException e) {
                continue;
            }
            String offices = generateOfficeChain(personnel.getOffice());
            String names = personnel.getPersonnelDetails().getName().getFirstName() + " " + personnel.getPersonnelDetails().getName().getLastName();
            DateTimeFormatter formatter = DateTimeFormat.shortDateTime().withOffsetParsed().withLocale(userContext.getCurrentLocale());
            String activityTime = formatter.print(session.getLastAccessedTime());
            ActivityContext activityContext = (ActivityContext) session.getAttribute(LoginConstants.ACTIVITYCONTEXT);
            String activityDesc = "[" + activityContext.getLastForward().getName() + "] " + activityContext.getLastForward().getPath();
            personnelInfos.add(new PersonnelInfo(offices, names, activityTime, activityDesc));
        }
    }
    Collections.sort(personnelInfos);
    List<LoggedUserDto> loggedUsers = new ArrayList<LoggedUserDto>();
    for (PersonnelInfo personnelInfo : personnelInfos) {
        loggedUsers.add(new LoggedUserDto(personnelInfo.getOffices(), personnelInfo.getNames(), personnelInfo.getActivityTime(), personnelInfo.getActivityContext()));
    }
    return loggedUsers;
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) PersonnelBusinessService(org.mifos.customers.personnel.business.service.PersonnelBusinessService) HttpSession(javax.servlet.http.HttpSession) UserContext(org.mifos.security.util.UserContext) ArrayList(java.util.ArrayList) PersonnelInfo(org.mifos.application.admin.system.PersonnelInfo) ShutdownManager(org.mifos.application.admin.system.ShutdownManager) ServiceException(org.mifos.framework.exceptions.ServiceException) PersonnelBO(org.mifos.customers.personnel.business.PersonnelBO) LoggedUserDto(org.mifos.application.admin.servicefacade.LoggedUserDto) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 5 with ActivityContext

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

the class BulkEntryActionStrutsTest method setUp.

@Before
public void setUp() throws Exception {
    enableCustomWorkingDays();
    userContext = TestUtils.makeUser();
    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, CollectionSheetEntryAction.class);
}
Also used : ActivityContext(org.mifos.security.util.ActivityContext) Before(org.junit.Before)

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