當前位置: 首頁>>代碼示例>>Java>>正文


Java UsernamePasswordToken.setRememberMe方法代碼示例

本文整理匯總了Java中org.apache.shiro.authc.UsernamePasswordToken.setRememberMe方法的典型用法代碼示例。如果您正苦於以下問題:Java UsernamePasswordToken.setRememberMe方法的具體用法?Java UsernamePasswordToken.setRememberMe怎麽用?Java UsernamePasswordToken.setRememberMe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.shiro.authc.UsernamePasswordToken的用法示例。


在下文中一共展示了UsernamePasswordToken.setRememberMe方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: signin

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@RequestMapping(value = "/signin", method = {
        RequestMethod.POST})
public String signin(ModelMap map, User user, HttpServletRequest request) {

    String error;
    UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPasswd());
    token.setRememberMe(null != request.getParameter("rememberme") ? true : false);
    try {
        Subject subject = SecurityUtils.getSubject();
        subject.login(token);
        subject.getSession().setAttribute("curUser", userService.findByUsername((String) subject.getPrincipal()));
        return "redirect:/dashboard/console";
    } catch (UnknownAccountException uae) {
        error = "用戶名錯誤!";
    } catch (IncorrectCredentialsException ice) {
        error = "密碼錯誤!";
    } catch (LockedAccountException lae) {
        error = "用戶被鎖定!";
    }
    map.addAttribute("error", error);
    return "signin";
}
 
開發者ID:melonlee,項目名稱:PowerApi,代碼行數:23,代碼來源:AuthController.java

示例2: tryLogin

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
public boolean tryLogin(String email, String password, Boolean rememberMe) {
    org.apache.shiro.subject.Subject currentUser = SecurityUtils.getSubject();
    UsernamePasswordToken token = new UsernamePasswordToken(email, password);
    token.setRememberMe(rememberMe);

    try {
        currentUser.login(token);
        System.out.println("User [" + currentUser.getPrincipal().toString() + "] logged in successfully.");
        // save username in the session
        currentUser.getSession().setAttribute("username", email);
        return true;
    } catch (UnknownAccountException uae) {
        System.out.println("There is no user with username of " + token.getPrincipal());
    } catch (IncorrectCredentialsException ice) {
        System.out.println("Password for account " + token.getPrincipal() + " was incorrect!");
    } catch (LockedAccountException lae) {
        System.out.println("The account for username " + token.getPrincipal() + " is locked.  " + "Please contact your administrator to unlock it.");
    }

    return false;
}
 
開發者ID:ETspielberg,項目名稱:bibliometrics,代碼行數:22,代碼來源:BibliometricReportRetrievalServlet.java

示例3: dashboard

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@RequestMapping(value = "/login", method = {
        RequestMethod.POST})
public String dashboard(ModelMap map, Admin admin) {
    String error = null;
    UsernamePasswordToken token = new UsernamePasswordToken(admin.getUsername(), admin.getPassword());
    token.setRememberMe(false);
    try {
        SecurityUtils.getSubject().login(token);
        return "redirect:/video/all";
    } catch (UnknownAccountException uae) {
        error = "用戶名錯誤!";
    } catch (IncorrectCredentialsException ice) {
        error = "密碼錯誤!";
    } catch (LockedAccountException lae) {
        error = "用戶被鎖定!";
    }
    map.addAttribute("error", error);
    return "login.ftl";
}
 
開發者ID:melonlee,項目名稱:LazyAdmin,代碼行數:20,代碼來源:AuthController.java

示例4: login

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@RequestMapping(value = "login", method = RequestMethod.POST)
public String login(@ModelAttribute("formDto") LoginDto formDto, BindingResult errors) {

    UsernamePasswordToken token = formDto.token();
    token.setRememberMe(false);

    try {
        SecurityUtils.getSubject().login(token);
    } catch (Exception e) {
        LOG.debug("Error authenticating.", e);
        errors.rejectValue("username", null, "The username or password was not correct.");
        return "login";
    }

    return "redirect:index";
}
 
開發者ID:monkeyk,項目名稱:oauth2-shiro,代碼行數:17,代碼來源:ShiroController.java

示例5: signup

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@RequestMapping(value = "/signup", method = {
        RequestMethod.POST})
public String signup(User user, ModelMap map) {
    //檢查用戶名是否被注冊
    User temp = userService.findByUsername(user.getUsername());
    if (null == temp) {
        //注冊
        String passwdTemp = user.getPasswd();
        passwordHelper.encryptPassword(user);
        userService.insert(user);
        //登錄到shiro中
        UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), passwdTemp);
        token.setRememberMe(true);
        Subject subject = SecurityUtils.getSubject();
        subject.login(token);
        subject.getSession().setAttribute("curUser", user);
        return "redirect:/dashboard/console";
    } else {
        map.addAttribute("error", "用戶名已經被占用!");
        return "signup";
    }
}
 
開發者ID:melonlee,項目名稱:PowerApi,代碼行數:23,代碼來源:AuthController.java

示例6: changepwd

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@RequestMapping(value = "/changepwd", method = {
        RequestMethod.POST})
