本文整理匯總了Java中org.apache.shiro.subject.Subject.isRemembered方法的典型用法代碼示例。如果您正苦於以下問題:Java Subject.isRemembered方法的具體用法?Java Subject.isRemembered怎麽用?Java Subject.isRemembered使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.subject.Subject
的用法示例。
在下文中一共展示了Subject.isRemembered方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: isAccessAllowed
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
@Override
protected boolean isAccessAllowed(ServletRequest request,
ServletResponse response, Object mappedValue) {
Subject subject = getSubject(request, response);
// 如果 isAuthenticated 為 false 證明不是登錄過的,同時 isRememberd 為true 證明是沒登陸直接通過記住我功能進來的
if (!subject.isAuthenticated() && subject.isRemembered()) {
// 獲取session的USERSESSION屬性來看session是不是空的
if(null == ShiroAuthenticationManager.getSessionAttribute(ShiroUtils.USERSESSION))
{
// 初始化
UserEntity userEntity = (UserEntity) subject.getPrincipal();
ShiroAuthenticationManager.setSessionAttribute(ShiroUtils.USERSESSION, userEntity);
}
}
// 這個方法本來隻返回 subject.isAuthenticated() 現在我們加上 subject.isRemembered()
// 讓它同時也兼容remember這種情況
return subject.isAuthenticated() || subject.isRemembered();
}
示例2: isAccessAllowed
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
// 是登錄頁麵 則直接返回true
if (isLoginRequest(request, response)) {
return true;
} else {
// 獲取主題
Subject subject = getSubject(request, response);
// 如果用戶【未認證】 但是用戶使用【記住我】功能
if (!subject.isAuthenticated() && subject.isRemembered()) {
// 獲取rememberMe的用戶名稱
Object principal = subject.getPrincipal();
if (null != principal) {
//從session中 獲取登錄用戶信息
//Session session = subject.getSession(true);
//User sessionUser = (User) session.getAttribute(User.SESSION_USER);
//如果session不保存用戶信息;則從數據庫中獲取
//if (sessionUser == null) {
// sessionUser = userService.getUserByName(String.valueOf(principal));
// subject.getSession().setAttribute(User.SESSION_USER, sessionUser);
//}
return true;
}
}
}
return true;
}
示例3: isAccessAllowed
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
HttpServletRequest req = (HttpServletRequest) request;
System.out.println("驗證登陸信息==" + req.getRequestURI());
System.out.println("sessionId==" + req.getSession().getId());
Subject currentUser = SecurityUtils.getSubject();
if (null != currentUser) {
if (currentUser.isAuthenticated() || currentUser.isRemembered()) {
return true;
}
}
// 返回false表示不執行後續的過濾器
return false;
}
示例4: isAccessAllowed
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
/**
* 判斷是否讓用戶登陸
*/
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
Subject subject = getSubject(request, response);
return subject.isAuthenticated() || subject.isRemembered();
}
示例5: init
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
@Override
protected void init(VaadinRequest request) {
LOGGER.debug("init - request = " + request);
Subject subject = SecurityUtils.getSubject();
boolean remembered = subject.isRemembered();
if (! (user().isPresent() && remembered)) setContent(login());
setSizeFull();
}
示例6: 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;
}