您的位置:首页 > 编程语言 > Java开发

Spring Security 3.1.3最小入门配置及实例下载

2013-12-11 18:00 656 查看
因为公司项目要用spring security管理权限,但是作为一个极其标准的菜鸟,只最略微接触了一些spring的东西,基本不算入门,研究了一整天才做出了最简单的demo,有基础了想提高的大牛们就不用往下看了,这个是最最基本的入门配置,附有实例下载,算是给那些也从来没有接触过的和我一样的菜鸟们吧。

这个例子全部都是配置出来的,没有用到任何JAVA代码,我想既然是学,对于新手来说把最简单的东西弄懂了后面一是比较有信心,二是循序渐进。网上的教程很多,但是我感觉很少有那种非常简单的(最后发现了个简单的教程,我放在附件里你们可以下载,挺有帮助),而且直接可以运行的实例基本上需要更改的太多,所以才把这个上传,希望别笑我,拜托啦。

    整个项目的目录是这样的



废话不多说,直接贴代码:

1.web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:application-security.xml
</param-value>
</context-param>

<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<!-- 拦截所有请求 -->
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 监听spring配置文件 -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- 监听Session -->
<listener>
<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

</web-app>


2.application-security.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 
<http pattern="/no.jsp" security="none"/>
<http auto-config="true" access-denied-page="/no.jsp">
<!-- <intercept-url pattern="/**" access="ROLE_USER" /> -->
<intercept-url pattern="/index1.jsp" access="ROLE_USER" />
<intercept-url pattern="/index2.jsp" access="ROLE_DAZA" />
<intercept-url pattern="/index3.jsp" access="ROLE_MANAGER" />

<!-- <form-login
login-page="/login.jsp"
login-processing-url="/gologin"
authentication-failure-url="/no.jsp"
default-target-url="/index.jsp"/> -->

<logout
invalidate-session="true"
logout-url="/logout.jsp"/>

</http>

<authentication-manager alias="appAuthenticationManager">
<authentication-provider>
<user-service>
<user name="user1" password="111111" authorities="ROLE_USER" />
<user name="user2" password="222222" authorities="ROLE_DAZA" />
<user name="user3" password="333333" authorities="ROLE_MANAGER,ROLE_DAZA,ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>

</beans:beans>

3.jsp什么的随便写点就好。

实例和教程的下载地址在下面了,话说,怎么才能添加附件?

Spring Security 3.1.3配置实例

SpringSecurity_3.0_教程
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息