public String changepwd(ModelMap map, User user, @RequestParam(value = "passwdnew", required = true) String passwdnew) {

    //驗證當前賬號
    UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPasswd());
    token.setRememberMe(false);
    try {
        SecurityUtils.getSubject().login(token);
        //驗證通過更新用戶密碼
        user.setId(getCurrentUser().getId());
        user.setPasswd(passwdnew);
        passwordHelper.encryptPassword(user);
        userService.updateById(user);
        return "redirect:/dashboard/console";
    } catch (UnknownAccountException | IncorrectCredentialsException | LockedAccountException e) {
        map.addAttribute("exception", e.getMessage());
        return "common/error";
    }
}
 
開發者ID:melonlee,項目名稱:PowerApi,代碼行數:21,代碼來源:DashboardController.java

示例7: execute

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
public String execute(Database database) {
	Subject currentUser = SecurityUtils.getSubject();
	if (!currentUser.isAuthenticated()) {
		UsernamePasswordToken token = new UsernamePasswordToken(username, password);
		token.setRememberMe(true);
		try {
			currentUser.login(token);
			return "user: "+username + " logged in successfully";
		} catch (Exception e) {
			throw new VectorizationException("Login failed");
		}
	}else{
		currentUser.logout();
		return execute(database);
	}
	
}
 
開發者ID:robertgmoss,項目名稱:vectorization,代碼行數:19,代碼來源:Login.java

示例8: login

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
public boolean login(LoginVo loginVo) {

	Subject currentUser = SecurityUtils.getSubject();
	UsernamePasswordToken token = new UsernamePasswordToken(
			loginVo.getUsername(), SecurityUtil.encodeMd5(loginVo
					.getPassword()));
	token.setRememberMe(true);

	try {
		currentUser.login(token);
	} catch (UnknownAccountException uae) {
		return false;
	} catch (IncorrectCredentialsException ice) {
		return false;
	} catch (LockedAccountException lae) {
		return false;
	} catch (AuthenticationException ae) {
		return false;
	}

	return true;
}
 
開發者ID:joaquinaimar,項目名稱:wizard,代碼行數:24,代碼來源:LoginServiceImpl.java

示例9: login

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
public Map<String, Object> login(String userName, String password) {

    Map<String, Object> loginInfo = new HashMap<String, Object>();

    Subject currentUser = SecurityUtils.getSubject();
    UsernamePasswordToken token = new UsernamePasswordToken(userName,
            password);
    token.setRememberMe(true);

    try {
        currentUser.login(token);
    } catch (UnknownAccountException uae) {
        return null;
    } catch (IncorrectCredentialsException ice) {
        return null;
    } catch (LockedAccountException lae) {
        return null;
    } catch (AuthenticationException ae) {
        return null;
    }
    loginInfo.put(WizardWebUtils.USER_NAME, userName);
    loginInfo.put(WizardWebUtils.ROLE_NAME, getRole(currentUser));

    return loginInfo;
}
 
開發者ID:joaquinaimar,項目名稱:wizard,代碼行數:27,代碼來源:LoginServiceImpl.java

示例10: login

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Override
public Map<String, Object> login(String userName, String password) {

	Map<String, Object> loginInfo = new HashMap<String, Object>();

	Subject currentUser = SecurityUtils.getSubject();
	UsernamePasswordToken token = new UsernamePasswordToken(userName,
			password);
	token.setRememberMe(true);

	try {
		currentUser.login(token);
	} catch (UnknownAccountException uae) {
		return null;
	} catch (IncorrectCredentialsException ice) {
		return null;
	} catch (LockedAccountException lae) {
		return null;
	} catch (AuthenticationException ae) {
		return null;
	}
	loginInfo.put(WizardWebUtils.USER_NAME, userName);
	loginInfo.put(WizardWebUtils.ROLE_NAME, getRole(currentUser));

	return loginInfo;
}
 
開發者ID:joaquinaimar,項目名稱:wizard,代碼行數:27,代碼來源:LoginServiceImpl.java

示例11: tryLogin

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
public boolean tryLogin(String username, String password, Boolean rememberMe) {
	org.apache.shiro.subject.Subject currentUser = SecurityUtils.getSubject();

	if (!currentUser.isAuthenticated()) {
		UsernamePasswordToken token = new UsernamePasswordToken(username, password);
		token.setRememberMe(rememberMe);

		try {
			currentUser.login(token);
			LOGGER.info("User [" + currentUser.getPrincipal().toString() + "] logged in successfully.");
			// save username in the session
			currentUser.getSession().setAttribute("username", username);
			return true;
		} catch (UnknownAccountException uae) {
			LOGGER.info("There is no user with username of " + token.getPrincipal());
		} catch (IncorrectCredentialsException ice) {
			LOGGER.info("Password for account " + token.getPrincipal() + " was incorrect!");
		} catch (LockedAccountException lae) {
			LOGGER.info("The account for username " + token.getPrincipal() + " is locked.  "
					+ "Please contact your administrator to unlock it.");
		}
	} else {
		return true;
	}

	return false;
}
 
