[roles]
# format: roleName = permission1, permission2, ..., permissionN
[urls]
# The /login.jsp is not restricted to authenticated users (otherwise no one could log in!), but
# the 'authc' filter must still be specified for it so it can process that url's
# login submissions. It is 'smart' enough to allow those requests through as specified by the
# shiro.loginUrl above.
/success.jsp = authc
服务端认证程序。
public class LoginController implements Controller {
private static final Log log = LogFactory.getLog(LoginController.class);
protected ErrMg error;
public ModelAndView doReturnError(HttpServletRequest request,
HttpServletResponse response, ErrMg message, String errpath) {
request.setAttribute("Error_Message", message);
return new ModelAndView(errpath);
}
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String loginName = request.getParameter("loginName");
String loginPwd = request.getParameter("password");
log.info("用户认证开始:" + loginName + " , " + loginPwd);
String userid = null;
String username = null;
error = new ErrMg();
AuthenticationToken token = new UsernamePasswordToken(loginName,
loginPwd);
Subject currentUser = SecurityUtils.getSubject();
try {
currentUser.login(token);
userid = (String)currentUser.getPrincipal();
log.info( "User [" + currentUser.getPrincipal() + "] logged in successfully." );
log.info("用户认证完毕:" + loginName + " , " + userid);
HttpSession session = request.getSession(true);
session.setAttribute("USERINFORMATION", userid);
session.setAttribute("USERNAME", userid);
return new ModelAndView("success.jsp");
} catch (UnknownAccountException uae) {
log.info("用户认证失败:" + "username wasn't in the system.");
error.setErrorMessage("username wasn't in the system.");
} catch (IncorrectCredentialsException ice) {
log.info("用户认证失败:" + "password didn't match.");
error.setErrorMessage("password didn't match.");
} catch (LockedAccountException lae) {
log.info("用户认证失败:" + "account for that username is locked - can't login.");
error.setErrorMessage("account for that username is locked - can't login.");
} catch (AuthenticationException ae) {
log.info("用户认证失败:" + "unexpected condition.");
error.setErrorMessage("unexpected condition.");
}
return this.doReturnError(request, response, error, "error.jsp");
}
}