Commit b600d774 authored by Paul0523's avatar Paul0523

重构代码

parent 1bf305cd
......@@ -53,5 +53,6 @@
<artifactId>bigsys-spring</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
package com.bigsys.shiro.filter;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
/**
* Created by fangzhipeng on 2017/8/15.
*/
public class LoginFilter extends FormAuthenticationFilter {
@Override
protected AuthenticationToken createToken(ServletRequest request, ServletResponse response) {
HttpServletRequest req = (HttpServletRequest) request;
String username = req.getParameter("username");
String password = req.getParameter("password");
return new UsernamePasswordToken(username, password);
}
}
......@@ -15,7 +15,7 @@ public class UserService {
public User getByUsername(String username) {
User user = new User();
user.setUsername(username);;
user.setPassword("123456");
user.setPassword("yuanguang2017");
return user;
}
}
......@@ -16,6 +16,9 @@
<bean id="userRealm" class="com.bigsys.shiro.realm.UserRealm">
</bean>
<bean id="authc" class="com.bigsys.shiro.filter.LoginFilter">
</bean>
<!-- 安全管理器 -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="userRealm" />
......@@ -23,16 +26,12 @@
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"/>
<property name="loginUrl" value="/login"/>
<property name="successUrl" value="/login/loginSuccessFull"/>
<property name="unauthorizedUrl" value="/login/unauthorized"/>
<property name="loginUrl" value="/static/login.html"/>
<property name="successUrl" value="/hello"/>
<property name="unauthorizedUrl" value="/static/login.html"/>
<property name="filterChainDefinitions">
<value>
/home* = anon
/ = anon
/logout = logout
/role/** = roles[admin]
/permission/** = perms[permssion:look]
/** = authc
</value>
</property>
......
......@@ -5,10 +5,10 @@
<title>登录页面</title>
</head>
<body>
<form action="login.html">
<form action="" method="post">
<label>用户名:</label><input type="text" name="username">
<label>密码:</label><input type="password" name="password">
<input type="submit" name="提交"/>
<input type="submit" value="提交"/>
</form>
</body>
</html>
\ No newline at end of file
......@@ -24,6 +24,13 @@
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
......
......@@ -13,6 +13,26 @@
<mvc:annotation-driven />
<mvc:resources mapping="/static/**" location="/,classpath:/static/"/>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="urlMap">
<map>
<entry key="/static/**" value="myResourceHandler" />
</map>
</property>
<property name="order" value="100000" />
</bean>
<bean id="myResourceHandler" name="myResourceHandler"
class="org.springframework.web.servlet.resource.ResourceHttpRequestHandler">
<property name="locations" value="classpath:/static/" />
<property name="supportedMethods">
<list>
<value>GET</value>
<value>HEAD</value>
<value>POST</value>
</list>
</property>
</bean>
</beans>
\ No newline at end of file
......@@ -37,6 +37,25 @@
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 配置Shiro过滤器,先让Shiro过滤系统接收到的请求 -->
<!-- 这里filter-name必须对应applicationContext.xml中定义的<bean id="shiroFilter"/> -->
<!-- 使用[/*]匹配所有请求,保证所有的可控请求都经过Shiro的过滤 -->
<!-- 通常会将此filter-mapping放置到最前面(即其他filter-mapping前面),以保证它是过滤器链中第一个起作用的 -->
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<!-- 该值缺省为false,表示生命周期由SpringApplicationContext管理,设置为true则表示由servlet container管理 -->
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment