use of org.apache.shiro.session.Session in project shiro by apache.
the class DefaultSampleManager method getValue.
/*--------------------------------------------
| C O N S T R U C T O R S |
============================================*/
/*--------------------------------------------
| A C C E S S O R S / M O D I F I E R S |
============================================*/
/*--------------------------------------------
| M E T H O D S |
============================================*/
public String getValue() {
String value = null;
Subject subject = SecurityUtils.getSubject();
Session session = subject.getSession(false);
if (session != null) {
value = (String) session.getAttribute(VALUE_KEY);
if (log.isDebugEnabled()) {
log.debug("retrieving session key [" + VALUE_KEY + "] with value [" + value + "] on session with id [" + session.getId() + "]");
}
}
return value;
}
use of org.apache.shiro.session.Session in project shiro by apache.
the class IndexController method referenceData.
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));
}
refData.put("sessionAttributes", sessionAttributes);
refData.put("subjectSession", subject.getSession());
return refData;
}
use of org.apache.shiro.session.Session in project shiro by apache.
the class ShiroSessionScope method scope.
public <T> Provider<T> scope(final Key<T> key, final Provider<T> unscoped) {
return new Provider<T>() {
public T get() {
Subject subject = ThreadContext.getSubject();
if (subject == null) {
throw new OutOfScopeException("There is no Shiro Session currently in scope.");
}
Session session = subject.getSession();
T scoped = castSessionAttribute(session);
if (scoped == null) {
scoped = unscoped.get();
}
return scoped;
}
@SuppressWarnings({ "unchecked" })
private T castSessionAttribute(Session session) {
return (T) session.getAttribute(key);
}
@Override
public String toString() {
return unscoped.toString();
}
};
}
use of org.apache.shiro.session.Session in project shiro by apache.
the class AbstractNativeSessionManager method stop.
public void stop(SessionKey key) throws InvalidSessionException {
Session session = lookupRequiredSession(key);
try {
if (log.isDebugEnabled()) {
log.debug("Stopping session with id [" + session.getId() + "]");
}
session.stop();
onStop(session, key);
notifyStop(session);
} finally {
afterStopped(session);
}
}
use of org.apache.shiro.session.Session in project shiro by apache.
the class AbstractNativeSessionManager method touch.
public void touch(SessionKey key) throws InvalidSessionException {
Session s = lookupRequiredSession(key);
s.touch();
onChange(s);
}
Aggregations