本文整理汇总了Java中org.apache.shiro.session.mgt.SimpleSession类的典型用法代码示例。如果您正苦于以下问题:Java SimpleSession类的具体用法?Java SimpleSession怎么用?Java SimpleSession使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleSession类属于org.apache.shiro.session.mgt包,在下文中一共展示了SimpleSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateSessions
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
@Override
public void validateSessions() {
Collection<?> activeSessions = getActiveSessions();
if (null != activeSessions && !activeSessions.isEmpty()) {
for (Iterator<?> i$ = activeSessions.iterator(); i$.hasNext();) {
Session session = (Session) i$.next();
try {
SessionKey key = new DefaultSessionKey(session.getId());
validate(session, key);
} catch (InvalidSessionException e) {
if (null != cacheManager) {
SimpleSession s = (SimpleSession) session;
if (null != s.getAttribute(Constant.SESSION_ID))
cacheManager.getCache(null).remove(s.getAttribute(Constant.SESSION_ID));
}
}
}
}
}
示例2: doReadSession
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
protected Session doReadSession(Serializable sessionId) {
byte[] sessionKey = buildRedisSessionKey(sessionId);
RedisConnection redisConnection = getRedisConnection();
try {
byte[] value = redisConnection.get(sessionKey);
if (value == null) {
return null;
}
Session session = SerializeUtil.deserialize(value, SimpleSession.class);
return session;
} finally {
redisConnection.close();
}
}
示例3: readSession
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
@Override
public SimpleSession readSession(Serializable sessionIdObj) {
final String sessionId = ensureStringSessionId(sessionIdObj);
final SimpleSession cachedSession = getFromCache(sessionId);
if (cachedSession != null) {
return cachedSession;
}
try {
final SimpleSession session = uncachedRead(sessionId);
updateCache(sessionId, session);
return session;
} catch (FileNotFoundException | NoSuchFileException unused) {
// Unknown session
throw new UnknownSessionException(sessionId);
} catch (ClassNotFoundException | IOException e) {
throw new SerializationException(e);
}
}
示例4: createSession
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
private CompletableFuture<Void> createSession(String replicaId, CreateSessionCommand c) {
if (securityManager == null) {
// Security has been disabled for this replica.
return CompletableFuture.completedFuture(null);
}
if (replicaId().equals(replicaId)) {
// The session commands are used only for replication of session events.
// We do not use them for local changes, because Shiro persisted them via SessionDAO already.
return CompletableFuture.completedFuture(null);
}
return CompletableFuture.supplyAsync(() -> {
final SimpleSession session = c.session();
try {
securityManager.createSession(session);
} catch (Throwable t) {
logger.warn("Failed to replicate a session creation: {}", session, t);
}
return null;
}, repositoryWorker); // Not really a repository update, but it will not hurt.
}
示例5: setAttribute
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
@Override
public void setAttribute(SessionKey sessionKey, Object attributeKey, Object value) throws InvalidSessionException {
try {
super.setAttribute(sessionKey, attributeKey, value);
} catch (UnknownSessionException e) {
Subject subject = ThreadContext.getSubject();
if ((value instanceof PrincipalCollection) && sessionDAO != null && subject != null
&& (subject instanceof DelegatingSubject)) {
try {
SessionContext sessionContext = createSessionContext(((DelegatingSubject) subject).getHost());
Session session = newSessionInstance(sessionContext);
session.setAttribute(attributeKey, value);
session.setTimeout(getGlobalSessionTimeout());
((SimpleSession) session).setId(sessionKey.getSessionId());
sessionDAO.create(session);
} catch (Exception ex) {
throw e;
}
} else {
if (!(value instanceof SavedRequest)) {
throw e;
}
}
}
}
示例6: getOnlineUsers
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
@RequestMapping("admin/userManager/userOnlineStore")
public void getOnlineUsers(Model model) {
Iterator<Session> sessions = sessionDao.getActiveSessions().iterator();
ArrayList<OnlineUser> ous = new ArrayList<OnlineUser>();
while (sessions.hasNext()) {
OnlineUser ou = new OnlineUser();
SimpleSession session = (SimpleSession) sessions.next();
ou.setHost(session.getHost());
ou.setId(session.getId().toString());
ou.setLastAccessTime(session.getLastAccessTime());
ou.setStartTime(session.getStartTimestamp());
PrincipalCollection principal = (PrincipalCollection) session
.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
if (principal != null) {
ShiroUser su = (ShiroUser) principal.getPrimaryPrincipal();
ou.setUserid(su.loginName);
ou.setUsername(su.name);
ou.setLogin(true);
}
ous.add(ou);
}
model.addAttribute("users", ous);
model.addAttribute("total", ous.size());
}
示例7: authenticate
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
@Override
public boolean authenticate(String username, PublicKey publicKey,
ServerSession session) {
if (username == null || publicKey == null) {
return false;
}
SimpleSession shiroSession = new SimpleSession();
shiroSession.setTimeout(-1L);
Subject subject = new Subject.Builder(securityManager)
.session(shiroSession)
.host(session.getIoSession().getRemoteAddress().toString())
.buildSubject();
try {
subject.login(new PublicKeyToken(username, publicKey));
} catch (AuthenticationException e) {
return false;
}
// Store subject in session.
session.setAttribute(ScmSshServer.SUBJECT_SESSION_ATTRIBUTE_KEY,
subject);
return true;
}
示例8: authenticate
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
@Override
public boolean authenticate(String username, String password,
ServerSession session) {
if (username == null || password == null) {
return false;
}
SimpleSession shiroSession = new SimpleSession();
shiroSession.setTimeout(-1L);
Subject subject = new Subject.Builder(securityManager)
.session(shiroSession)
.host(session.getIoSession().getRemoteAddress().toString())
.buildSubject();
try {
subject.login(new UsernamePasswordToken(username, password));
} catch (AuthenticationException e) {
return false;
}
// Store subject in session.
session.setAttribute(ScmSshServer.SUBJECT_SESSION_ATTRIBUTE_KEY,
subject);
return true;
}
示例9: start
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
@Override
public Session start(SessionContext context) {
try {
return super.start(context);
} catch (NullPointerException e) {
SimpleSession session = new SimpleSession();
session.setId(0);
return session;
}
}
示例10: getActiveSessions
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
public Collection<Session> getActiveSessions() {
List<Session> list = InstanceUtil.newArrayList();
RedisConnection redisConnection = getRedisConnection();
try {
Set<byte[]> set = redisConnection.keys((Constants.REDIS_SHIRO_SESSION + "*").getBytes());
for (byte[] key : set) {
list.add(SerializeUtil.deserialize(redisConnection.get(key), SimpleSession.class));
}
} finally {
redisConnection.close();
}
return list;
}
示例11: exists
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
/**
* Returns whether the session with the given ID exists.
*/
public boolean exists(String sessionId) {
requireNonNull(sessionId, "sessionId");
final SimpleSession cachedSession = getFromCache(sessionId);
if (cachedSession != null) {
return true;
}
return Files.isRegularFile(sessionId2Path(sessionId));
}
示例12: deserialize
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
/**
* Deserializes a {@link Session} from a byte array using an {@link ObjectInputStream}.
*/
static SimpleSession deserialize(byte[] encoded) throws IOException, ClassNotFoundException {
try (ByteArrayInputStream bais = new ByteArrayInputStream(encoded);
ObjectInputStream ois = new ObjectInputStream(bais)) {
return (SimpleSession) ois.readObject();
}
}
示例13: serialize
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
@Override
public void serialize(SimpleSession value, JsonGenerator gen, SerializerProvider provider)
throws IOException {
try (ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
ObjectOutputStream oos = new ObjectOutputStream(baos)) {
oos.writeObject(value);
oos.flush();
gen.writeString(Base64.getEncoder().encodeToString(baos.toByteArray()));
}
}
示例14: deserialize
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
@Override
public SimpleSession deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
try (ByteArrayInputStream bais =
new ByteArrayInputStream(Base64.getDecoder().decode(p.readValueAs(String.class)));
ObjectInputStream ois = new ObjectInputStream(bais)) {
return (SimpleSession) ois.readObject();
} catch (ClassNotFoundException e) {
ctxt.reportInputMismatch(SimpleSession.class, "failed to deserialize a session: " + e);
throw new Error(); // Should never reach here
}
}
示例15: CreateSessionCommand
import org.apache.shiro.session.mgt.SimpleSession; //导入依赖的package包/类
@JsonCreator
CreateSessionCommand(@JsonProperty("timestamp") @Nullable Long timestamp,
@JsonProperty("author") @Nullable Author author,
@JsonProperty("session")
@JsonDeserialize(using = SimpleSessionJsonDeserializer.class)
SimpleSession session) {
super(CommandType.CREATE_SESSION, timestamp, author);
this.session = requireNonNull(session, "session");
}