Search in sources :

Example 61 with HttpSession

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

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

the class LoginAction method setUserContextInSession.

private void setUserContextInSession(UserContext userContext, HttpServletRequest request) {
    HttpSession hs = request.getSession(false);
    hs.setAttribute(Constants.USERCONTEXT, userContext);
    hs.setAttribute(Globals.LOCALE_KEY, userContext.getCurrentLocale());
}
Also used : HttpSession(javax.servlet.http.HttpSession)

Example 63 with HttpSession

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

the class BulkEntryActionStrutsTest method getUserLocale.

private Locale getUserLocale(final 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 64 with HttpSession

use of javax.servlet.http.HttpSession in project hudson-2.x by hudson.

the class SecurityRealm method doLogout.

/**
     * Handles the logout processing.
     * <p/>
     * <p/>
     * The default implementation erases the session and do a few other clean up, then
     * redirect the user to the URL specified by {@link #getPostLogOutUrl(StaplerRequest, Authentication)}.
     *
     * @since 1.314
     */
public void doLogout(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
    HttpSession session = req.getSession(false);
    if (session != null) {
        session.invalidate();
    }
    Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    SecurityContextHolder.clearContext();
    //Clear env property.
    EnvVars.clearHudsonUserEnvVar();
    // reset remember-me cookie
    Cookie cookie = new Cookie(ACEGI_SECURITY_HASHED_REMEMBER_ME_COOKIE_KEY, "");
    cookie.setPath(req.getContextPath().length() > 0 ? req.getContextPath() : "/");
    rsp.addCookie(cookie);
    rsp.sendRedirect2(getPostLogOutUrl(req, auth));
}
Also used : Cookie(javax.servlet.http.Cookie) HttpSession(javax.servlet.http.HttpSession) Authentication(org.acegisecurity.Authentication)

Example 65 with HttpSession

use of javax.servlet.http.HttpSession in project nutz by nutzam.

the class ModuleProcessor method process.

public void process(ActionContext ac) throws Throwable {
    RequestIocContext reqContext = null;
    try {
        if (null != moduleObj) {
            ac.setModule(moduleObj);
        } else {
            Ioc ioc = ac.getIoc();
            Object obj;
            /*
                 * 如果 Ioc 容器实现了高级接口,那么会为当前请求设置上下文对象
                 */
            if (NutSessionListener.isSessionScopeEnable && ioc instanceof Ioc2) {
                reqContext = new RequestIocContext(ac.getRequest());
                HttpSession sess = Mvcs.getHttpSession(false);
                IocContext myContext = null;
                // 如果容器可以创建 Session ...
                if (null != sess) {
                    SessionIocContext sessionContext = new SessionIocContext(sess);
                    myContext = new ComboContext(reqContext, sessionContext);
                } else // 如果容器禁止了 Session ...
                {
                    myContext = reqContext;
                }
                Mvcs.setIocContext(myContext);
                obj = ((Ioc2) ioc).get(moduleType, injectName, myContext);
            } else
                /*
                 * 否则,则仅仅简单的从容器获取
                 */
                obj = ioc.get(moduleType, injectName);
            ac.setModule(obj);
        }
        ac.setMethod(method);
        // if (log.isDebugEnabled()) //打印实际执行的Method信息
        // log.debugf("Handle URL[%s] by Method[%s]",ac.getPath(),method);
        doNext(ac);
    } finally {
        if (reqContext != null)
            try {
                reqContext.depose();
            } catch (Throwable e) {
                if (log.isDebugEnabled())
                    log.debug("ReqContext depose fail?!", e);
            }
    }
}
Also used : ComboContext(org.nutz.ioc.impl.ComboContext) SessionIocContext(org.nutz.mvc.ioc.SessionIocContext) RequestIocContext(org.nutz.mvc.ioc.RequestIocContext) IocContext(org.nutz.ioc.IocContext) SessionIocContext(org.nutz.mvc.ioc.SessionIocContext) HttpSession(javax.servlet.http.HttpSession) Ioc2(org.nutz.ioc.Ioc2) Ioc(org.nutz.ioc.Ioc) RequestIocContext(org.nutz.mvc.ioc.RequestIocContext)

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