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

本文提供了一个针对Spring Security 3.1.3的最简单入门配置示例,适合初学者。整个配置过程无需编写JAVA代码,完全在XML中完成,旨在帮助对Spring Security无基础的开发者快速上手。文章还附带了可以直接运行的实例下载链接和一个相关的教程资源。

因为公司项目要用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_教程

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值