`
xxtianxiaxing
  • 浏览: 691000 次
  • 性别: Icon_minigender_1
  • 来自: 陕西
社区版块
存档分类
最新评论

spring security 配置

阅读更多
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
	xmlns:jee="http://www.springframework.org/schema/jee" xmlns:jms="http://www.springframework.org/schema/jms"
	xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
		http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd
		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
	
	
	<!-- login start -->
	<bean id="filterChainProxy" class="org.springframework.security.util.FilterChainProxy">
		<property name="filterInvocationDefinitionSource">
			<value><![CDATA[
				CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
				PATTERN_TYPE_APACHE_ANT
				/**=channelProcessingFilter,httpSessionContextIntegrationFilter,logoutFilter,authenticationProcessingFilter,concurrentSessionFilter,rememberMeProcessingFilter,anonymousProcessingFilter,exceptionTranslationFilter,filterSecurityInterceptor
			]]></value>
				<!-- securityContextHolderAwareRequestFilter,rememberMeProcessingFilter,anonymousProcessingFilter, -->
		</property>
	</bean>
	
	<bean id="httpSessionContextIntegrationFilter" class="org.springframework.security.context.HttpSessionContextIntegrationFilter"/>
	
	<!-- login out -->
	<bean id="logoutFilter" class="org.springframework.security.ui.logout.LogoutFilter">
		<constructor-arg>
			<list>
				<bean class="org.springframework.security.ui.logout.SecurityContextLogoutHandler"/>
			</list>
		</constructor-arg>
		<constructor-arg value="/web/page/login/login_out_success.jsp"/>
		<property name="filterProcessesUrl" value="/loginout.do"/>
	</bean>
	
	<!-- login -->
	<bean id="authenticationProcessingFilter" class="org.springframework.security.ui.webapp.AuthenticationProcessingFilter">
		<property name="filterProcessesUrl" value="/login.do"/>
		<property name="defaultTargetUrl" value="/web/page/login/login_name.jsp"/>
		<property name="authenticationFailureUrl" value="http://www.baidu.com"/>
		<property name="authenticationManager" ref="authenticationManager"/>
		<property name="rememberMeServices" ref="rememberMeServices"/>
	</bean>
	<bean id="authenticationManager" class="org.springframework.security.providers.ProviderManager">
		<property name="providers">
			<list>
				<ref bean="daoAuthenticationProvider"/>
				<bean class="org.springframework.security.providers.rememberme.RememberMeAuthenticationProvider">
					<property name="key" value="hereonline"/>
				</bean>
				<ref local="anonymousAuthenticationProvider"/>
			</list>
		</property>
		<property name="sessionController" ref="concurrentSessionController"/>
	</bean>
	
	<bean id="daoAuthenticationProvider" class="org.springframework.security.providers.dao.DaoAuthenticationProvider">
		<property name="userDetailsService" ref="hoUserDAO"></property>
	</bean>
	
	<!-- login start end-->
	
	
	<!-- url -->
	<bean id="filterSecurityInterceptor" class="org.springframework.security.intercept.web.FilterSecurityInterceptor">
		<property name="authenticationManager" ref="authenticationManager"/>
		<property name="accessDecisionManager" ref="accessDecisionManager"/>
		<property name="objectDefinitionSource">
			<value>
				CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
				PATTERN_TYPE_APACHE_ANT
				/web/page/login/login_id.jsp = PRI_1,PRI_ADMIN
			</value>
		</property>		
	</bean>
	
	<bean id="accessDecisionManager" class="org.springframework.security.vote.AffirmativeBased">
		<property name="allowIfAllAbstainDecisions" value="true"/>
		<property name="decisionVoters">
			<list>
				<ref bean="roleVoter"/>
			</list>
		</property>
	</bean>
	
	<bean id="roleVoter" class="org.springframework.security.vote.RoleVoter">
		<property name="rolePrefix" value="PRI_"></property>
	</bean>
	
	<!-- exception convert -->
	<bean id="exceptionTranslationFilter" class="org.springframework.security.ui.ExceptionTranslationFilter">
		<property name="authenticationEntryPoint">
			<ref local="authenticationProcessingFilterEntryPoint"/>
		</property>
		<property name="accessDeniedHandler">
			<bean class="org.springframework.security.ui.AccessDeniedHandlerImpl">
				<property name="errorPage" value="/web/page/login/login_foward_login.jsp"/>
			</bean>
		</property>
	</bean>
	
	<bean id="authenticationProcessingFilterEntryPoint" class="org.springframework.security.ui.webapp.AuthenticationProcessingFilterEntryPoint">
		<property name="loginFormUrl" value="/web/page/login/login_err.jsp"/>
	</bean>
	
	<!-- 设置cookie 属性-->
	<bean id="rememberMeServices" class="org.springframework.security.ui.rememberme.TokenBasedRememberMeServices">
		<property name="tokenValiditySeconds" value="5"/>
		<property name="key" value="hereonline"/>
		<property name="userDetailsService" ref="hoUserDAO"/>
	</bean>	
	
	<!-- cookie 自动登录 -->
	<bean id="rememberMeProcessingFilter" class="org.springframework.security.ui.rememberme.RememberMeProcessingFilter">
		<property name="rememberMeServices" ref="rememberMeServices"/>
		<property name="authenticationManager" ref="authenticationManager"/>
	</bean>
	
	<!-- 阻止用户在成功登录之后再进行一次成功登录  -->
	<bean id="concurrentSessionController" class="org.springframework.security.concurrent.ConcurrentSessionControllerImpl">
		<property name="maximumSessions" value="1"/>
		<property name="exceptionIfMaximumExceeded" value="true"/>
		<property name="sessionRegistry" ref="sessionRegistry"/>
	</bean>
	<!-- 通过监听HttpSessionEventPublisher 发的不的时间记录用户Session 并发数 -->
	<bean id="sessionRegistry" class="org.springframework.security.concurrent.SessionRegistryImpl"/>
	
	<bean id="concurrentSessionFilter" class="org.springframework.security.concurrent.ConcurrentSessionFilter">
		<property name="sessionRegistry" ref="sessionRegistry"/>
		<property name="expiredUrl" value="/web/page/login/session_err.jsp"/>
	</bean>
		 
		
	<!-- 匿名用户处理过滤器 -->
	<bean id="anonymousProcessingFilter" class="org.springframework.security.providers.anonymous.AnonymousProcessingFilter">
		<property name="key" value="hereonline"/>
		<property name="userAttribute" value="ANONYMOUSUSER,PRI_ANONYMOUSUSER"/>
	</bean>
	<!-- 匿名用户认证提供 -->
	<bean id="anonymousAuthenticationProvider" class="org.springframework.security.providers.anonymous.AnonymousAuthenticationProvider">
		<property name="key" value="hereonline"/>
	</bean>
	
	<!-- acegi的通道过滤器 -->
	<bean id="channelProcessingFilter" class="org.springframework.security.securechannel.ChannelProcessingFilter">
		<property name="channelDecisionManager" ref="channelDecisionManager"/>
		<property name="filterInvocationDefinitionSource">
			<value>
				CONVERT_URL_TO_UPPERCASE_BEFORE_COMPARISON
				\A/web/page/login/login_name.jsp\Z=REQUIRES_SECURE_CHANNEL
				\A/j_acegi_security_check.*\Z=REQUIRES_SECURE_CHANNEL
				\A.*\Z=REQUIRES_INSECURE_CHANNEL
			</value>
		</property>
	</bean>
	
	<bean id="channelDecisionManager" class="org.springframework.security.securechannel.ChannelDecisionManagerImpl">
		<property name="channelProcessors">
			<list>
				<ref local="secureChannelProcessor"/>
				<bean class="org.springframework.security.securechannel.InsecureChannelProcessor"/>
			</list>
		</property>
	</bean>
	
	<bean id="secureChannelProcessor" class="org.springframework.security.securechannel.SecureChannelProcessor">
		<property name="entryPoint" ref="retryWithHttpsEntryPoint"/>
	</bean>
	
	<bean id="retryWithHttpsEntryPoint" class="org.springframework.security.securechannel.RetryWithHttpsEntryPoint">
		<property name="portMapper" ref="portMapper"/>
	</bean>
	
	<bean id="portMapper" class="org.springframework.security.util.PortMapperImpl">
		<property name="portMappings">
			<map>
				<entry key="8888" value="8443"></entry>
			</map>
		</property>
	</bean>
	
	
	
	<bean id="loggerListener" class="org.springframework.security.event.authentication.LoggerListener"/>

	<bean class="cn.com.hereonline.sso.listener.LoginSuccessListener"/>
	
</beans>


分享到:
评论

相关推荐

    spring cloud2.0 eureka server spring security配置

    以上就是关于Spring Cloud 2.0中Eureka Server与Spring Security配置的相关知识点。通过这些配置,你可以确保Eureka Server的数据安全,防止未授权的访问。在实际项目中,还需要根据具体的业务需求进行调整和优化。

    spring security配置实例

    ### Spring Security配置实例详解 #### 一、Spring Security简介与应用场景 Spring Security 是一个功能强大的安全框架,提供了全面的安全服务,支持认证、授权以及其他安全服务。它为开发人员提供了高度可定制化...

    springsecurity使用配置详解

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

    Restful风格服务端应用的Spring Boot + Spring Security配置

    这篇博客将深入探讨如何配置Spring Boot与Spring Security,以创建一个安全的RESTful服务。 首先,我们需要理解Spring Boot的核心特性,它简化了Spring应用程序的初始化和配置过程。通过自动配置和起步依赖,Spring...

    SPRING SECURITY配置

    **Spring Security配置详解** Spring Security是一款强大的安全框架,它为Java应用提供了全面的安全服务,包括认证、授权和访问控制。本文将深入探讨Spring Security的核心概念、配置方式以及常见应用场景。 ### 1...

    Spring Security 配置实例XML文件

    Spring Security 配置实例XML文件

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

    教程文档`教你使用_SpringSecurity_3.0_52页.pdf`会详细指导你如何一步步配置和使用Spring Security。它应该包含了配置文件的示例、如何集成到Spring应用中、如何创建自定义认证逻辑以及如何进行授权设置等内容。...

    26.JavaWeb-SpringSecurity安全框架-SpringSecurity配置类

    SpringSecurity配置类

    spring security 配置(含源码)

    了解了这些核心概念后,你可以通过`springsecurity-sample`项目中的代码实践,进一步熟悉Spring Security的配置和使用。这个项目可能包含了一个简单的Spring Boot应用,其中已经集成了Spring Security,并提供了一些...

    详解spring security 配置多个AuthenticationProvider

    Spring Security 配置多个 AuthenticationProvider 详解 Spring Security 是一个功能强大且灵活的安全框架,提供了多种身份验证机制和访问控制机制。在实际开发中,我们经常需要配置多个身份验证提供程序...

    spring-security多登录页面配置

    ### Spring Security 多登录页面配置详解 在许多大型企业级应用中,为了更好地实现权限管理和用户体验,往往会采用多个登录页面的方式来进行用户身份验证。这种方式能够有效地将不同类型的用户(如前台用户、后台...

    SpringBoot+SpringSecurity处理Ajax登录请求问题(推荐)

    SpringBoot+SpringSecurity处理Ajax登录请求问题 SpringBoot+SpringSecurity处理Ajax登录请求问题是SpringBoot开发中的一個常见问题,本文将详细介绍如何使用SpringBoot+SpringSecurity处理Ajax登录请求问题。 ...

    java学习之SpringSecurity配置了登录链接无权限

    我们在使用SpringSecurity作为后台权限框架的时候,框架给我们提供了配置登录请求的接口,供我们配置登录链接,当我们配置了登录链接地址后,前端访问登陆请求的时候显示无权限。 异常分析 由于SpringSecurity的...

    spring security 2 配置说明

    - **配置**:这是Spring Security配置中最核心的部分,通过`&lt;http&gt;`元素可以定义哪些URL需要进行身份验证和授权。`auto-config='true'`属性表示自动配置,简化了配置过程。`&lt;intercept-url&gt;`元素用于指定特定URL的...

    SpringSecurity笔记,编程不良人笔记

    在`SpringSecurity.md`和`SpringSecurity.pdf`文档中,可能包含SpringSecurity配置、自定义用户服务、授权策略等方面的代码示例。`codes`目录可能包含实际运行的项目代码,方便读者实践和理解。 8. **图笔记.draw...

    Spring Security 配置

    介绍了Spring Security 的配置方法及其使用技巧

    Spring Security 基本使用和配置代码

    这是自定义Spring Security配置的主要地方。你可以重写`configure(HttpSecurity http)`方法来定义HTTP安全规则。 ```java @Configuration @EnableWebSecurity public class SecurityConfig extends ...

    精彩:Spring Security 演讲PPT

    3. **定义安全规则**: 在Spring Security配置文件中定义具体的认证和授权规则,如使用数据库存储用户信息、使用自定义登录页面等。 #### 四、Spring Security 2.x 概览 Spring Security 2.x不仅提供了强大的功能...

    springSecurity 实现传参

    1. **配置Spring Security**:在Spring Security配置类中,你需要定义哪些URL需要保护,哪些不需要。例如,通常登录页面是公开的,而其他所有页面都需要身份验证。你可以使用`http.authorizeRequests()`方法来配置...

    SpringSecurity入门小demo(SSM+Spring Security)

    在 `HelloSpringSecurity` 文件中,你可能看到以下关键代码: - **WebSecurityConfigurerAdapter** 类:这是 Spring Security 提供的配置适配器,可以覆盖其方法来定制安全规则。 - `configure(HttpSecurity http)...

Global site tag (gtag.js) - Google Analytics