此文老猫原创,转载请加本文连接:http://blog.csdn.net/nthack5730/article/details/51124171
更多有关老猫的文章:http://blog.csdn.net/nthack5730
<property name="filterChainDefinitions">
<value>
<!-- 对静态资源设置匿名访问 -->
/js/** = anon
/css/** = anon
/img/** = anon
/fonts/** = anon
/scripts/** = anon
</value>
</property>
/**
* This default implementation merely returns <code>true</code> if the request is an HTTP <code>POST</code>,
* <code>false</code> otherwise. Can be overridden by subclasses for custom login submission detection behavior.
*
* @param request the incoming ServletRequest
* @param response the outgoing ServletResponse.
* @return <code>true</code> if the request is an HTTP <code>POST</code>, <code>false</code> otherwise.
*/
@SuppressWarnings({"UnusedDeclaration"})
protected boolean isLoginSubmission(ServletRequest request, ServletResponse response) {
return (request instanceof HttpServletRequest) && WebUtils.toHttp(request).getMethod().equalsIgnoreCase(POST_METHOD);
}
此文老猫原创,转载请加本文连接:http://blog.csdn.net/nthack5730/article/details/51124171
更多有关老猫的文章:http://blog.csdn.net/nthack5730
<form action="${pageContext.request.contextPath }/login.action" method="post">
<div>
<input type="text" name="username" class="username"
placeholder="用户名 / UID" autocomplete="off" required/>
</div>
<div>
<input type="password" name="password" class="password"
placeholder="密码" oncontextmenu="return false"
onpaste="return false" required/>
</div>
<button id="submit" type="submit" class="btn btn-success btn-block loginbtn">登陆</button>
</form>
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) {
String username = getUsername(request);
String password = getPassword(request);
return createToken(username, password, request, response);
}
public String login() {
return "login";
}
@Controller("LoginAction")
@Scope("prototype")
<!-- user名空间 -->
<package name="user" namespace="/user" extends="struts-default"> <!-- 登陆提交的地址,和applicationContext-shiro.xml中配置的loginurl一致 -->
<action name="login" class="com.my.action.LoginAction" method="login">
<result name="login">/WEB-INF/jsp/login.jsp</result>
</action>
</package>
public String login() throws Exception {
//从request中获取FormAuthenticationFilter填充的异常信息,就是ShiroLoginFailure的全限定名
String exceptionClassName = (String) request.get("shiroLoginFailure");
//根据Shiro返回的异常类信息判断,抛出并处理这个异常信息
if (UnknownAccountException.class.getName().equals(exceptionClassName)) {
error = "用户不存在,请核对用户名";//如果UnknownAccountException抛出这个异常,表示账号不存在
} else if (IncorrectCredentialsException.class.getName().equals(
exceptionClassName)) {
error = "用户名/密码错误";
} else if (exceptionClassName != null) {
error = "其他错误:" + exceptionClassName;
}
//此方法不处理登陆成功,shiro认证成功会跳转到上一个路径
//登陆失败,还到login页面
return "login";
}
public class BaseAction<T> extends ActionSupport implements RequestAware,
SessionAware, ApplicationAware, ModelDriven<T> {
/**
*
*/
private static final long serialVersionUID = 1L;
protected T model; // 这里使用protected是为了可以封装 也可以继承
public Map<String, Object> application;
public Map<String, Object> request;
public Map<String, Object> session;
...
}
此文老猫原创,转载请加本文连接:http://blog.csdn.net/nthack5730/article/details/51124171
更多有关老猫的文章:http://blog.csdn.net/nthack5730
<property name="filterChainDefinitions">
<value>
<!-- 对静态资源设置匿名访问 -->
/js/** = anon
/css/** = anon
/img/** = anon
/fonts/** = anon
/scripts/** = anon
<!-- /** = authc 表示所有URL都必须认证才可以通过访问 -->
/** = authc
</value>
</property>
此文老猫原创,转载请加本文连接:http://blog.csdn.net/nthack5730/article/details/51124171
更多有关老猫的文章:http://blog.csdn.net/nthack5730
<!-- 请求logout.action地址,shiro去清除session -->
/logout.action = logout