当前位置: 首页>>代码示例>>Java>>正文


Java SimpleSession类代码示例

本文整理汇总了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));
				}
			}
		}
	}
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:20,代码来源:DefaultSessionManager.java

示例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();
    }
}
 
开发者ID:iBase4J,项目名称:iBase4J-Common,代码行数:15,代码来源:RedisSessionDAO.java

示例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);
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:20,代码来源:FileBasedSessionDAO.java

示例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.
}
 
开发者ID:line,项目名称:centraldogma,代码行数:23,代码来源:StandaloneCommandExecutor.java

示例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;
			}
		}
	}
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:26,代码来源:SimpleSessionManager.java

示例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());
}
 
开发者ID:wu560130911,项目名称:MultimediaDesktop,代码行数:25,代码来源:UserAdminManagerController.java

示例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;
}
 
开发者ID:litesolutions,项目名称:scm-ssh-plugin,代码行数:23,代码来源:ScmPublickeyAuthenticator.java

示例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;
}
 
开发者ID:litesolutions,项目名称:scm-ssh-plugin,代码行数:23,代码来源:ScmPasswordAuthenticator.java

示例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;
	}
}
 
开发者ID:funtl,项目名称:framework,代码行数:11,代码来源:SessionManager.java

示例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;
}
 
开发者ID:iBase4J,项目名称:iBase4J-Common,代码行数:14,代码来源:RedisSessionDAO.java

示例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));
}
 
开发者ID:line,项目名称:centraldogma,代码行数:14,代码来源:FileBasedSessionDAO.java

示例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();
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:10,代码来源:FileBasedSessionDAO.java

示例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()));
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:12,代码来源:SimpleSessionJsonSerializer.java

示例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
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:12,代码来源:SimpleSessionJsonDeserializer.java

示例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");
}
 
开发者ID:line,项目名称:centraldogma,代码行数:11,代码来源:CreateSessionCommand.java


注:本文中的org.apache.shiro.session.mgt.SimpleSession类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。