List of usage examples for org.apache.shiro.session Session getAttributeKeys
Collection<Object> getAttributeKeys() throws InvalidSessionException;
From source file:cn.mario256.blog.filter.AuthenticationFilter.java
License:Open Source License
/** * ??/*from w ww . j ava 2s.com*/ * * @param token * * @param subject * Subject * @param servletRequest * ServletRequest * @param servletResponse * ServletResponse * @return ?? */ @Override protected boolean onLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, Subject subject, ServletRequest servletRequest, ServletResponse servletResponse) throws Exception { Session session = subject.getSession(); Map<Object, Object> attributes = new HashMap<Object, Object>(); Collection<Object> keys = session.getAttributeKeys(); for (Object key : keys) { attributes.put(key, session.getAttribute(key)); } session.stop(); session = subject.getSession(); for (Map.Entry<Object, Object> entry : attributes.entrySet()) { session.setAttribute(entry.getKey(), entry.getValue()); } return super.onLoginSuccess(token, subject, servletRequest, servletResponse); }
From source file:com.app.filter.AuthenticationFilter.java
License:Open Source License
@Override protected boolean onLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, Subject subject, ServletRequest servletRequest, ServletResponse servletResponse) throws Exception { Session session = subject.getSession(); Map<Object, Object> attributes = new HashMap<Object, Object>(); Collection<Object> keys = session.getAttributeKeys(); for (Object key : keys) { attributes.put(key, session.getAttribute(key)); }/* w ww. j a v a 2 s . co m*/ session.stop(); session = subject.getSession(); for (Entry<Object, Object> entry : attributes.entrySet()) { session.setAttribute(entry.getKey(), entry.getValue()); } return super.onLoginSuccess(token, subject, servletRequest, servletResponse); }
From source file:com.baguaz.module.user.BgzSessionListener.java
License:Apache License
private String buildLogStr(Session session) { StringBuilder sb = new StringBuilder(); sb.append("\n#################################################").append("\nid :") .append(session.getId())/* w ww . j a va 2 s.co m*/ .append("\nstart :" + DateFormatUtils.format(session.getStartTimestamp(), "yyyy-MM-dd HH:mm:ss")) .append("\nlast :" + DateFormatUtils.format(session.getLastAccessTime(), "yyyy-MM-dd HH:mm:ss")) .append("\ntimeout(min):" + session.getTimeout() / (1000 * 60)) .append("\nhost :" + session.getHost()) .append("\nattr keys :" + session.getAttributeKeys()) .append("\n#################################################"); return sb.toString(); }
From source file:com.dp2345.filter.AuthenticationFilter.java
License:Open Source License
/** * HttpSession?shirosession//from w w w . j ava 2s .co m */ @Override protected boolean onLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, Subject subject, ServletRequest servletRequest, ServletResponse servletResponse) throws Exception { Session session = subject.getSession(); Map<Object, Object> attributes = new HashMap<Object, Object>(); Collection<Object> keys = session.getAttributeKeys(); for (Object key : keys) { attributes.put(key, session.getAttribute(key)); } session.stop(); session = subject.getSession(); for (Entry<Object, Object> entry : attributes.entrySet()) { session.setAttribute(entry.getKey(), entry.getValue()); } return super.onLoginSuccess(token, subject, servletRequest, servletResponse); }
From source file:com.flowlogix.ejb.StatefulUtil.java
License:Apache License
/** * Pings all pingable SFSBs in the session * //from w w w. j av a 2 s. co m * @param session * @return true if successful, false if any of the pings failed */ public static boolean pingStateful(Session session) { boolean rv = true; List<String> attrNames = FluentIterable.from(session.getAttributeKeys()) .transform(new Function<Object, String>() { @Override public String apply(Object f) { if (f instanceof String) { return (String) f; } else { return null; } } }).filter(Predicates.and(Predicates.notNull(), Predicates.contains(ejbPattern))).toList(); for (String attrName : attrNames) { synchronized (session.getId().toString().intern()) { try { Object _pingable = session.getAttribute(attrName); if (_pingable instanceof Pingable) { Pingable pingable = (Pingable) _pingable; pingable.ping(); } } catch (EJBException e) { log.debug("Failed to Ping Stateful EJB: ", e); rv = false; // signal failure if any of the pings fail session.removeAttribute(attrName); } } } return rv; }
From source file:com.flowlogix.security.cdi.ShiroSessionScopeContext.java
License:Apache License
public <T> void onDestroy(Session session) { List<String> attrNames = FluentIterable.from(session.getAttributeKeys()) .transform(new Function<Object, String>() { @Override//w w w . j a v a2 s .c o m public String apply(Object f) { return f instanceof String ? (String) f : null; } }).filter(Predicates.and(Predicates.notNull(), Predicates.contains(bpPattern))).toList(); for (String attrName : attrNames) { @SuppressWarnings("unchecked") ScopeInst<T> scopeInst = (ScopeInst<T>) session.getAttribute(attrName); if (scopeInst != null) { scopeInst.bean.destroy(scopeInst.instance, scopeInst.context); } } }
From source file:com.ikanow.aleph2.security.db.SessionDb.java
License:Apache License
protected JsonNode serialize(Object session) { ObjectNode sessionOb = null;// ww w .j a v a 2 s. c o m if (session instanceof Session) { Session s = (Session) session; ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); sessionOb = mapper.createObjectNode(); sessionOb.put("_id", s.getId().toString()); sessionOb.put("last_access_time", s.getLastAccessTime().getTime()); sessionOb.put("start_time_stamp", s.getStartTimestamp().getTime()); sessionOb.put("timeout", s.getTimeout()); sessionOb.put("host", s.getHost()); ObjectNode attributesOb = sessionOb.putObject("attributes"); for (Iterator<Object> it = s.getAttributeKeys().iterator(); it.hasNext();) { Object key = it.next(); Object value = s.getAttribute(key); if (value != null) { // base64 encode objects in session logger.debug("Storing session attribute:" + key + "=" + value); attributesOb.put(escapeMongoCharacters("" + key), SerializableUtils.serialize(value)); } } } return sessionOb; }
From source file:com.ikanow.aleph2.security.service.IkanowV2SecurityServiceTest.java
License:Apache License
@Test public void testSessionDb() { SessionDb sessionDb = new SessionDb(_service_context); Session session1 = mock(Session.class); when(session1.getId()).thenReturn("123"); when(session1.getHost()).thenReturn("localhost"); Date now = new Date(); when(session1.getLastAccessTime()).thenReturn(now); when(session1.getStartTimestamp()).thenReturn(now); when(session1.getTimeout()).thenReturn(1000L * 60L); when(session1.getAttributeKeys()).thenReturn(Arrays.asList("currentUser")); when(session1.getAttribute(any())).thenReturn("doesnotexist@ikanow.com"); sessionDb.store(session1);//from w w w. ja v a 2s .c o m Session session2 = (Session) sessionDb.loadById("123"); assertNotNull(session2); assertEquals(session1.getId(), session2.getId()); assertEquals(session1.getHost(), session2.getHost()); assertEquals(session1.getLastAccessTime(), session2.getLastAccessTime()); assertEquals(session1.getStartTimestamp(), session2.getStartTimestamp()); assertEquals(session1.getAttribute("currentUser"), session2.getAttribute("currentUser")); sessionDb.delete("123"); Session session3 = (Session) sessionDb.loadById("123"); assertNull(session3); }
From source file:com.panlingxiao.shiro.spring.web.IndexController.java
License:Apache License
protected Map<String, Object> referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { Subject subject = SecurityUtils.getSubject(); boolean hasRole1 = subject.hasRole("role1"); boolean hasRole2 = subject.hasRole("role2"); Map<String, Object> refData = new HashMap<String, Object>(); refData.put("hasRole1", hasRole1); refData.put("hasRole2", hasRole2); Session session = subject.getSession(); Map<Object, Object> sessionAttributes = new LinkedHashMap<Object, Object>(); for (Object key : session.getAttributeKeys()) { sessionAttributes.put(key, session.getAttribute(key)); }//from w w w. ja v a 2s . c o m refData.put("sessionAttributes", sessionAttributes); refData.put("subjectSession", subject.getSession()); return refData; }
From source file:com.xc.xnode.shiro.AuthenticationFilter.java
License:Open Source License
@Override protected boolean onLoginSuccess(org.apache.shiro.authc.AuthenticationToken token, Subject subject, ServletRequest servletRequest, ServletResponse servletResponse) throws Exception { Session session = subject.getSession(); Map<Object, Object> attributes = new HashMap<Object, Object>(); Collection<Object> keys = session.getAttributeKeys(); for (Object key : keys) { attributes.put(key, session.getAttribute(key)); }/*from w ww . j a v a 2 s.com*/ session.stop(); session = subject.getSession(); for (Entry<Object, Object> entry : attributes.entrySet()) { session.setAttribute(entry.getKey(), entry.getValue()); } // WebUtils.issueRedirect(servletRequest, servletResponse, getSuccessUrl(), null, true); // return false; return super.onLoginSuccess(token, subject, servletRequest, servletResponse); }