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


Java Subject.getSession方法代码示例

本文整理汇总了Java中org.apache.shiro.subject.Subject.getSession方法的典型用法代码示例。如果您正苦于以下问题:Java Subject.getSession方法的具体用法?Java Subject.getSession怎么用?Java Subject.getSession使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.shiro.subject.Subject的用法示例。


在下文中一共展示了Subject.getSession方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAccessAllowed

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@Override
protected boolean isAccessAllowed(ServletRequest request,
		ServletResponse response, Object mappedValue) throws Exception {

	HttpServletRequest httpRequest = ((HttpServletRequest)request);
	String url = httpRequest.getRequestURI();
	if(url.startsWith(ShiroUtils.OPENAPI)){
		return Boolean.TRUE;
	}
	Subject subject = getSubject(request, response);
	Session session = subject.getSession();
	SessionStatus sessionStatus = (SessionStatus) session.getAttribute(UserSessionServiceImpl.SESSION_STATUS);
	if (null != sessionStatus && !sessionStatus.isOnline()) {
		return  Boolean.FALSE;
	}
	return Boolean.TRUE;
}
 
开发者ID:wjggwm,项目名称:webside,代码行数:18,代码来源:KickoutAuthFilter.java

示例2: getCurrentUser

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
/** 获取当前用户 */
public static final Long getCurrentUser() {
	Subject currentUser = SecurityUtils.getSubject();
	if (null != currentUser) {
		try {
			Session session = currentUser.getSession();
			if (null != session) {
				return (Long) session.getAttribute(Constants.CURRENT_USER);
			}
		} catch (InvalidSessionException e) {
			logger.error(e);
		}
	}
	return null;
}
 
开发者ID:youngMen1,项目名称:JAVA-,代码行数:16,代码来源:WebUtil.java

示例3: setSession

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
/**
 * 将一些数据放到ShiroSession中,以便于其它地方使用
 * 
 * @see 比如Controller,使用时直接用HttpSession.getAttribute(key)就可以取到
 */
public static final void setSession(Object key, Object value) {
	Subject currentUser = SecurityUtils.getSubject();
	if (null != currentUser) {
		Session session = currentUser.getSession();
		if (null != session) {
			session.setAttribute(key, value);
		}
	}
}
 
开发者ID:youngMen1,项目名称:JAVA-,代码行数:15,代码来源:WebUtil.java

示例4: getSession

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
public Session getSession(){
	Session session = null;
	try{
		Subject subject = SecurityUtils.getSubject();
		session = subject.getSession(false);
		if (session == null){
			session = subject.getSession();
		}
	}catch (InvalidSessionException e){
		logger.error("Invalid session error", e);
	}catch (UnavailableSecurityManagerException e2){
		logger.error("Unavailable SecurityManager error", e2);
	}
	return session;
}
 
开发者ID:egojit8,项目名称:easyweb,代码行数:16,代码来源:SessionCacheManager.java

示例5: saveSession

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
/** 保存session */
private void saveSession(String account, String host) {
	// 踢出用户
	SysSession record = new SysSession();
	record.setAccount(account);
	Parameter parameter = new Parameter("sysSessionService", "querySessionIdByAccount").setModel(record);
	logger.info("{} execute querySessionIdByAccount start...", parameter.getNo());
	List<?> sessionIds = provider.execute(parameter).getList();
	logger.info("{} execute querySessionIdByAccount end.", parameter.getNo());
	Subject currentUser = SecurityUtils.getSubject();
	Session session = currentUser.getSession();
	String currentSessionId= session.getId().toString();
	if (sessionIds != null) {
		for (Object sessionId : sessionIds) {
			record.setSessionId((String) sessionId);
			parameter = new Parameter("sysSessionService", "deleteBySessionId").setModel(record);
			logger.info("{} execute deleteBySessionId start...", parameter.getNo());
			provider.execute(parameter);
			logger.info("{} execute deleteBySessionId end.", parameter.getNo());
			if (!currentSessionId.equals(sessionId)) {
				sessionRepository.delete((String) sessionId);
				sessionRepository.cleanupExpiredSessions();
			}
		}
	}
	// 保存用户
	record.setSessionId(currentSessionId);
	record.setIp(StringUtils.isBlank(host) ? session.getHost() : host);
	record.setStartTime(session.getStartTimestamp());
	parameter = new Parameter("sysSessionService", "update").setModel(record);
	logger.info("{} execute sysSessionService.update start...", parameter.getNo());
	provider.execute(parameter);
	logger.info("{} execute sysSessionService.update end.", parameter.getNo());
}
 
