Search in sources :

Example 56 with HttpSession

use of javax.servlet.http.HttpSession in project head by mifos.

the class PersonAction method refreshUserContextIfActive.

/*
     * When we update user we want to refresh his roles (and permissions) immediately
     * This method search for edited user in all active sessions and refresh his context
     */
private void refreshUserContextIfActive(HttpServletRequest request, Long id, String username, Set<Short> roles) {
    ShutdownManager shutdownManager = (ShutdownManager) ServletUtils.getGlobal(request, ShutdownManager.class.getName());
    Collection<HttpSession> sessions = shutdownManager.getActiveSessions();
    for (HttpSession session : sessions) {
        UserContext userContext = (UserContext) session.getAttribute("UserContext");
        if (userContext != null) {
            if (userContext.getId() == id.shortValue()) {
                userContext.setRoles(roles);
                authenticationAuthorizationServiceFacade.reloadUserDetailsForSecurityContext(username);
                break;
            }
        }
    }
}
Also used : HttpSession(javax.servlet.http.HttpSession) UserContext(org.mifos.security.util.UserContext) ShutdownManager(org.mifos.application.admin.system.ShutdownManager)

Example 57 with HttpSession

use of javax.servlet.http.HttpSession in project head by mifos.

the class CustomerActionForm method getUserLocale.

protected Locale getUserLocale(HttpServletRequest request) {
    Locale locale = null;
    HttpSession session = request.getSession();
    if (session != null) {
        UserContext userContext = (UserContext) session.getAttribute(LoginConstants.USERCONTEXT);
        if (null != userContext) {
            locale = userContext.getCurrentLocale();
        }
    }
    return locale;
}
Also used : Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession) UserContext(org.mifos.security.util.UserContext)

Example 58 with HttpSession

use of javax.servlet.http.HttpSession in project head by mifos.

the class ApproveTransactions method submit.

public ActionForward submit(ActionMapping mapping, ActionForm form, HttpServletRequest request, @SuppressWarnings("unused") HttpServletResponse response) throws Exception {
    HttpSession session = request.getSession(true);
    ViewStageTransactionActionForm actionForm = (ViewStageTransactionActionForm) form;
    GlMasterBO glMasterBO = new GlMasterBO();
    int stage = 1;
    List<String> amountActionList = getAmountAction(actionForm);
    List<GlDetailBO> glDetailBOList = getGlDetailBOList(actionForm, amountActionList, Integer.parseInt(actionForm.getTransactionDetailID()));
    glMasterBO.setTransactionMasterId(Integer.parseInt(actionForm.getStageTransactionNo()));
    glMasterBO.setTransactionDate(DateUtils.getDate(actionForm.getStageTrxnDate()));
    glMasterBO.setTransactionType(actionForm.getStageTrxnType());
    glMasterBO.setFromOfficeLevel(new Integer(actionForm.getStageOfficeHierarchy()));
    glMasterBO.setFromOfficeId(actionForm.getStageOffice());
    glMasterBO.setToOfficeLevel(new Integer(actionForm.getStageOfficeHierarchy()));
    glMasterBO.setToOfficeId(actionForm.getStageOffice());
    glMasterBO.setMainAccount(actionForm.getStageMainAccount());
    glMasterBO.setTransactionAmount(new BigDecimal(actionForm.getStageAmount()));
    glMasterBO.setAmountAction(amountActionList.get(0));
    glMasterBO.setTransactionNarration(actionForm.getStageNotes());
    glMasterBO.setStage(stage);
    glMasterBO.setGlDetailBOList(glDetailBOList);
    // default value
    glMasterBO.setStatus("");
    // default value
    glMasterBO.setTransactionBy(0);
    glMasterBO.setCreatedBy(getUserContext(request).getId());
    glMasterBO.setCreatedDate(DateUtils.getCurrentDateWithoutTimeStamp());
    accountingServiceFacade.savingAccountingTransactions(glMasterBO);
    return mapping.findForward("submit_success");
}
Also used : HttpSession(javax.servlet.http.HttpSession) GlMasterBO(org.mifos.application.accounting.business.GlMasterBO) ViewStageTransactionActionForm(org.mifos.accounting.struts.actionform.ViewStageTransactionActionForm) BigDecimal(java.math.BigDecimal) GlDetailBO(org.mifos.application.accounting.business.GlDetailBO)

Example 59 with HttpSession

use of javax.servlet.http.HttpSession 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 60 with HttpSession

use of javax.servlet.http.HttpSession in project head by mifos.

the class LookupOptionsActionForm method getUserLocale.

protected Locale getUserLocale(HttpServletRequest request) {
    Locale locale = null;
    HttpSession session = request.getSession();
    if (session != null) {
        UserContext userContext = (UserContext) session.getAttribute(LoginConstants.USERCONTEXT);
        if (null != userContext) {
            locale = userContext.getCurrentLocale();
        }
    }
    return locale;
}
Also used : Locale(java.util.Locale) HttpSession(javax.servlet.http.HttpSession) UserContext(org.mifos.security.util.UserContext)

Aggregations

HttpSession (javax.servlet.http.HttpSession)730 HttpServletRequest (javax.servlet.http.HttpServletRequest)151 Test (org.junit.Test)110 IOException (java.io.IOException)80 HttpServletResponse (javax.servlet.http.HttpServletResponse)80 ServletException (javax.servlet.ServletException)75 ArrayList (java.util.ArrayList)65 RequestDispatcher (javax.servlet.RequestDispatcher)59 HashMap (java.util.HashMap)48 Map (java.util.Map)44 Locale (java.util.Locale)39 Properties (java.util.Properties)39 PrintWriter (java.io.PrintWriter)38 Cookie (javax.servlet.http.Cookie)27 List (java.util.List)24 SQLException (java.sql.SQLException)23 WebUser (org.compiere.util.WebUser)23 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)20 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)20 ModelAndView (org.springframework.web.servlet.ModelAndView)20