Search in sources :

Example 1 with ShutdownManager

use of org.mifos.application.admin.system.ShutdownManager in project head by mifos.

the class ShutdownServiceFacadeWebTier method cancelShutdown.

@Override
public void cancelShutdown(HttpServletRequest request) {
    ShutdownManager shutdownManager = (ShutdownManager) ServletUtils.getGlobal(request, ShutdownManager.class.getName());
    shutdownManager.cancelShutdown();
}
Also used : ShutdownManager(org.mifos.application.admin.system.ShutdownManager)

Example 2 with ShutdownManager

use of org.mifos.application.admin.system.ShutdownManager 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 3 with ShutdownManager

use of org.mifos.application.admin.system.ShutdownManager in project head by mifos.

the class MifosLegacyUsernamePasswordAuthenticationFilter method doFilter.

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    //LocaleContextHolder.setLocale(Localization.getInstance().getConfiguredLocale());
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    AuthenticationException denied = null;
    boolean allowAuthenticationToContinue = true;
    if (MifosBatchJob.isBatchJobRunningThatRequiresExclusiveAccess()) {
        allowAuthenticationToContinue = false;
        HttpSession session = request.getSession(false);
        if (session != null) {
            session.invalidate();
        }
        denied = new AuthenticationServiceException(messages.getMessage(LoginConstants.BATCH_JOB_RUNNING, "You have been logged out of the system because batch jobs are running."));
    }
    ShutdownManager shutdownManager = (ShutdownManager) ServletUtils.getGlobal(request, ShutdownManager.class.getName());
    if (shutdownManager.isShutdownDone()) {
        allowAuthenticationToContinue = false;
        request.getSession(false).invalidate();
        denied = new AuthenticationServiceException(messages.getMessage(LoginConstants.SHUTDOWN, "You have been logged out of the system because Mifos is shutting down."));
    }
    if (shutdownManager.isInShutdownCountdownNotificationThreshold()) {
        request.setAttribute("shutdownIsImminent", true);
    }
    if (allowAuthenticationToContinue) {
        super.doFilter(request, response, chain);
    } else {
        unsuccessfulAuthentication(request, response, denied);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AuthenticationException(org.springframework.security.core.AuthenticationException) HttpSession(javax.servlet.http.HttpSession) HttpServletResponse(javax.servlet.http.HttpServletResponse) ShutdownManager(org.mifos.application.admin.system.ShutdownManager) AuthenticationServiceException(org.springframework.security.authentication.AuthenticationServiceException)

Example 4 with ShutdownManager

use of org.mifos.application.admin.system.ShutdownManager in project head by mifos.

the class ApplicationInitializer method sessionCreated.

@Override
public void sessionCreated(HttpSessionEvent httpSessionEvent) {
    ServletContext ctx = httpSessionEvent.getSession().getServletContext();
    final ShutdownManager shutdownManager = (ShutdownManager) ctx.getAttribute(ShutdownManager.class.getName());
    shutdownManager.sessionCreated(httpSessionEvent);
}
Also used : ServletContext(javax.servlet.ServletContext) ShutdownManager(org.mifos.application.admin.system.ShutdownManager)

Example 5 with ShutdownManager

use of org.mifos.application.admin.system.ShutdownManager 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)

Aggregations

ShutdownManager (org.mifos.application.admin.system.ShutdownManager)11 HttpSession (javax.servlet.http.HttpSession)4 ServiceException (org.mifos.framework.exceptions.ServiceException)3 UserContext (org.mifos.security.util.UserContext)3 ArrayList (java.util.ArrayList)2 ServletContext (javax.servlet.ServletContext)2 PersonnelBO (org.mifos.customers.personnel.business.PersonnelBO)2 PersonnelBusinessService (org.mifos.customers.personnel.business.service.PersonnelBusinessService)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ActionForward (org.apache.struts.action.ActionForward)1 HibernateException (org.hibernate.HibernateException)1 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)1 Before (org.junit.Before)1 InvalidDateException (org.mifos.application.admin.servicefacade.InvalidDateException)1 LoggedUserDto (org.mifos.application.admin.servicefacade.LoggedUserDto)1 PersonnelServiceFacade (org.mifos.application.admin.servicefacade.PersonnelServiceFacade)1 PersonnelInfo (org.mifos.application.admin.system.PersonnelInfo)1 MifosUserBuilder (org.mifos.builders.MifosUserBuilder)1 LocaleSetting (org.mifos.config.LocaleSetting)1