`
chembo
  • 浏览: 948504 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

spring security3 配置文件

阅读更多
首先是spring3,适合后台管理的配置:

<?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.0.xsd
           http://www.springframework.org/schema/security
           http://www.springframework.org/schema/security/spring-security-3.0.xsd">

	<http access-denied-page="/deny.jsp" auto-config="true">
		<intercept-url pattern="/modules/index.jsp*" filters="none" />
		<intercept-url pattern="/js/**" filters="none" />
		<intercept-url pattern="/images/**" filters="none" />
		<intercept-url pattern="/css/**" filters="none" />
		<intercept-url pattern="/flash/**" filters="none" />
		<intercept-url pattern="/common/**" filters="none" />
		<intercept-url pattern="/myupload/uploadhandler.do" filters="none" />
		<intercept-url pattern="/user/uploadAvatar.do" filters="none" />
	    <intercept-url pattern="/**" access="IS_AUTHENTICATED_FULLY" /> 
	    <form-login login-page="/modules/index.jsp"  authentication-failure-url="/modules/index.jsp?error=true" login-processing-url="/gjposs_security_check.do"  default-target-url="/modules/common/main.jsp" always-use-default-target="true"/>
	    <logout logout-success-url="/modules/index.jsp"/>
	    <http-basic/>
	</http>
	<beans:bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" />
	<authentication-manager alias="authenticationManager">
		<authentication-provider user-service-ref="securityManager">
			<password-encoder ref="passwordEncoder">
				<!-- salt-source user-property="getUsername"/> --> 
			</password-encoder>
		</authentication-provider>
	</authentication-manager>

	
	<beans:bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased">
	    <beans:property name="allowIfAllAbstainDecisions" value="false"/>
	    <beans:property name="decisionVoters">
	        <beans:list>
	            <beans:bean class="org.springframework.security.access.vote.RoleVoter"/>
	            <beans:bean class="org.springframework.security.access.vote.AuthenticatedVoter"/>
	        </beans:list>
	    </beans:property>
	</beans:bean>
	<beans:bean id="resourceSecurityInterceptor" class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
		<beans:property name="authenticationManager" ref="authenticationManager"/>
	    <beans:property name="accessDecisionManager" ref="accessDecisionManager"/>
	    <beans:property name="securityMetadataSource" ref="secureResourceFilterInvocationDefinitionSource" />
	    <beans:property name="observeOncePerRequest" value="false" />
	</beans:bean>
	
	<beans:bean id="secureResourceFilterInvocationDefinitionSource" class="com.gjp.oss.security.interceptor.SecureResourceFilterInvocationDefinitionSource" />
	<beans:bean id="securityManager" class="com.gjp.oss.security.support.SecurityManagerSupport">
		<beans:property name="sessionFactory">
			<beans:ref bean="sessionFactory" />
		</beans:property>
	</beans:bean>
	
</beans:beans>


然后是适合portal的配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
	xmlns:sec="http://www.springframework.org/schema/security"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
           http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

	<bean id="springSecurityFilterChain" class="org.springframework.security.web.FilterChainProxy">
		<sec:filter-chain-map path-type="ant">
			<sec:filter-chain pattern="/**" filters="
			      securityContextPersistenceFilter,
			      logoutFilter,
			      formLoginFilter,
			      exceptionTranslationFilter,
			      filterSecurityInterceptor" />
		</sec:filter-chain-map>
	</bean>

	<bean id="securityContextPersistenceFilter"
		class="org.springframework.security.web.context.SecurityContextPersistenceFilter">
		<property name="securityContextRepository">
			<bean class="org.springframework.security.web.context.HttpSessionSecurityContextRepository"/>
		</property>
	</bean>
	
	<bean id="logoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter">
		<constructor-arg><bean class="org.springframework.security.web.authentication.logout.SimpleUrlLogoutSuccessHandler"/></constructor-arg>
		<constructor-arg><bean class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"/></constructor-arg>
		<property name="filterProcessesUrl" value="/security-logout.do"></property>
	</bean>

	<bean id="formLoginFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter">
		<property name="authenticationManager" ref="authenticationManager"/>
		<property name="filterProcessesUrl" value="/security-login.do"/>
		<property name="authenticationSuccessHandler">
			<bean class="org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler">
				<property name="defaultTargetUrl" value="/login/forward.do"></property>
				<property name="alwaysUseDefaultTargetUrl" value="true"></property>
			</bean>
		</property>
		<property name="authenticationFailureHandler">
			<bean class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler">
				<property name="defaultFailureUrl" value="/login/login.do"></property>
			</bean>
		</property>
		<property name="sessionAuthenticationStrategy">
			<bean class="org.springframework.security.web.authentication.session.ConcurrentSessionControlStrategy">
				<constructor-arg>
					<bean class="org.springframework.security.core.session.SessionRegistryImpl"></bean>
				</constructor-arg>
				<property name="maximumSessions" value="1"></property>
			</bean>
		</property>
	</bean> 

	<bean id="exceptionTranslationFilter"
	     class="org.springframework.security.web.access.ExceptionTranslationFilter">
		<property name="authenticationEntryPoint">
			<bean class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
				<property name="loginFormUrl" value="/login/login.do"/>
			</bean>
		</property>
		<property name="accessDeniedHandler">
			<bean class="org.springframework.security.web.access.AccessDeniedHandlerImpl">
				<property name="errorPage" value="/login/login.do"/>
			</bean>
		</property>
	</bean>

	<bean id="filterSecurityInterceptor"
	        class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor">
		<property name="authenticationManager" ref="authenticationManager"/>
		<property name="accessDecisionManager" ref="accessDecisionManager"/>
		<property name="securityMetadataSource">
			<sec:filter-security-metadata-source>
				<sec:intercept-url pattern="/usercenter/**" access="ROLE_VERIFIED_PORTAL_USER" />
			</sec:filter-security-metadata-source>
		</property>
	</bean>

	<bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" />
	<bean id="authenticationManager"
		class="org.springframework.security.authentication.ProviderManager">
		<property name="providers">
			<bean class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
				<property name="userDetailsService" ref="portalUserDetailsService" />
				<property name="passwordEncoder" ref="passwordEncoder" />
				<property name="hideUserNotFoundExceptions" value="false" />
			</bean>
		</property>
	</bean>
	<bean id="accessDecisionManager" class="org.springframework.security.access.vote.ConsensusBased">
		<property name="decisionVoters">
			<list>
				<bean class="org.springframework.security.access.vote.RoleVoter"></bean>
			</list>
		</property>
	</bean>

</beans>
分享到:
评论

相关推荐

    SpringSecurity 3配置文件

    在本文中,我们将深入探讨Spring Security 3的配置文件,以及如何理解和使用这些配置来增强应用的安全性。 首先,Spring Security的配置通常位于一个或多个XML文件中,这些文件通过`&lt;beans&gt;`标签定义了安全相关的...

    Spring Security3中文文档

    根据给定的文件信息,以下是对“Spring Security3”这一主题的详细知识点解析: ### Spring Security3概述 Spring Security3是Spring框架中的一个模块,它提供了全面的安全服务,旨在为Web和非Web应用程序提供访问...

    Spring Security.pdf

    在pom文件中配置Spring Security依赖后,可以创建Spring Security工程的结构,包括编写配置类来配置安全性细节,如用户详情服务、密码编码器、安全拦截器等。接着,实现用户登录、登出等页面和功能。在配置过程中,...

    spring-security多登录页面配置

    从给定的部分内容来看,我们可以看到这是一个Spring Security的配置文件,使用了Spring Security的XML命名空间。下面是一个示例性的配置片段: ```xml &lt;!-- 允许访问登录页面 --&gt; &lt;!-- 静态资源不受保护 -...

    SpringSecurity 2 权限基于数据库--完整DEMO(带数据库文件)

    1. **SpringSecurity配置**: - SpringSecurity的核心在于其配置,通过XML或Java配置,我们可以定义用户认证和授权规则。在DEMO中,你会看到如何设置`http`元素来配置安全拦截器路径,以及如何定义`authentication-...

    Spring Security 3.1 +Spring +Servlet+JdbcTemplate

    在提供的压缩包中,`securitydb_2.sql`很可能包含了预设的数据库结构和初始数据,这些数据可能是为了设置Spring Security的安全配置,如用户角色、权限等。这通常涉及创建用户表、角色表以及它们之间的关联。执行这...

    spring-security3 配置和使用

    这个文件是 Spring Security 3 的核心配置文件,用于定义安全策略和授权规则。下面是一个基本的 security 配置文件示例: ```xml &lt;beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:...

    spring security 3.1.3 源码含sample源码

    Spring Security的配置通常是在Spring的XML配置文件中完成的,定义过滤器链、安全拦截器、认证和授权规则。3.1.3版本的配置可能包括了对旧版XML配置的支持。 **6. Sample项目** 提供的"sample"项目是一个运行实例,...

    spring security3.0.4 的acl使用例子

    `src`目录则是源代码存放的地方,可能包含了配置文件、Java源码和其他资源文件。 总的来说,这个例子提供了一个使用Spring Security 3.0.4的ACL特性的实践指南,帮助开发者实现对象级别的细粒度权限控制。通过理解...

    spring security3.0所有最新开发包及源码及文档

    3. **文档**:可能包括用户指南、API参考文档、开发者文档等,帮助开发者了解如何使用和配置Spring Security 3.0。 4. **示例代码**:演示了如何在实际应用中集成和使用Spring Security,有助于快速上手。 5. **...

    Spring-Security2.0 和 3.0中文文档

    开发者可以通过配置文件或注解来定制过滤器链。 5. **OAuth支持**: Spring Security 3.0 开始引入OAuth支持,允许与其他OAuth提供者进行集成,实现了社交登录等功能,比如通过Google、Facebook账户登录。 6. **...

    SpringBoot+vue+SpringSecurity电商后台管理系统

    【SpringBoot+vue+SpringSecurity电商后台管理系统】是一种基于现代技术栈构建的高效、安全的电商后台解决方案。这个系统利用了Spring Boot的便捷性、Vue.js的前端交互性和Spring Security的强大安全特性,为电商...

    spring security3配置和使用实例+教程

    `security_3`可能是一个包含Spring Security配置文件、Java类和其他相关资源的目录。这些类可能包括自定义的认证和授权类,如实现`UserDetailsService`接口的类,以便从数据库加载用户信息。 教程文档`教你使用_...

    springsecurity使用配置详解

    在提供的压缩包`springsecurity配置demo`中,你将找到示例代码和详细说明,这将帮助你更好地理解和实践上述概念。通过学习和实践这些示例,你将能够为自己的Spring应用程序构建强大的安全防护。

    Spring Security3技术手册

    - 在Spring Security配置中引用自定义的服务层代码,以替代原有的资源管理方式。 - **示例代码**: 在`spring-security.xml`中配置自定义资源管理逻辑。 **6. 控制用户信息** - **6.1 MD5加密** - 使用MD5算法...

    Spring Security3的使用方法

    首先,你需要在Spring的配置文件中引入Spring Security的命名空间,如`&lt;http&gt;`和`&lt;authentication-manager&gt;`。`&lt;http&gt;`元素用来配置安全性相关的HTTP拦截器,而`&lt;authentication-manager&gt;`则定义了用户认证的机制。 ...

    Spring Security in Action

    Spring Security 的配置主要通过 security.xml 文件实现。security.xml 文件中定义了身份验证、授权和访问控制等配置项。 六、Spring Security 的架构 Spring Security 的架构主要包括以下几层: * Presentation ...

    springsecurity 安全权限授权框架

    Spring Security 是一个强大的和高度可定制的身份验证和访问控制...通过分析项目中的 `springsecurity` 文件,我们可以看到具体实现这些功能的代码细节,这将有助于深入理解 Spring Security 的工作原理和最佳实践。

    spring3+struts2+hibernate3+dwr3+spring security3+ajax完整实例

    4. 配置Spring Security:在Spring Security的配置文件(如security.xml)中定义用户、角色和访问规则。 5. 配置DWR:创建dwr.xml,暴露服务器端的方法供JavaScript调用,实现Ajax通信。 6. 实现业务逻辑:编写...

    Spring-Boot1.52 SpringSecurity4 Spring Data Jpa 整合例子

    配置文件 接下来,需要在 `application.properties` 文件中配置数据库连接信息以及 Spring Security 的设置。 ```properties spring.datasource.url=jdbc:mysql://localhost:3306/testdb spring.datasource....

Global site tag (gtag.js) - Google Analytics