开发者ID:youngMen1,项目名称:JAVA-,代码行数:35,代码来源:Realm.java

示例6: setAuthenticationSession

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
/**
 * 将一些数据放到ShiroSession中,以便于其它地方使用
 * 比如Controller里面,使用时直接用HttpSession.getAttribute(key)就可以取到
 */
private void setAuthenticationSession(Object value){
    Subject currentUser = SecurityUtils.getSubject();
    if(null != currentUser){
        Session session = currentUser.getSession();
        System.out.println("当前Session超时时间为[" + session.getTimeout() + "]毫秒");
        session.setTimeout(1000 * 60 * 60 * 2);
        System.out.println("修改Session超时时间为[" + session.getTimeout() + "]毫秒");
        session.setAttribute("currentUser", value);
    }
}
 
开发者ID:v5java,项目名称:demo-springmvc-shiro,代码行数:15,代码来源:MyRealm.java

示例7: login

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@ApiOperation(value = "登录")
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(HttpServletRequest request) {
    Subject subject = SecurityUtils.getSubject();
    Session session = subject.getSession();
    String serverSessionId = session.getId().toString();
    // 判断是否已登录,如果已登录,则回跳
    String code = RedisUtil.get(ZHENG_UPMS_SERVER_SESSION_ID + "_" + serverSessionId);
    // code校验值
    if (StringUtils.isNotBlank(code)) {
        // 回跳
        String backurl = request.getParameter("backurl");
        String username = (String) subject.getPrincipal();
        if (StringUtils.isBlank(backurl)) {
            backurl = "/";
        } else {
            if (backurl.contains("?")) {
                backurl += "&upms_code=" + code + "&upms_username=" + username;
            } else {
                backurl += "?upms_code=" + code + "&upms_username=" + username;
            }
        }
        _log.debug("认证中心帐号通过,带code回跳:{}", backurl);
        return "redirect:" + backurl;
    }
    return "/sso/login.jsp";
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:28,代码来源:SSOController.java

示例8: isAccessAllowed

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
    Subject subject = getSubject(request, response);
    Session session = subject.getSession();
    // 判断请求类型
    String upmsType = PropertiesFileUtil.getInstance("zheng-upms-client").get("zheng.upms.type");
    session.setAttribute(UpmsConstant.UPMS_TYPE, upmsType);
    if ("client".equals(upmsType)) {
        return validateClient(request, response);
    }
    if ("server".equals(upmsType)) {
        return subject.isAuthenticated();
    }
    return false;
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:16,代码来源:UpmsAuthenticationFilter.java

示例9: logout

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@RequestMapping("/mlogoutUser")
public String logout(UUser user, Model model) throws IOException {
  Subject subject = SecurityUtils.getSubject();
  Session session = subject.getSession();
  session.removeAttribute("UserName");
  return "redirect:../login.jsp";
}
 
开发者ID:MiniPa,项目名称:cjs_ssms,代码行数:8,代码来源:UserManagerController.java

示例10: login

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@ApiOperation(value = "登录")
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(HttpServletRequest request) {
    Subject subject = SecurityUtils.getSubject();
    Session session = subject.getSession();
    String serverSessionId = session.getId().toString();
    // 判断是否已登录,如果已登录,则回跳
    String code = RedisUtil.get(ZHENG_UPMS_SERVER_SESSION_ID + "_" + serverSessionId);
    // code校验值
    if (StringUtils.isNotBlank(code)) {
        // 回跳
        String backurl = request.getParameter("backurl");
        String username = (String) subject.getPrincipal();
        if (StringUtils.isBlank(backurl)) {
            backurl = "/";
        } else {
            if (backurl.contains("?")) {
                backurl += "&upms_code=" + code + "&upms_username=" + username;
            } else {
                backurl += "?upms_code=" + code + "&upms_username=" + username;
            }
        }
        LOGGER.debug("认证中心帐号通过,带code回跳:{}", backurl);
        return "redirect:" + backurl;
    }
    return "/sso/login.jsp";
}
 
开发者ID:ChangyiHuang,项目名称:shuzheng,代码行数:28,代码来源:SSOController.java

示例11: saveSession

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
/** 保存session */
private void saveSession(String account, String host) {
	// 踢出用户
	SysSession record = new SysSession();
	record.setAccount(account);
	Parameter parameter = new Parameter("sysSessionService", "querySessionIdByAccount").setModel(record);
	logger.info("{} execute querySessionIdByAccount start...", parameter.getNo());
	List<?> sessionIds = provider.execute(parameter).getList();
	logger.info("{} execute querySessionIdByAccount end.", parameter.getNo());
	Subject currentUser = SecurityUtils.getSubject();
	Session session = currentUser.getSession();
	String currentSessionId = session.getId().toString();
	if (sessionIds != null) {
		for (Object sessionId : sessionIds) {
			record.setSessionId((String) sessionId);
			parameter = new Parameter("sysSessionService", "deleteBySessionId").setModel(record);
			logger.info("{} execute deleteBySessionId start...", parameter.getNo());
			provider.execute(parameter);
			logger.info("{} execute deleteBySessionId end.", parameter.getNo());
			if (!currentSessionId.equals(sessionId)) {
				sessionRepository.delete((String) sessionId);
				sessionRepository.cleanupExpiredSessions();
			}
		}
	}
	// 保存会话
	record.setSessionId(currentSessionId);
	record.setIp(StringUtils.isBlank(host) ? session.getHost() : host);
	record.setStartTime(session.getStartTimestamp());
	parameter = new Parameter("sysSessionService", "update").setModel(record);
	logger.info("{} execute sysSessionService.update start...", parameter.getNo());
	provider.execute(parameter);
	logger.info("{} execute sysSessionService.update end.", parameter.getNo());
}
 
开发者ID:youngMen1,项目名称:JAVA-,代码行数:35,代码来源:Realm.java

示例12: getCurrentUser

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
/** 获取当前用户 */
public static final Long getCurrentUser() {
	Subject currentUser = SecurityUtils.getSubject();
	if (null != currentUser) {
		try {
               Session session = currentUser.getSession();
               if (null != session) {
               	return (Long) session.getAttribute(Constants.CURRENT_USER);
               }
           } catch (InvalidSessionException e) {
               logger.error(e);
           }
	}
	return null;
}
 
开发者ID:tb544731152,项目名称:iBase4J,代码行数:16,代码来源:WebUtil.java

示例13: logout

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@RequestMapping("/logoutUser")
public String logout(UUser user, Model model) throws IOException {
  Subject subject = SecurityUtils.getSubject();
  Session session = subject.getSession();
  //session.removeAttribute("userName");
  session.removeAttribute("sysbUserName");
  return "redirect:/index.jsp";
}
 
开发者ID:MiniPa,项目名称:cjs_ssms,代码行数:9,代码来源:UserFrontController.java

示例14: setSession

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
/**
 * 
 * @param key
 * @param value
 */
private void setSession(Object key, Object value){
	Subject subject = SecurityUtils.getSubject();
	if(subject != null){
		Session session = subject.getSession();
		if(session != null){
			session.setAttribute(key, value);
		}
	}
}
 
开发者ID:xujeff,项目名称:tianti,代码行数:15,代码来源:ShiroDBRealm.java

示例15: isAccessAllowed

import org.apache.shiro.subject.Subject; //导入方法依赖的package包/类
@Override
protected boolean isAccessAllowed(ServletRequest req, ServletResponse resp, Object mappedValue) {
    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) resp;
    // 是登录页面 则直接返回true
    if (isLoginRequest(request, response)) {
        return true;
    }
    // 获取主题
    Subject subject = getSubject(request, response);
    //如果用户【已认证】 直接跳过
    if (subject.isAuthenticated()) {
        return true;
    }
    // 如果用户【未认证】 但是用户使用【记住我】功能
    if (subject.isRemembered()) {
        // 获取rememberMe的用户名称
        Object principal = subject.getPrincipal();
        if (null != principal) {
            //从session中 获取登录用户信息
            Session session = subject.getSession(true);
            MMSnsCommonUserEntity commonUser = (MMSnsCommonUserEntity) session.getAttribute(MMSnsCommonUserEntity.MMSNS_COMMON_USER);
            //如果session不保存用户信息;则从数据库中获取
            if (commonUser == null) {
                List<MMSnsCommonUserEntity> commonUsers = commonUserService.getCommonUserByCondition(principal.toString(), principal.toString(),principal.toString(),null,null);
                if (commonUser != null && commonUsers.size() > 0) {
                    session.setAttribute(MMSnsCommonUserEntity.MMSNS_COMMON_USER, commonUsers.get(0));
                }
            }
            return true;
        }
    }
    return false;
}
 
开发者ID:babymm,项目名称:mmsns,代码行数:35,代码来源:MMSnsRememberAuthenticationFilter.java


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