本文整理匯總了Java中org.apache.shiro.subject.Subject.isAuthenticated方法的典型用法代碼示例。如果您正苦於以下問題:Java Subject.isAuthenticated方法的具體用法?Java Subject.isAuthenticated怎麽用?Java Subject.isAuthenticated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.shiro.subject.Subject
的用法示例。
在下文中一共展示了Subject.isAuthenticated方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getGroups
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
@ApiOperation("獲取小組列表")
@GetMapping
public ResponseEntity getGroups(@RequestParam("page") int page,
@RequestParam("page_size") int pageSize,
@RequestParam(name = "owner", required = false, defaultValue = "0") int owner) {
if (owner > 0) {
// 鑒權
Subject subject = SecurityUtils.getSubject();
if (! subject.isAuthenticated()) {
throw new UnauthorizedException();
}
int uid = SessionHelper.get().getUid();
if (uid != owner) {
throw new UnauthorizedException();
}
PageRowBounds pager = new PageRowBounds(page, pageSize);
List<GroupEntity> groups = groupService.getGroups(uid, pager);
Map<String, Object> data = new HashMap<>(2);
data.put("data", groups);
data.put("total", pager.getTotal());
return new ResponseEntity(data);
} else {
return new ResponseEntity(new ArrayList<>());
}
}
示例2: login
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(@Valid LoginAO loginForm, BindingResult result) {
if (result.hasErrors()) {
return "login";
}
UsernamePasswordToken token = new UsernamePasswordToken(loginForm.getUserName(), loginForm.getPassword());
Subject subject = SecurityUtils.getSubject();
subject.login(token);
if (subject.isAuthenticated()) {
//登錄成功,數據初始化
//1,session信息,用戶名,上次登錄時間信息
//2,菜單列表信息
//3,係統該要信息,待辦事項
return "redirect:/index";
} else {
token.clear();
return "login";
}
}
示例3: 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();
}
示例4: 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;
}
示例5: doGet
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Subject subject = SecurityUtils.getSubject();
if (subject.isAuthenticated()) {
subject.logout(); // session 會銷毀,在SessionListener監聽session銷毀,清理權限緩存
System.out.println("退出成功");
}
response.sendRedirect("login.jsp");
}
示例6: auth
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
public static void auth(final String[] filters) {
final Filter f = (req, res) -> {
final Subject currentUser = SecurityUtils.getSubject();
if (!currentUser.isAuthenticated()) {
// 未授權
halt(401, "You don't have permission to access it.");
}
};
// add auth before protected routes.
for (String filter : filters) {
before(filter, f);
}
}
示例7: index
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
@RequestMapping("")
public String index(HttpServletRequest request, String redirectUrl, Model model) {
if (redirectUrl != null && !redirectUrl.startsWith(request.getContextPath() + "/")) {
redirectUrl = null;
}
Subject subject = SecurityUtils.getSubject();
if(subject.isAuthenticated()){
return "redirect:/";
}
model.addAttribute("captchaId", UUID.randomUUID().toString());
model.addAttribute("redirectUrl", redirectUrl);
return "/login/index";
}
示例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("lambo-upms-client").get("lambo.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;
}
示例9: 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;
}
示例10: 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;
}
示例11: login
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
/**
* @return
*/
@RequestMapping(method = RequestMethod.GET)
public String login() {
Subject subjec = SecurityUtils.getSubject();
if (subjec != null && subjec.isAuthenticated()) {
return "redirect:/admin";
}
return "login";
}
示例12: 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();
}
示例13: isAccessAllowed
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
protected boolean isAccessAllowed(ServletRequest request,
ServletResponse response, Object mappedValue) {
Subject subject = getSubject(request, response);
return subject.isAuthenticated();
}
示例14: restlogin
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
/**
* 前後端分離的情況之下rest風格登錄獲取TGT ST
* @Description:TODO
* @author:hsj qq:2356899074
* @time:2017年12月1日 下午2:49:40
* @param req
* @param respon
* @return
* @throws Exception
*/
@RequestMapping("/restlogin")
public String restlogin(HttpServletRequest req,HttpServletResponse respon)throws Exception{
// return RestFulLogin.validateFromCAS("hsjhsj", "hsjhsj");
//校驗有沒有username和password
String username = "hsjhsj";
UsernamePasswordToken token = new UsernamePasswordToken("hsjhsj","hsjhsj");
//獲取當前的Subject
Subject currentUser = SecurityUtils.getSubject();
try {
//在調用了login方法後,SecurityManager會收到AuthenticationToken,並將其發送給已配置的Realm執行必須的認證檢查
//每個Realm都能在必要時對提交的AuthenticationTokens作出反應
//所以這一步在調用login(token)方法時,它會走到MyRealm.doGetAuthenticationInfo()方法中,具體驗證方式詳見此方法
logger.info("對用戶[" + username + "]進行登錄驗證..驗證開始");
currentUser.login(token);
logger.info("對用戶[" + username + "]進行登錄驗證..驗證通過");
}catch(UnknownAccountException uae){
logger.info("對用戶[" + username + "]進行登錄驗證..驗證未通過,未知賬戶");
return "403";
}catch(IncorrectCredentialsException ice){
logger.info("對用戶[" + username + "]進行登錄驗證..驗證未通過,錯誤的憑證");
return "403";
}catch(LockedAccountException lae){
logger.info("對用戶[" + username + "]進行登錄驗證..驗證未通過,賬戶已鎖定");
return "403";
}catch(ExcessiveAttemptsException eae){
logger.info("對用戶[" + username + "]進行登錄驗證..驗證未通過,錯誤次數過多");
return "403";
}catch(AuthenticationException ae){
//通過處理Shiro的運行時AuthenticationException就可以控製用戶登錄失敗或密碼錯誤時的情景
logger.info("對用戶[" + username + "]進行登錄驗證..驗證未通過,堆棧軌跡如下");
ae.printStackTrace();
return "403";
}
//驗證是否登錄成功
if(currentUser.isAuthenticated()){
logger.info("用戶[" + username + "]登錄認證通過(這裏可以進行一些認證通過後的一些係統參數初始化操作)");
return "inde";
}else{
token.clear();
return "403";
}
}
示例15: login
import org.apache.shiro.subject.Subject; //導入方法依賴的package包/類
@RequestMapping(value="/login", method=RequestMethod.POST)
public String login(String username, String password, HttpServletRequest request){
System.out.println("-------------------------------------------------------");
String rand = (String)request.getSession().getAttribute("rand");
String captcha = WebUtils.getCleanParam(request, "captcha");
System.out.println("用戶["+username+"]登錄時輸入的驗證碼為["+captcha+"],HttpSession中的驗證碼為["+rand+"]");
if(!StringUtils.equals(rand, captcha)){
request.setAttribute("message_login", "驗證碼不正確");
return InternalResourceViewResolver.FORWARD_URL_PREFIX + "/";
}
UsernamePasswordToken token = new UsernamePasswordToken(username, password);
token.setRememberMe(true);
System.out.print("為驗證登錄用戶而封裝的Token:");
System.out.println(ReflectionToStringBuilder.toString(token, ToStringStyle.MULTI_LINE_STYLE));
//獲取當前的Subject
Subject currentUser = SecurityUtils.getSubject();
try {
//在調用了login方法後,SecurityManager會收到AuthenticationToken,並將其發送給已配置的Realm執行必須的認證檢查
//每個Realm都能在必要時對提交的AuthenticationTokens作出反應
//所以這一步在調用login(token)方法時,它會走到MyRealm.doGetAuthenticationInfo()方法中,具體驗證方式詳見此方法
System.out.println("對用戶[" + username + "]進行登錄驗證...驗證開始");
currentUser.login(token);
System.out.println("對用戶[" + username + "]進行登錄驗證...驗證通過");
}catch(UnknownAccountException uae){
System.out.println("對用戶[" + username + "]進行登錄驗證...驗證未通過,未知賬戶");
request.setAttribute("message_login", "未知賬戶");
}catch(IncorrectCredentialsException ice){
System.out.println("對用戶[" + username + "]進行登錄驗證...驗證未通過,錯誤的憑證");
request.setAttribute("message_login", "密碼不正確");
}catch(LockedAccountException lae){
System.out.println("對用戶[" + username + "]進行登錄驗證...驗證未通過,賬戶已鎖定");
request.setAttribute("message_login", "賬戶已鎖定");
}catch(ExcessiveAttemptsException eae){
System.out.println("對用戶[" + username + "]進行登錄驗證...驗證未通過,錯誤次數過多");
request.setAttribute("message_login", "用戶名或密碼錯誤次數過多");
}catch(AuthenticationException ae){
//通過處理Shiro的運行時AuthenticationException就可以控製用戶登錄失敗或密碼錯誤時的情景
System.out.println("對用戶[" + username + "]進行登錄驗證...驗證未通過,堆棧軌跡如下");
ae.printStackTrace();
request.setAttribute("message_login", "用戶名或密碼不正確");
}
//驗證是否登錄成功
if(currentUser.isAuthenticated()){
System.out.println("用戶[" + username + "]登錄認證通過(這裏可進行一些認證通過後的係統參數初始化操作)");
return "main";
}else{
token.clear();
return InternalResourceViewResolver.FORWARD_URL_PREFIX + "/";
}
}