use of org.apache.shiro.authc.UsernamePasswordToken in project ssm_shiro_blog by Mandelo.
the class MainController method login.
/**
* 登录功能
*
* @param user
* @param model
* @return
*/
@RequestMapping(value = "/user/login", method = RequestMethod.POST)
public String login(User user, HttpSession session, Model model) {
UsernamePasswordToken token = new UsernamePasswordToken(user.getUsername(), user.getPassword());
Subject subject = SecurityUtils.getSubject();
subject.login(token);
User loginUser = userService.selectByUsername(user.getUsername());
session.setAttribute("loginUser", loginUser);
// System.out.println(loginUser);
return "/loginSuccess";
}
use of org.apache.shiro.authc.UsernamePasswordToken in project fruit-manage by liuzhaozhao.
the class ShiroDbRealm method doGetAuthenticationInfo.
// @Override
// public void setCacheManager(CacheManager cacheManager) {
// super.setCacheManager(cacheManager);
// // ShiroCache.setCacheManager(cacheManager);
// }
/**
* 身份证认证
*
* @param authenticationToken
* @return
* @throws AuthenticationException
*/
@Override
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) authenticationToken;
String username = usernamePasswordToken.getUsername();
User user = User.dao.getUser(username);
SimpleAuthenticationInfo authenticationInfo = null;
if (user != null) {
authenticationInfo = new SimpleAuthenticationInfo(user, user.getPass(), getName());
// authenticationInfo.setCredentialsSalt(ByteSource.Util.bytes(name
// + user.get("salt")));
}
return authenticationInfo;
}
use of org.apache.shiro.authc.UsernamePasswordToken in project Ganster-CMS by Gangster-trio.
the class LoginController method login.
@PostMapping("/login")
public Message login(@RequestParam("userName") String userName, @RequestParam("password") String password) {
logger.info("用户" + userName + "进行登录");
UsernamePasswordToken token = new UsernamePasswordToken(userName, password);
// token.setRememberMe(true);
Message message = new Message();
Subject subject = SecurityUtils.getSubject();
try {
subject.login(token);
message.setCode(100);
message.setMsg("ok");
} catch (Exception e) {
message.setCode(120);
message.setMsg("抱歉,信息错误");
return message;
}
return message;
}
use of org.apache.shiro.authc.UsernamePasswordToken in project airavata by apache.
the class JDBCUserStore method authenticate.
@Override
public boolean authenticate(String userName, Object credentials) throws UserStoreException {
AuthenticationToken authenticationToken = new UsernamePasswordToken(userName, passwordDigester.getPasswordHashValue((String) credentials));
AuthenticationInfo authenticationInfo;
try {
authenticationInfo = jdbcRealm.getAuthenticationInfo(authenticationToken);
return authenticationInfo != null;
} catch (AuthenticationException e) {
log.debug(e.getLocalizedMessage(), e);
return false;
}
}
use of org.apache.shiro.authc.UsernamePasswordToken in project shiro by apache.
the class LoginController method onSubmit.
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object cmd, BindException errors) throws Exception {
LoginCommand command = (LoginCommand) cmd;
UsernamePasswordToken token = new UsernamePasswordToken(command.getUsername(), command.getPassword());
try {
SecurityUtils.getSubject().login(token);
} catch (AuthenticationException e) {
log.debug("Error authenticating.", e);
errors.reject("error.invalidLogin", "The username or password was not correct.");
}
if (errors.hasErrors()) {
return showForm(request, response, errors);
} else {
return new ModelAndView(getSuccessView());
}
}
Aggregations