List of usage examples for org.apache.shiro.spring.remoting SecureRemoteInvocationFactory SESSION_ID_KEY
String SESSION_ID_KEY
To view the source code for org.apache.shiro.spring.remoting SecureRemoteInvocationFactory SESSION_ID_KEY.
Click Source Link
From source file:info.novatec.inspectit.cmr.spring.exporter.SessionAwareSecureRemoteInvocationExecutor.java
License:Apache License
/** * {@inheritDoc}// w w w . jav a 2 s .c om */ @Override public Object invoke(final RemoteInvocation invocation, final Object targetObject) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { try { Subject.Builder builder = new Subject.Builder(securityManager); String host = (String) invocation.getAttribute(SecureRemoteInvocationFactory.HOST_KEY); if (host != null) { builder.host(host); } Serializable sessionId = invocation.getAttribute(SecureRemoteInvocationFactory.SESSION_ID_KEY); if (sessionId != null) { builder.sessionId(sessionId); } Subject subject = builder.buildSubject(); return subject.execute(new Callable<Object>() { public Object call() throws Exception { // This is the part which is significantly modified to set the session id thread local manually. Object result = SessionAwareSecureRemoteInvocationExecutor.super.invoke(invocation, targetObject); Object sessionId = null; Session session = SecurityUtils.getSubject().getSession(false); if (null != session) { sessionId = session.getId(); } sessionIdThreadLocal.set(sessionId); return result; } }); } catch (ExecutionException e) { Throwable cause = e.getCause(); if ((cause instanceof NoSuchMethodException)) { throw ((NoSuchMethodException) cause); // NOPMD } if ((cause instanceof IllegalAccessException)) { throw ((IllegalAccessException) cause); // NOPMD } if ((cause instanceof InvocationTargetException)) { throw ((InvocationTargetException) cause); // NOPMD } throw new InvocationTargetException(cause); // NOPMD } catch (Throwable t) { // NOPMD throw new InvocationTargetException(t); } }