開發者ID:ETspielberg,項目名稱:bibliometrics,代碼行數:28,代碼來源:UserLoggingServlet.java

示例12: login

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Transactional
@Override
public User login(String username, String password) throws IncorrectCredentialsException{
	UsernamePasswordToken token = new UsernamePasswordToken();
	token.setUsername(username);
	token.setPassword(password.toCharArray());
	token.setRememberMe(true);
	SecurityUtils.getSubject().login(token);
	if (SecurityUtils.getSubject().isAuthenticated()) {
		SecurityUtils.getSubject().getSession().setAttribute("username", username);
		return userDao.get("from User u where u.username = ?",
				new String[] { username });
	}
	return null;
}
 
開發者ID:inexistence,項目名稱:VideoMeeting,代碼行數:16,代碼來源:AccountServiceImpl.java

示例13: login

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
/**
 * 安全登陸方法
 *
 * @param loginName
 *            用戶名稱
 * @param loginPwd
 *            用戶密碼
 * @param isRemeberMe
 *            是否記住我
 * @return
 */
public static boolean login(String loginName, String loginPwd, boolean isRemeberMe) {
	UsernamePasswordToken token = new UsernamePasswordToken(loginName, loginPwd);
	// 記錄該令牌,如果不記錄則類似購物車功能不能使用。
	token.setRememberMe(isRemeberMe);
	// subject理解成權限對象。類似user
	Subject subject = SecurityUtils.getSubject();

	// 如果當前已登陸,先退出登陸
	SecurityUser securityUser = getSecurityUser();
	if (securityUser != null) {
		logout();
	}
	try {
		subject.login(token);
	} catch (Exception ex) {
		logger.error(ex.getMessage(), ex);
	}
	// } catch (UnknownAccountException ex) {// 用戶名沒有找到
	// logger.error(ex.getMessage(), ex);
	// } catch (IncorrectCredentialsException ex) {// 用戶名密碼不匹配
	// logger.error(ex.getMessage(), ex);
	// } catch (AuthenticationException e) {// 其他的登錄錯誤
	// logger.error(e.getMessage(), e);
	// }

	if (subject.isAuthenticated()) {
		return true;
	}
	return false;
}
 
開發者ID:xuegongzi,項目名稱:rabbitframework,代碼行數:42,代碼來源:RabbitSecurityUtils.java

示例14: authenticateUser

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
private void authenticateUser(Subject currentUser, ShiroSecurityToken securityToken) {
    boolean authenticated = currentUser.isAuthenticated();
    boolean sameUser = securityToken.getUsername().equals(currentUser.getPrincipal());
    LOG.trace("Authenticated: {}, same Username: {}", authenticated, sameUser);

    if (!authenticated || !sameUser) {
        UsernamePasswordToken token = new UsernamePasswordToken(securityToken.getUsername(), securityToken.getPassword());
        if (policy.isAlwaysReauthenticate()) {
            token.setRememberMe(false);
        } else {
            token.setRememberMe(true);
        }

        try {
            currentUser.login(token);
            LOG.debug("Current user {} successfully authenticated", currentUser.getPrincipal());
        } catch (UnknownAccountException uae) {
            throw new UnknownAccountException("Authentication Failed. There is no user with username of " + token.getPrincipal(), uae.getCause());
        } catch (IncorrectCredentialsException ice) {
            throw new IncorrectCredentialsException("Authentication Failed. Password for account " + token.getPrincipal() + " was incorrect!", ice.getCause());
        } catch (LockedAccountException lae) {
            throw new LockedAccountException("Authentication Failed. The account for username " + token.getPrincipal() + " is locked."
                    + "Please contact your administrator to unlock it.", lae.getCause());
        } catch (AuthenticationException ae) {
            throw new AuthenticationException("Authentication Failed.", ae.getCause());
        }
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:29,代碼來源:ShiroSecurityProcessor.java

示例15: testUser1

import org.apache.shiro.authc.UsernamePasswordToken; //導入方法依賴的package包/類
@Test
public void testUser1() throws Exception {
  /*
   * login the current subject
   */
  Subject subject = SecurityUtils.getSubject();

  // use a username/pass token
  UsernamePasswordToken token = new UsernamePasswordToken("root", "123456");
  token.setRememberMe(true);
  subject.login(token);

  log.info("User successfuly logged in");

  Thread.sleep(2 * 1000);
  log.info("hasRole:" + subject.hasRole("admin"));

  Thread.sleep(2 * 1000);

  log.info("isPermitted:" + subject.isPermitted("*"));

  log.info("session:" + subject.getSession().getTimeout());
  log.info("session:" + subject.getSession().getLastAccessTime());

  DefaultSessionManager sessionManager = (DefaultSessionManager) ((DefaultSecurityManager) SecurityUtils.getSecurityManager()).getSessionManager();
  sessionManager.getSessionDAO().getActiveSessions();
  Thread.sleep(30 * 1000);
}
 
開發者ID:wjw465150,項目名稱:shiro-redis,代碼行數:29,代碼來源:TestRedisRealmManager.java


注:本文中的org.apache.shiro.authc.UsernamePasswordToken.setRememberMe方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。