/** * Called when a servlet/portlet completes the service of a request. * This method must be called if {@link #requestEnter} is called * and returns true. This method shall not be called, otherwise. * * @since 3.0.1 */ public static void requestExit(Session sess) { final Integer v = (Integer) sess.getAttribute(ATTR_REQUEST_COUNT); final int i = v != null ? v.intValue() - 1 : 0; sess.setAttribute(ATTR_REQUEST_COUNT, new Integer(i >= 0 ? i : 0)); }
/** Called when a servlet/portlet starts to serve a request. * It checks whether the number of concurrent requests per session * exceeds the number specified in * {@link org.zkoss.zk.ui.util.Configuration#getSessionMaxRequests}. * If exceeded, false is returned, and the servlet/portlet shall stop * processing and return an error code back the client. * * <p>If not exceeded, true is returned, and the servlet/portlet * can continue the processing and it shall invoke {@link #requestExit} * in the finally clause. * * @since 3.0.1 */ public static boolean requestEnter(Session sess) { final Integer v = (Integer) sess.getAttribute(ATTR_REQUEST_COUNT); final int i = v != null ? v.intValue() + 1 : 1; final int max = sess.getWebApp().getConfiguration().getSessionMaxRequests(); if (max < 0 || i <= max) { sess.setAttribute(ATTR_REQUEST_COUNT, new Integer(i)); return true; } return false; }
Object o = null; if (sess != null) { o = sess.getAttribute(Attributes.PREFERRED_FIRST_DAY_OF_WEEK); if (o == null) { final Object hsess = sess.getNativeSession(); if (hsess instanceof HttpSession) o = ((HttpSession) hsess).getServletContext()
/** Returns this Web application, or null if not available. * <p>Notice that this method is useful only if ZK libraries are * NOT shared by multiple Web application (in other words, * they are installed under <code>WEB-INF/lib</code>). * If you share ZK libraries among multiple applications (such as * installing them under <code>shared/lib</code>), the returned instance could * be any of them. * * <p>If you share ZK libraries among multiple applications, you could * retrieve the current Web application by one of the following * depending your context. * <ol> * <li>In an event listener:<br/> * <code>Sessions.getCurrent(false).getWebApp();</code><br/> * Note, since {@link Sessions#getCurrent(boolean)} returns null if it executes * in a working thread (without {@link Execution}).</li> * <li>In a working thread (not current execution):<br/> * <code>WebManager.getWebManager(servletContext).getWebApp();</code><br/> * As shown above, {@link org.zkoss.zk.ui.http.WebManager#getWebManager} * requires a servlet context.</li></ol> * @since 5.0.9 */ public static WebApp getCurrent() { final Session sess = Sessions.getCurrent(false); return sess != null ? sess.getWebApp() : _wapp; }
/** * Submits the authentication request. */ private void doSubmit() { showMessage(""); final Organization organization = getSelectedOrganization(); String instId = organization == null ? null : organization.getId().getIdPart(); String username = j_username.getValue().trim(); final String password = j_password.getValue(); if (username.contains("\\")) { String[] pcs = username.split("\\\\", 2); instId = pcs[0]; username = pcs[1]; } if (!username.isEmpty() && !password.isEmpty() && !instId.isEmpty()) { session.setAttribute(Constants.DEFAULT_INSTITUTION, instId); FrameworkWebSupport.setCookie(Constants.DEFAULT_INSTITUTION, instId); session.setAttribute(Constants.DEFAULT_USERNAME, username); //FrameworkWebSupport.setCookie(Constants.DEFAULT_USERNAME, username); j_username.setValue(instId + "\\" + username); showState(Labels.getLabel(Constants.LBL_LOGIN_PROGRESS)); session.setAttribute(org.carewebframework.security.spring.Constants.SAVED_REQUEST, savedRequest); Events.sendEvent("onSubmit", loginRoot.getRoot(), null); } else { showMessage(Labels.getLabel(Constants.LBL_LOGIN_REQUIRED_FIELDS)); } }
String username = (String) session.removeAttribute(Constants.DEFAULT_USERNAME); username = authError == null ? "" : username; showMessage(authError == null ? null : loginFailureMessage); defaultInst = (String) session.getAttribute(Constants.DEFAULT_INSTITUTION); .getAttribute(org.carewebframework.security.spring.Constants.SAVED_REQUEST);
/** Puts a ZK session to the cache. * You can retrieve the native session by {@link Session#getNativeSession}. * @param sess the ZK session. */ public void put(Session sess) { ((HttpSession) sess.getNativeSession()).setAttribute(Attributes.ZK_SESSION, sess); }
/** Invokes {@link #getDesktopCache}'s {@link DesktopCache#sessionDidActivate}. */ public void sessionDidActivate(Session sess) { DesktopCache dc = (DesktopCache) sess.getAttribute(ATTR_CACHE); if (dc != null) dc.sessionDidActivate(sess); }
public Object setAttribute(String name, Object value, boolean recurse) { if (recurse && !hasAttribute(name)) { if (_sess != null) { if (_sess.hasAttribute(name, true)) return _sess.setAttribute(name, value, true); } else if (_wapp != null) { if (_wapp.hasAttribute(name, true)) return _wapp.setAttribute(name, value, true); } } return setAttribute(name, value); }
final String errpg = sess.getWebApp().getConfiguration().getErrorPage(sess.getDeviceType(), err); if (errpg != null) { try {
private static final Object setup(Object sess, ServletRequest request, ServletResponse response, String charset) { final Object[] old; if (request.getAttribute(ATTR_SETUP) != null) { //has been setup old = null; } else { final HttpSession hsess; if (sess instanceof Session) { final Session se = (Session) sess; //Invoke the request interceptors se.getWebApp().getConfiguration().invokeRequestInterceptors(se, request, response); hsess = (HttpSession) se.getNativeSession(); } else { hsess = (HttpSession) sess; } final Object ol = Charsets.setup(hsess, request, response, charset); //Charsets will handle PREFERRED_LOCALE //time zone final TimeZone tz = getTimeZone(hsess); final Object otz = TimeZones.setThreadLocal(tz); //date format info final DateFormatInfo dfinfo = getDateFormatInfo(hsess); final Object odi = DateFormats.setLocalFormatInfo(dfinfo); request.setAttribute(ATTR_SETUP, Boolean.TRUE); //mark as setup old = new Object[] { ol, otz, odi }; } if (sess instanceof Session) SessionsCtrl.setCurrent((Session) sess); return old; }
public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); timer.setDelay(execution.getSession().getMaxInactiveInterval() * 500); savedRequest = (SavedRequest) session.removeAttribute(org.carewebframework.security.spring.Constants.SAVED_REQUEST); AuthenticationException authError = (AuthenticationException) session .removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION); IUser user = (IUser) session.removeAttribute(org.carewebframework.security.spring.Constants.SAVED_USER); Map<Object, Object> args = new HashMap<Object, Object>(); args.put("savedRequest", savedRequest);
public Object removeAttribute(String name, boolean recurse) { if (recurse && !hasAttribute(name)) { if (_sess != null) { if (_sess.hasAttribute(name, true)) return _sess.removeAttribute(name, true); } else if (_wapp != null) { if (_wapp.hasAttribute(name, true)) return _wapp.removeAttribute(name, true); } return null; } return removeAttribute(name); }
/** * Initialize the login form. * * @param comp - The component */ @SuppressWarnings("deprecation") @Override public void doAfterCompose(final Component comp) throws Exception { super.doAfterCompose(comp); savedRequest = (SavedRequest) session.removeAttribute(org.carewebframework.security.spring.Constants.SAVED_REQUEST); final AuthenticationException authError = (AuthenticationException) session .removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION); CredentialsExpiredException expired = getException(authError, CredentialsExpiredException.class); User user = expired != null && SecurityUtil.getSecurityService().canChangePassword() ? (User) expired .getExtraInformation() : null; String form = user != null ? ChangePasswordController.DIALOG_CHANGE_PASSWORD : LoginPaneController.DIALOG_LOGIN_PANE; Map<Object, Object> args = new HashMap<Object, Object>(); args.put("savedRequest", savedRequest); args.put("authError", authError); args.put("user", user); ZKUtil.loadZulPage(form, loginForm, args, this); getPage().setTitle(user != null ? "Change Password" : "Please Login"); resetTimer(); }
if (autoTimeout != null ? autoTimeout.booleanValue() : wapp.getConfiguration().isAutomaticTimeout(deviceType)) { if (desktop != null) { tmout = desktop.getSession().getMaxInactiveInterval(); } else { Object req = exec.getNativeRequest(); final Session sess = SessionsCtrl.getSession(wapp, hsess); if (sess != null) { tmout = sess.getMaxInactiveInterval(); } else {
/** Returns the desktop of the specified ID, or null if not found. * If null is returned, {@link #recoverDesktop} will be invoked. * @param sess the session (never null) * @param dtid the desktop ID to look for * @since 5.0.3 */ protected Desktop getDesktop(Session sess, String dtid) { return ((WebAppCtrl) sess.getWebApp()).getDesktopCache(sess).getDesktopIfAny(dtid); }
/** * Submits the authentication request. */ public void onSubmit() { showMessage(""); ISecurityDomain securityDomain = getSelectedSecurityDomain(); String securityDomainId = securityDomain == null ? null : securityDomain.getLogicalId(); String username = txtUsername.getValue().trim(); String password = txtPassword.getValue(); if (username.contains("\\")) { String[] pcs = username.split("\\\\", 2); securityDomainId = pcs[0]; username = pcs[1]; } if (!username.isEmpty() && !password.isEmpty() && !securityDomainId.isEmpty()) { session.setAttribute(Constants.DEFAULT_SECURITY_DOMAIN, securityDomainId); FrameworkWebSupport.setCookie(Constants.DEFAULT_SECURITY_DOMAIN, securityDomainId); session.setAttribute(Constants.DEFAULT_USERNAME, username); txtUsername.setValue(securityDomainId + "\\" + username); showStatus(StrUtil.getLabel(Constants.LBL_LOGIN_PROGRESS)); session.setAttribute(org.carewebframework.security.spring.Constants.SAVED_REQUEST, savedRequest); Events.sendEvent("onSubmit", loginRoot.getRoot(), null); } else { showMessage(StrUtil.getLabel(Constants.LBL_LOGIN_REQUIRED_FIELDS)); pane.setVisible(true); } }
String username = (String) session.removeAttribute(Constants.DEFAULT_USERNAME); username = authError == null ? defaultUsername : username; showMessage(authError == null ? null : loginFailureMessage); securityDomainId = (String) session.getAttribute(Constants.DEFAULT_SECURITY_DOMAIN);
/** Removes the ZK session from the cache. */ public void remove(Session sess) { ((HttpSession) sess.getNativeSession()).removeAttribute(Attributes.ZK_SESSION); }
/** Invokes {@link #getDesktopCache}'s {@link DesktopCache#sessionWillPassivate}. */ public void sessionWillPassivate(Session sess) { DesktopCache dc = (DesktopCache) sess.getAttribute(ATTR_CACHE); if (dc != null) dc.sessionWillPassivate(sess); }