use of org.apache.shiro.authc.UsernamePasswordToken in project vip by guangdada.
the class LoginController method loginVali.
/**
* 点击登录执行的动作
*/
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String loginVali() {
String username = super.getPara("username").trim();
String password = super.getPara("password").trim();
// 验证验证码是否正确
if (ToolUtil.getKaptchaOnOff()) {
String kaptcha = super.getPara("kaptcha").trim();
String code = (String) super.getSession().getAttribute(Constants.KAPTCHA_SESSION_KEY);
if (ToolUtil.isEmpty(kaptcha) || !kaptcha.equals(code)) {
throw new InvalidKaptchaException();
}
}
Subject currentUser = ShiroKit.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(username, password.toCharArray());
token.setRememberMe(true);
currentUser.login(token);
ShiroUser shiroUser = ShiroKit.getUser();
super.getSession().setAttribute("shiroUser", shiroUser);
super.getSession().setAttribute("username", shiroUser.getAccount());
LogManager.me().executeLog(LogTaskFactory.loginLog(shiroUser.getId(), getIp()));
ShiroKit.getSession().setAttribute("sessionFlag", true);
return REDIRECT + "/";
}
use of org.apache.shiro.authc.UsernamePasswordToken in project moon by gentoo111.
the class RestfulFilter method isAccessAllowed.
@Override
protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) {
String loginToken = getToken(request);
if (StringUtils.isBlank(loginToken)) {
// 非Restful方式
return super.isAccessAllowed(request, response, mappedValue);
}
TokenManager tokenManager = SpringUtil.getBean(TokenManager.class);
UsernamePasswordToken token = tokenManager.getToken(loginToken);
if (token != null) {
try {
Subject subject = getSubject(request, response);
if (subject.getPrincipal() == null) {
subject.login(token);
}
return true;
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
use of org.apache.shiro.authc.UsernamePasswordToken in project moon by gentoo111.
the class LoginController method restfulLogin.
@LogAnnotation
@ApiOperation(value = "restful登录方式,前后端分离时的接口")
@PostMapping("/sys/login/restful")
public Token restfulLogin(String username, String password) {
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password);
SecurityUtils.getSubject().login(usernamePasswordToken);
return tokenManeger.saveToken(usernamePasswordToken);
}
use of org.apache.shiro.authc.UsernamePasswordToken in project moon by gentoo111.
the class LoginController method login.
@LogAnnotation
@ApiOperation(value = "web端登陆")
@PostMapping("/sys/login")
public void login(String username, String password) {
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password);
SecurityUtils.getSubject().login(usernamePasswordToken);
}
use of org.apache.shiro.authc.UsernamePasswordToken in project moon by gentoo111.
the class EhCacheTokenManager method saveToken.
@Override
public Token saveToken(UsernamePasswordToken usernamePasswordToken) {
Cache cache = cacheManager.getCacheManager().getCache("login_user_tokens");
String key = UUID.randomUUID().toString();
Element element = new Element(key, usernamePasswordToken);
element.setTimeToLive(expireSeconds);
cache.put(element);
return new Token(key, DateUtils.addSeconds(new Date(), expireSeconds));
}
Aggregations