@Test public void testSessionManagerProxyNonStartRemoteInvocation() throws Exception { SecureRemoteInvocationFactory factory = new SecureRemoteInvocationFactory(); MethodInvocation mi = createMock(MethodInvocation.class); Method method = getMethod("getSession", SessionManager.class); expect(mi.getMethod()).andReturn(method).anyTimes(); String dummySessionId = UUID.randomUUID().toString(); SessionKey sessionKey = new DefaultSessionKey(dummySessionId); Object[] args = {sessionKey}; expect(mi.getArguments()).andReturn(args).anyTimes(); replay(mi); RemoteInvocation ri = factory.createRemoteInvocation(mi); verify(mi); assertEquals(dummySessionId, ri.getAttribute(SecureRemoteInvocationFactory.SESSION_ID_KEY)); }
public RemoteInvocation createRemoteInvocation(MethodInvocation mi) { Serializable sessionId = null; String host = null; boolean sessionManagerMethodInvocation = false; Class miDeclaringClass = mi.getMethod().getDeclaringClass(); if (SessionManager.class.equals(miDeclaringClass) || NativeSessionManager.class.equals(miDeclaringClass)) { sessionManagerMethodInvocation = true; if (!mi.getMethod().getName().equals("start")) { SessionKey key = (SessionKey) mi.getArguments()[0]; sessionId = key.getSessionId(); } } if (sessionId == null) sessionId = this.sessionId; if (sessionId == null) { try { SecurityUtils.getSecurityManager(); if (!sessionManagerMethodInvocation) { Subject subject = SecurityUtils.getSubject(); Session session = subject.getSession(false); if (session != null) { sessionId = session.getId(); host = session.getHost(); } } } catch (Exception e) { log.trace("No security manager set. Trying next to get session id from system property"); } } if (sessionId == null) { if (log.isTraceEnabled()) { log.trace("No Session found for the currently executing subject via subject.getSession(false). " + "Attempting to revert back to the 'shiro.session.id' system property..."); } sessionId = System.getProperty(SESSION_ID_SYSTEM_PROPERTY_NAME); if (sessionId == null && log.isTraceEnabled()) { log.trace("No 'shiro.session.id' system property found. Heuristics have been exhausted; " + "RemoteInvocation will not contain a sessionId."); } } RemoteInvocation ri = new RemoteInvocation(mi); if (sessionId != null) { ri.addAttribute(SESSION_ID_KEY, sessionId); } if (host != null) { ri.addAttribute(HOST_KEY, host); } return ri; }
SecureRemoteInvocationFactory extends DefaultRemoteInvocationFactory { public RemoteInvocation createRemoteInvocation(MethodInvocation mi) { Serializable sessionId = null; String host = null; boolean sessionManagerMethodInvocation = false; Class miDeclaringClass = mi.getMethod().getDeclaringClass(); if (SessionManager.class.equals(miDeclaringClass) || NativeSessionManager.class.equals(miDeclaringClass)) { sessionManagerMethodInvocation = true; if (!mi.getMethod().getName().equals("start")) { SessionKey key = (SessionKey) mi.getArguments()[0]; sessionId = key.getSessionId(); } } if (sessionId == null) sessionId = this.sessionId; if (sessionId == null) { try { SecurityUtils.getSecurityManager(); if (!sessionManagerMethodInvocation) { Subject subject = SecurityUtils.getSubject(); Session session = subject.getSession(false); if (session != null) { sessionId = session.getId(); host = session.getHost(); } } } catch (Exception e) { log.trace("No security manager set. Trying next to get session id from system property"); } } if (sessionId == null) { if (log.isTraceEnabled()) { log.trace("No Session found for the currently executing subject via subject.getSession(false). " + "Attempting to revert back to the 'shiro.session.id' system property..."); } sessionId = System.getProperty(SESSION_ID_SYSTEM_PROPERTY_NAME); if (sessionId == null && log.isTraceEnabled()) { log.trace("No 'shiro.session.id' system property found. Heuristics have been exhausted; " + "RemoteInvocation will not contain a sessionId."); } } RemoteInvocation ri = new RemoteInvocation(mi); if (sessionId != null) { ri.addAttribute(SESSION_ID_KEY, sessionId); } if (host != null) { ri.addAttribute(HOST_KEY, host); } return ri; } }
SecureRemoteInvocationFactory extends DefaultRemoteInvocationFactory { public RemoteInvocation createRemoteInvocation(MethodInvocation mi) { Serializable sessionId = null; String host = null; boolean sessionManagerMethodInvocation = false; Class miDeclaringClass = mi.getMethod().getDeclaringClass(); if (SessionManager.class.equals(miDeclaringClass) || NativeSessionManager.class.equals(miDeclaringClass)) { sessionManagerMethodInvocation = true; if (!mi.getMethod().getName().equals("start")) { SessionKey key = (SessionKey) mi.getArguments()[0]; sessionId = key.getSessionId(); } } if (sessionId == null) sessionId = this.sessionId; if (sessionId == null) { try { SecurityUtils.getSecurityManager(); if (!sessionManagerMethodInvocation) { Subject subject = SecurityUtils.getSubject(); Session session = subject.getSession(false); if (session != null) { sessionId = session.getId(); host = session.getHost(); } } } catch (Exception e) { log.trace("No security manager set. Trying next to get session id from system property"); } } if (sessionId == null) { if (log.isTraceEnabled()) { log.trace("No Session found for the currently executing subject via subject.getSession(false). " + "Attempting to revert back to the 'shiro.session.id' system property..."); } sessionId = System.getProperty(SESSION_ID_SYSTEM_PROPERTY_NAME); if (sessionId == null && log.isTraceEnabled()) { log.trace("No 'shiro.session.id' system property found. Heuristics have been exhausted; " + "RemoteInvocation will not contain a sessionId."); } } RemoteInvocation ri = new RemoteInvocation(mi); if (sessionId != null) { ri.addAttribute(SESSION_ID_KEY, sessionId); } if (host != null) { ri.addAttribute(HOST_KEY, host); } return ri; } SecureRemoteInvocationFactory();  SecureRemoteInvocationFactory(String sessionId); }
SecureRemoteInvocationFactory extends DefaultRemoteInvocationFactory { public RemoteInvocation createRemoteInvocation(MethodInvocation mi) { Serializable sessionId = null; String host = null; boolean sessionManagerMethodInvocation = false; Class miDeclaringClass = mi.getMethod().getDeclaringClass(); if (SessionManager.class.equals(miDeclaringClass) || NativeSessionManager.class.equals(miDeclaringClass)) { sessionManagerMethodInvocation = true; if (!mi.getMethod().getName().equals("start")) { SessionKey key = (SessionKey) mi.getArguments()[0]; sessionId = key.getSessionId(); } } if (sessionId == null) sessionId = this.sessionId; if (sessionId == null) { try { SecurityUtils.getSecurityManager(); if (!sessionManagerMethodInvocation) { Subject subject = SecurityUtils.getSubject(); Session session = subject.getSession(false); if (session != null) { sessionId = session.getId(); host = session.getHost(); } } } catch (Exception e) { log.trace("No security manager set. Trying next to get session id from system property"); } } if (sessionId == null) { if (log.isTraceEnabled()) { log.trace("No Session found for the currently executing subject via subject.getSession(false). " + "Attempting to revert back to the 'shiro.session.id' system property..."); } sessionId = System.getProperty(SESSION_ID_SYSTEM_PROPERTY_NAME); if (sessionId == null && log.isTraceEnabled()) { log.trace("No 'shiro.session.id' system property found. Heuristics have been exhausted; " + "RemoteInvocation will not contain a sessionId."); } } RemoteInvocation ri = new RemoteInvocation(mi); if (sessionId != null) { ri.addAttribute(SESSION_ID_KEY, sessionId); } if (host != null) { ri.addAttribute(HOST_KEY, host); } return ri; } SecureRemoteInvocationFactory();  SecureRemoteInvocationFactory(String sessionId); RemoteInvocation createRemoteInvocation(MethodInvocation mi); }
SecureRemoteInvocationFactory extends DefaultRemoteInvocationFactory { public RemoteInvocation createRemoteInvocation(MethodInvocation mi) { Serializable sessionId = null; String host = null; boolean sessionManagerMethodInvocation = false; Class miDeclaringClass = mi.getMethod().getDeclaringClass(); if (SessionManager.class.equals(miDeclaringClass) || NativeSessionManager.class.equals(miDeclaringClass)) { sessionManagerMethodInvocation = true; if (!mi.getMethod().getName().equals("start")) { SessionKey key = (SessionKey) mi.getArguments()[0]; sessionId = key.getSessionId(); } } if (sessionId == null) sessionId = this.sessionId; if (sessionId == null) { try { SecurityUtils.getSecurityManager(); if (!sessionManagerMethodInvocation) { Subject subject = SecurityUtils.getSubject(); Session session = subject.getSession(false); if (session != null) { sessionId = session.getId(); host = session.getHost(); } } } catch (Exception e) { log.trace("No security manager set. Trying next to get session id from system property"); } } if (sessionId == null) { if (log.isTraceEnabled()) { log.trace("No Session found for the currently executing subject via subject.getSession(false). " + "Attempting to revert back to the 'shiro.session.id' system property..."); } sessionId = System.getProperty(SESSION_ID_SYSTEM_PROPERTY_NAME); if (sessionId == null && log.isTraceEnabled()) { log.trace("No 'shiro.session.id' system property found. Heuristics have been exhausted; " + "RemoteInvocation will not contain a sessionId."); } } RemoteInvocation ri = new RemoteInvocation(mi); if (sessionId != null) { ri.addAttribute(SESSION_ID_KEY, sessionId); } if (host != null) { ri.addAttribute(HOST_KEY, host); } return ri; } SecureRemoteInvocationFactory();  SecureRemoteInvocationFactory(String sessionId); RemoteInvocation createRemoteInvocation(MethodInvocation mi); static final String SESSION_ID_KEY; static final String HOST_KEY; }