public void testSessionIsInvalidatedDuringMaintenance() throws InterruptedException { // 20 seconds sessionComponent.setInactiveInterval("20"); final CountDownLatch startedLatch = new CountDownLatch(1); final CountDownLatch completedLatch = new CountDownLatch(1); final CountDownLatch blockerLatch = new CountDownLatch(1); MySession session = (MySession) newSessionWithBlockableInvalidate(startedLatch, blockerLatch, completedLatch); // now minus 15 seconds session.m_accessed = System.currentTimeMillis() - (25 * 1000L); // now minus 5 seconds session.expirationTimeSuggestion.setValue(System.currentTimeMillis() - (5 * 1000L)); expectGetCurrentSessionReturnNull(session); registerSession(session); resetMaintenance("20", "20"); if (!(startedLatch.await(2, TimeUnit.SECONDS))) { fail("Took too long for the maintenance thread to start up"); } blockerLatch.countDown(); if (!(completedLatch.await(5, TimeUnit.SECONDS))) { fail("Took too long for the Session.invalidate() to complete"); } }
@Override public void onUnauthorizedInstantiation(final Component component) { if (MySession.get().isMobileUserAgent() == true) { throw new RestartResponseAtInterceptPageException(LoginMobilePage.class); } else { throw new RestartResponseAtInterceptPageException(LoginPage.class); } }
/** * @see * org.apache.wicket.authorization.IAuthorizationStrategy#isInstantiationAuthorized(java.lang.Class) */ @Override public <T extends IRequestableComponent> boolean isInstantiationAuthorized( final Class<T> componentClass) { if (WebPage.class.isAssignableFrom(componentClass) == true) { if (MySession.get().isAuthenticated() == true) { return true; } if (AbstractSecuredBasePage.class.isAssignableFrom(componentClass) == true || AbstractSecuredBasePage.class.isAssignableFrom(componentClass) == true || AbstractSecuredMobilePage.class.isAssignableFrom(componentClass) == true) { return false; } } return true; }
/** * 将全部记录加入列表 */ public void buildRecordsList() { try { getMySession(); recordsList = new ArrayList<Department>(); Map<?, ?> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap(); if ("false".equals((String) params.get("reload"))) { if (null != mySession.getTempInt() && mySession.getTempInt().containsKey("Department.rowcount")) { for (int i = 0; i < mySession.getTempInt().get("Department.rowcount"); i++) recordsList.add(new Department(i)); return; } } Query query = getSession().getNamedQuery("core.department.records"); Iterator<?> it = query.list().iterator(); int id, cId, mId; String cDate, mDate, uuid; java.util.Date cDate_, mDate_; int org, parent, seq; String name, desc; int rowcount = 0; while (it.hasNext()) { Object obj[] = (Object[]) it.next(); id = cId = mId = 0; cDate = mDate = uuid = ""; cDate_ = mDate_ = null; org = parent = seq = 0; name = desc = ""; // 读取obj数据时,一定要确保obj不能为null if (obj[0] != null) id = Integer.valueOf(String.valueOf(obj[0])); if (obj[1] != null) cId = Integer.valueOf(String.valueOf(obj[1])); if (obj[2] != null) { java.sql.Timestamp t = (java.sql.Timestamp) obj[2]; cDate_ = new java.util.Date(t.getTime()); cDate = dtf.format(cDate_); } if (obj[3] != null) mId = Integer.valueOf(String.valueOf(obj[3])); if (obj[4] != null) { java.sql.Timestamp t = (java.sql.Timestamp) obj[4]; mDate_ = new java.util.Date(t.getTime()); mDate = dtf.format(mDate_); } if (obj[5] != null) uuid = String.valueOf(obj[5]); if (obj[6] != null) org = Integer.valueOf(String.valueOf(obj[6])); if (obj[7] != null) parent = Integer.valueOf(String.valueOf(obj[7])); if (obj[8] != null) name = String.valueOf(obj[8]); if (obj[9] != null) desc = String.valueOf(obj[9]); if (obj[10] != null) seq = Integer.valueOf(String.valueOf(obj[10])); recordsList.add(new Department(id, cId, cDate, mId, mDate, uuid, org, parent, name, desc, seq)); rowcount++; } it = null; mySession.getTempInt().put("Department.rowcount", rowcount); } catch (Exception ex) { ex.printStackTrace(); } }