當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。