当前位置: 首页 > news >正文

微网站建设网站建设方案计划书人员规划

微网站建设,网站建设方案计划书人员规划,做百度推广一个月多少钱,万江网站建设公司安全任务#xff08;例如#xff0c;用户身份验证和用户查看应用程序资源的授权#xff09;通常由应用程序服务器处理。 可以将这些任务委托给Spring安全性流程#xff0c;以减轻应用程序服务器处理这些任务的负担。 Spring安全性基本上通过实现标准javax.servlet.Filter来… 安全任务例如用户身份验证和用户查看应用程序资源的授权通常由应用程序服务器处理。 可以将这些任务委托给Spring安全性流程以减轻应用程序服务器处理这些任务的负担。 Spring安全性基本上通过实现标准javax.servlet.Filter来处理这些任务。 为了在应用程序中初始化Spring安全性您需要在web.xml中声明以下过滤器 filterfilter-namespringSecurityFilterChain/filter-namefilter-classorg.springframework.web.filter.DelegatingFilterProxy/filter-class/filterfilter-mappingfilter-namespringSecurityFilterChain/filter-nameurl-pattern/*/url-pattern/filter-mapping 现在这个过滤器springSecurityFilterChain仅将请求委托给Spring安全框架在此框架中定义的安全任务将由在应用程序上下文中定义的安全过滤器处理。 那么这是怎么发生的呢 在DelegatingFilterProxyjavax.servlet.Filter的实现的doFilter方法内将检查spring应用程序上下文中是否有名为“ springSecurityFilterChain”的bean。 这个springSecurityFilterChainbean实际上是为spring过滤器链定义的别名。 alias namefilterChainProxy aliasspringSecurityFilterChain/ 因此当在应用程序上下文中完成检查时它将返回filterChainProxy bean。 此过滤器链与javax.servlet.FilterChain的链不同web.xml中定义的Java过滤器使用javax.servlet.FilterChain来调用下一个可能的过滤器如果存在的话或将请求传递给servlet / jsp。 bean filterChainProxy包含在Spring应用程序上下文中定义的安全过滤器的有序列表。 所以这是下一组问题 1.谁初始化/定义这个filterChainProxy 2.在Spring应用程序上下文中定义了哪些安全过滤器 3.这些安全过滤器与web.xml中定义的普通过滤器有何不同 现在是第一个问题当在应用程序上下文中定义了安全名称空间的‹http›元素时将初始化filterChainProxy。 这是‹http›元素的基本结构 sec:http auto-configtruesec:intercept-url pattern/** accessROLE_USER / /sec:httpsec:authentication-manager idauthenticationManagersec:authentication-providersec:user-servicesec:user nameadmin passwordpassword authoritiesROLE_USER, ROLE_ADMIN /sec:user nameuser passwordpassword authoritiesROLE_USER //sec:user-service/sec:authentication-provider /sec:authentication-manager 现在来自Spring框架的HttpSecurityBeanDefinitionParser读取了这个‹http›元素以在应用程序上下文中注册filterChainProxy。 将auto-config设置为true的http元素实际上是以下内容的简写形式 sec:httpsec:form-login /sec:http-basic /sec:logout / /sec:http 稍后我们将讨论‹http›的子元素。 因此现在提到第二个问题默认情况下所有过滤器都在过滤器链中注册了什么 这是Spring文档的答案 ‹http›名称空间块始终创建一个SecurityContextPersistenceFilter ExceptionTranslationFilter和FilterSecurityInterceptor 。 这些是固定的不能用替代方法替代。 因此默认情况下当我们添加‹http›元素时将添加以上三个过滤器。 并且由于将auto-config设置为trueBasicAuthenticationFilterLogoutFilter和UsernamePasswordAuthenticationFilter也被添加到过滤器链中。 现在如果您查看任何这些过滤器的源代码它们也是标准的javax.servlet.Filter实现。 但是通过在应用程序上下文而不是在web.xml中定义这些过滤器应用程序服务器会将控件转移到Spring以处理与安全性相关的任务。 Spring的filterChainProxy将负责链接将应用于请求的安全过滤器。 这回答了第三个问题。 为了更好地控制要应用于请求的安全筛选器我们可以定义自己的FilterChainProxy实现。 bean idfilterChainProxy classorg.springframework.security.web.FilterChainProxysec:filter-chain-map path-typeantsec:filter-chain pattern/images/* filtersnone/sec:filter-chain pattern/** filterssecurityContextFilter, logoutFilter, formLoginFilter, servletApiFilter, anonFilter, exceptionTranslator, filterSecurityInterceptor, customFilter1, customeFilter2 //sec:filter-chain-map /bean 从上面的xml中我们看到我们不希望对图像应用任何过滤器而对于其余的请求则指定了必须应用的一系列过滤器。 因此通常我们按照从最小约束到最大约束的顺序指定过滤器链。 但是通常不需要这种注册我们自己的过滤器链的方法。 Spring通过‹http›元素提供了多个挂钩通过这些挂钩我们可以更好地控制安全性的应用方式。 因此我们将详细介绍所有可以通过‹http›元素配置的内容。 1.身份验证HttpBasicAuthentication和基于表单登录的身份验证 2.通过ACL访问控制列表的授权支持 3.注销支持 4.匿名登录支持 5.记住我身份验证 6.并发会话管理 1身份验证身份验证可以通过两种方式处理-HttpBasicAuthentication和基于表单登录的身份验证。 我们将在短期内简要讨论这两个。 在理解这些内容之前最好对AuthenticationManager有基本的了解它是通过Spring安全性实现身份验证的核心。 在身份验证管理器元素内我们定义了可用于该应用程序的所有身份验证提供程序。 身份验证提供程序包含UserDetailsS​​ervice的实现。 Spring将用户信息加载到UserDetailsS​​ervice中并将用户名/密码组合与登录时提供的凭据进行比较。 这是UserDetailsS​​ervice接口 package org.springframework.security.core.userdetails;import org.springframework.dao.DataAccessException;/*** Core interface which loads user-specific data.* It is used throughout the framework as a user DAO and is the strategy used by the* {link org.springframework.security.authentication.dao.DaoAuthenticationProvider DaoAuthenticationProvider}.* The interface requires only one read-only method, which simplifies support for new data-access strategies.* see org.springframework.security.authentication.dao.DaoAuthenticationProvider* see UserDetails* author Ben Alex*/ public interface UserDetailsService {/*** Locates the user based on the username. In the actual implementation, the search may possibly be case* insensitive, or case insensitive depending on how the implementation instance is configured. In this case, the* codeUserDetails/code object that comes back may have a username that is of a different case than what was* actually requested..** param username the username identifying the user whose data is required.** return a fully populated user record (never codenull/code)** throws UsernameNotFoundException if the user could not be found or the user has no GrantedAuthority* throws DataAccessException if user could not be found for a repository-specific reason*/UserDetails loadUserByUsername(String username)throws UsernameNotFoundException, DataAccessException; } Spring提供了此服务的两个内置实现 a在应用程序上下文中存储用户登录名/密码详细信息 当应用程序的用户很少时这非常适合。 可以如下初始化 sec:authentication-manager idauthenticationManagersec:authentication-providersec:user-servicesec:user nameadmin passwordpassword authoritiesROLE_ADMIN,ROLE_USER/sec:user nameuser passwordpassword authoritiesROLE_USER//sec:user-service/sec:authentication-provider /sec:authentication-manager ‹authentication-provider›标记对应于DaoAuthenticationProvider它实际上调用提供的UserDetailsS​​ervice的实现。 在这种情况下我们将直接以XML提供用户名和密码。 当应用程序的用户群很大时我们希望将信息存储在数据库中。 为‹user-service›初始化的对应的Bean是org.springframework.security.core.userdetails.memory.InMemoryDaoImpl b在数据库中存储用户详细信息这是必须初始化的方式。 sec:authentication-manager idauthenticationManagersec:authentication-providersec:jdbc-user-service data-source-refdataSource //sec:authentication-provider /sec:authentication-manager Spring中的相应类是org.springframework.security.core.userdetails.jdbc.JdbcDaoImpl。 如果查看此类则可以发现用户名和密码存储在users表中可以分配给用户的角色存储在Authoritys表中。 稍后我们将讨论角色。 这些是此类从数据库中获取用户凭据和权限的查询 -- Fetch user credentials: select username,password,enabled from users where username ? -- Fetch user authorities: select username,authority from authorities where username ? 现在假设您有一个旧数据库您的用户详细信息存储在其他表中然后我们可以配置Spring为获取用户凭据和权限而执行的获取查询。 假设我有一个成员表其中包含ID用户名密码字段以及角色表其中包含用户名角色字段。 这是我们必须配置的方式 sec:authentication-manager idauthenticationManagersec:authentication-provider!-- TBD password-encoder hashmd5/ --sec:jdbc-user-service iduserDetailsService data-source-refdataSource users-by-username-querySELECT username, password, true as enabledFROM MEMBERWHERE username?authorities-by-username-querySELECT member.username, role.role as authoritiesFROM ROLE role, MEMBER memberWHERE role.member_idmember.id and member.username?//sec:authentication-provider /sec:authentication-manager 现在介绍执行身份验证的方法 HttpBasicAuthentication可以如下配置 sec:http auto-configtruesec:http-basic / /sec:http 默认情况下启用此选项后浏览器通常会显示一个登录对话框供用户登录。 代替登录对话框我们可以配置它以显示特定的登录页面。 这种身份验证是在超文本传输​​协议标准中正式定义的。 登录凭据以base 64编码已通过Authentication http标头发送到服务器。 但是它有它自己的缺点。 最大的问题与注销服务器有关。 大多数浏览器倾向于缓存会话不同的用户无法通过刷新浏览器重新登录。 定义‹http-basic›实际上在幕后定义了BasicAuthenticationFilter过滤器。 身份验证成功后身份验证对象将放入Spring securityContext中。 可以通过类SecurityContextHolder访问安全上下文。 这是BasicAuthenticationFilter bean声明的样子 sec:custom-filter positionBASIC_AUTH_FILTER refbasicAuthenticationFilter /bean idbasicAuthenticationFilter classorg.springframework.security.web.authentication.www.BasicAuthenticationFilterproperty nameauthenticationManager refauthenticationManager/property nameauthenticationEntryPoint refauthenticationEntryPoint/ /beanbean idauthenticationEntryPoint classorg.springframework.security.web.authentication.LoginUrlAuthenticationEntryPointproperty nameloginFormUrl value/login.jsp/ /bean 有关过滤器位置的更多详细信息请参阅枚举org.springframework.security.config.http.SecurityFilters 基于表单登录的身份验证这是我们启用它的方式 sec:form-login login-page/login.jsp/ 但是Spring提供了多个钩子。 属性default-target-url指定登录页面在用户进行身份验证后应该进入的位置而authentication-failure-url定义在身份验证失败时用户应该进入的页面。 sec:form-login login-page/login.jsp default-target-url/app/messagePost authentication-failure-url/login.jsp?errortrue/ 下一组属性是 始终使用默认目标身份验证成功处理程序引用和身份验证失败处理程序引用 。 身份验证成功时将调用authentication-success-handler-ref 身份验证失败时将调用authentication-failure-handler-ref 。 这是AuthenticationSuccessHandler和AuthenticationFailureHandler的接口。 /*** Strategy used to handle a successful user authentication.* p* Implementations can do whatever they want but typical behaviour would be to control the navigation to the* subsequent destination (using a redirect or a forward). For example, after a user has logged in by submitting a* login form, the application needs to decide where they should be redirected to afterwards* (see {link AbstractAuthenticationProcessingFilter} and subclasses). Other logic may also be included if required.** author Luke Taylor* since 3.0*/ public interface AuthenticationSuccessHandler {/*** Called when a user has been successfully authenticated.** param request the request which caused the successful authentication* param response the response* param authentication the ttAuthentication/tt object which was created during the authentication process.*/void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,Authentication authentication) throws IOException, ServletException; }/*** Strategy used to handle a failed authentication attempt.* p* Typical behaviour might be to redirect the user to the authentication page (in the case of a form login) to* allow them to try again. More sophisticated logic might be implemented depending on the type of the exception.* For example, a {link CredentialsExpiredException} might cause a redirect to a web controller which allowed the* user to change their password.** author Luke Taylor* since 3.0*/ public interface AuthenticationFailureHandler {/*** Called when an authentication attempt fails.* param request the request during which the authentication attempt occurred.* param response the response.* param exception the exception which was thrown to reject the authentication request.*/void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,AuthenticationException exception) throws IOException, ServletException; } Spring有2个内置的成功处理程序实现。 SimpleUrlAuthenticationSuccessHandler和SavedRequestAwareAuthenticationSuccessHandler。 后者扩展了前者。 SavedRequestAwareAuthenticationSuccessHandler的目的是将用户带到他已重定向到Login页面进行身份验证的页面。这是定义了form-login›元素时的默认成功处理程序。 我们也可以使用自定义实现来覆盖它。 假设我们总是希望在用户登录后显示特定页面而不是让他进入他之前所在的页面我们可以将always-use-default-target设置为true。 对于故障处理程序还有两种内置的实现SimpleUrlAuthenticationFailureHandler和ExceptionMappingAuthenticationFailureHandler。 后者扩展了前者。 我们仅在SimpleUrlAuthenticationFailureHandler的情况下指定单个URL在身份验证失败的情况下将引导用户进入在ExceptionMappingAuthenticationFailureHandler的情况下我们根据身份验证异常的类型指定用户将被引导到的多个URLorg.springframework的子类.security.core.AuthenticationException在身份验证过程中抛出UserDetailsS​​ervice实现将引发异常。 同样在定义自定义登录页面时我们将用户名和密码字段分别标记为j_username和j_password 并且Submit操作将默认为j_spring_security_check 。 我们还可以配置这些字段名称并通过分别指定以下属性来提交操作 用户名参数密码参数和login-processing-url 。 过滤器定义如下所示 sec:custom-filter positionFORM_LOGIN_FILTER refformLoginFilter / bean idformLoginFilter classorg.springframework.security.web.authentication.UsernamePasswordAuthenticationFilterproperty nameauthenticationManager refauthenticationManager/property namefilterProcessesUrl value/j_spring_security_check/property nameusernameParameter valueusername /property namepasswordParameter valuepassword/property nameauthenticationSuccessHandlerbean classorg.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler property namealwaysUseDefaultTargetUrl valuetrue/property namedefaultTargetUrl value/success.jsp//bean/propertyproperty nameauthenticationFailureHandler!--bean class org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler /--bean idauthenticationFailureHandler classorg.springframework.security.web.authentication.ExceptionMappingAuthenticationFailureHandlerproperty nameexceptionMappingspropsprop keyorg.springframework.security.authentication.BadCredentialsException/login/badCredentials/propprop keyorg.springframework.security.authentication.CredentialsExpiredException/login/credentialsExpired/propprop keyorg.springframework.security.authentication.LockedException/login/accountLocked/propprop keyorg.springframework.security.authentication.DisabledException/login/accountDisabled/prop/props/property/bean/property/bean 在表单登录的情况下如基本身份验证中所述注销不会有任何问题。 但是缺点是用户名和密码在标题中以明文形式发送。 这可以通过使用加密技术对密码进行编码来解决。 Spring使用身份验证提供程序中的‹password-encoder›元素对此提供了内置支持。 这是我们必须如何配置它 sec:authentication-manager idauthenticationManagersec:authentication-providersec:password-encoder hashmd5/sec:jdbc-user-service data-source-refdataSource //sec:authentication-provider /sec:authentication-manager 2.通过ACL进行授权支持 Spring通过‹http›中的‹intercept-url›支持授权。 sec:http access-decision-manager-refaccessDecisionManagersec:intercept-url pattern/app/messageList* accessROLE_USER,ROLE_ANONYMOUS/sec:intercept-url pattern/app/messagePost* accessROLE_USER/sec:intercept-url pattern/app/messageDelete* accessROLE_ADMIN/sec:intercept-url pattern/app/* accessROLE_USER/form-login login-page/login.jsp default-target-url/app/messagePost authentication-failure-url/login.jsp?errortrue/!-- Other settings -- /sec:http 每个intercept-url指定一个URL模式用户访问这些与指定模式匹配的URL必须具有的角色。 请注意网址格式始终以“ *”结尾。 如果未指定“ *”则问题是黑客可以通过仅在url中传递一些参数来绕过安全机制。 因此在幕后发生的事情是当Spring将所有这些URL作为元数据传递给FilterSecurityInterceptor时被拦截。 因此这是不使用‹intercept-url›即可配置的方法 sec:custom-filter positionFILTER_SECURITY_INTERCEPTOR reffilterSecurityInterceptor / bean idfilterSecurityInterceptor classorg.springframework.security.web.access.intercept.FilterSecurityInterceptorproperty nameauthenticationManager refauthenticationManager/property nameaccessDecisionManager refaccessDecisionManager/property namesecurityMetadataSourcesec:filter-security-metadata-source lowercase-comparisonstrue request-matcherant use-expressionstruesec:intercept-url pattern/app/messageList* accessROLE_USER,ROLE_ANONYMOUS/sec:intercept-url pattern/app/messagePost* accessROLE_USER/sec:intercept-url pattern/app/messageDelete* accessROLE_ADMIN/sec:intercept-url pattern/app/* accessROLE_USER//sec:filter-security-metadata-source/property /bean 因此从上面的代码中您可以看到匿名用户只能访问messageList页面并且要查看其他任何页面他应该以用户身份登录到应用程序。 同样如果您仔细观察Bean声明则有一个属性accessDecisionManager。 这样做的目的是什么 实际上是由Bean做出访问控制决策。 它必须实现AccessDecisionManager接口。 Spring提供了三个内置的访问决策管理器。 在了解访问决策管理器的工作原理之前我们需要知道AccessDecisionVoter到底是什么。 AccessDecisionManager实际上由一个或多个访问决策投票者组成。 该投票者封装了允许/拒绝/放弃用户查看资源的逻辑。 投票弃权或多或少类似于根本不投票因此投票结果由AccessDecisionVoter接口中定义的ACCESS_GRANTEDACCESS_DENIED和ACCESS_ABSTAIN常量字段表示。 我们可以定义自定义访问决策投票者并将其注入我们的访问决策管理器定义中。 现在回到内置的决策管理器他们是 AffirmativeBased至少一名选民必须投票才能授予访问权限 基于共识大多数选民必须投票才能授予访问权限 基于一致意见所有选民都必须投票弃权或授予访问权限无投票人投票才能拒绝访问 默认情况下将基于AffirmativeBased的访问决策管理器初始化其中包含2个投票者RoleVoter和AuthenticatedVoter。 如果用户具有所需角色RoleVoter会授予访问权限。 但是请注意如果投票者必须授予访问权限则该角色必须以“ ROLE_”前缀开头。 但这也可以为其他前缀定制。 我们将很快看到如何做。 AuthenticatedVoter仅在用户通过身份验证时才授予访问权限。 接受的身份验证级别为IS_AUTHENTICATED_FULLYIS_AUTHENTICATED_REMEMBERED和IS_AUTHENTICATED_ANONYMOUSLY。 假设我们要定义一个自定义投票器并将其添加到访问决策管理器中我们可以这样做 sec:http access-decision-manager-refaccessDecisionManager auto-configtrue!-- filters declaration go here-- /sec:httpbean idaccessDecisionManager classorg.springframework.security.access.vote.AffirmativeBasedproperty namedecisionVoterslistbean classorg.springframework.security.access.vote.RoleVoter!-- Customize the prefix--property namerolePrefix valueROLE_//beanbean classorg.springframework.security.access.vote.AuthenticatedVoter/bean classcom.pramati.security.voters.CustomVoter//list/property /bean 3.注销支持 Spring提供了一个处理程序来处理注销请求。 可以配置如下 sec:http!-- Other filter declarations here --sec:logout //sec:http 默认情况下注销URL映射到/ j_spring_security_logout 。 我们可以通过指定logout-url属性来自定义该URL。 同样当用户注销时他将被带到上下文路径根。 如果必须将用户重定向到其他URL则必须通过logout-success-url进行配置。 这是您的操作方式 sec:logout logout-url/j_logMeOut logout-success-url/app/messageList/ 如果您希望登录页面在不同的情况下有所不同而不是默认使用一个特定的网址那么我们必须实现LogoutSuccessHandler并将其引用到‹logout›元素 sec:logout logout-url/j_logMeOut success-handler-refcustomLogoutSuccessHandler/ 如果您不想使用‹logout›元素则可以按以下方法定义底层过滤器 sec:custom-filter positionLOGOUT_FILTER reflogoutFilter / bean idlogoutFilter classorg.springframework.security.web.authentication.logout.LogoutFilterconstructor-arg value/pages/Security/logout.html /constructor-arglistbean classorg.springframework.security.web.authentication.logout.SecurityContextLogoutHandler//list/constructor-argproperty namefilterProcessesUrl value/j_logMeOut/ /bean 4.匿名登录支持默认情况下Spring创建一个匿名角色。 因此当您将角色指定为“ ROLE_ANONYMOUS”或“ IS_AUTHENTICATED_ANONYMOUSLY”时任何匿名用户都可以查看该页面。 在AffirmativedBased访问决策管理器中当RoleVoter看到访问属性设置为“ ROLE_ANONYMOUS”时将授予访问权限。 同样如果将访问属性设置为“ IS_AUTHENTICATED_ANONYMOUSLY”则AuthenticatedVoter会授予访问权限。 假设要为匿名用户分配其他角色名称则可以按如下方式覆盖默认配置 sec:httpsec:intercept-url pattern/login.jsp* filtersnone/sec:intercept-url pattern/* accessROLE_USER/!-- Defines a custom role in place of ROLE_ANONYMOUS. ROLE_ANONYMOUS will no more work, use ROLE_GUEST instead of it--sec:anonymous usernameguest granted-authorityROLE_GUEST / /sec:httpp styletext-align: justify;Here is the how the underlying filter can be defined if you dont want to use ‹anonymous› element:/p1 sec:custom-filter positionANONYMOUS_FILTER refanonymousFilter / bean idanonymousFilter classorg.springframework.security.web.authentication.AnonymousAuthenticationFilter property nameuserAttribute valueROLE_GUEST / /bean 5.记住我身份验证这是指网站能够记住会话之间主体的身份。 Spring通过在成功进行交互式身份验证后向浏览器发送cookie来实现此目的该cookie的组成如下 base64用户名“” expirationTime “” md5Hex用户名“” expirationTime “”密码“” 键 现在当浏览器向服务器发出下一个请求时它还将与此Cookie一起发送。 现在Spring在幕后执行以下操作 a从后端检索给定用户名的密码 b从数据库中获取用户名的密码并计算用户名密码expirationTime和密钥的md5Hex并将其与Cookie中的值进行比较 c如果它们匹配–您已登录 如果不匹配则说明您提供了伪造的Cookie或者用户名/密码/密钥之一已更改。 我们可以通过在‹http›中添加元素来启用“记住我”身份验证。 这是我们的方法 sec:http!-- Other filter declarations here --sec:remember-me keymyAppKey//sec:http 通常将自动选择UserDetailsS​​ervice。 如果您的应用程序上下文中有多个则需要指定与user-service-ref属性一起使用的属性其中值是UserDetailsS​​ervice bean的名称。 需要注意的一点是这里存在一个潜在的安全问题因为“记住我”令牌可以被捕获并且由于它在到期之前一直有效而可能被滥用。 通过使用滚动令牌可以避免这种情况。 这是您可以实现基于令牌的“记住我”服务的方法 sec:http access-decision-manager-refaccessDecisionManager!-- Other filter declarations here --remember-me services-aliasrememberMeService data-source-refdataSource/!-- remember-me data-source-refdataSource keypramati/ --/sec:httpbean idtokenRepository classorg.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImplproperty namedataSource refdataSource/property namecreateTableOnStartup valuetrue/ /beanbean idrememberMeService classorg.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServicesproperty nameuserDetailsService refuserDetailsService/property nametokenRepository reftokenRepository/ /bean 注意事项 a因为在定义beantokenRepository时已指定createTableOnStartup为true所以将在数据库中创建一个新表persistent_logins。 这是用于创建表的sql create table persistent_logins (username varchar(64) not null,series varchar(64) primary key,token varchar(64) not null,last_used timestamp not null); b我们不再提供自己的安全令牌。 Spring将自动生成令牌并将其放入/更新到persistent_tokens表中。 当用户从浏览器访问应用程序并通过选择“记住我”选项登录到应用程序时将在此表中创建一个条目。 下次用户从同一浏览器登录时用户将自动登录并且数据库中的令牌值将更改为新值但系列值保持不变。 假设用户现在从其他浏览器登录并选择记住我那么将为该浏览器创建一个新条目。 当他从该浏览器访问应用程序时随后的更新将发生在该特定行本身上。 因此使用这种方法的好处是攻击者将只能使用被盗的cookie直到受害者用户下次访问该应用程序为止而不是像先前的单令牌方法那样在记住的cookie的整个生存期内使用它。 当受害者下一次访问该网站时他将使用相同的cookie。 现在Spring将抛出CookieTheftException该异常可用于通知用户发生了盗窃。 可以使用安全链中的自定义过滤器来定义它而不用使用到目前为止已使用的元素 sec:custom-filter positionREMEMBER_ME_FILTER refrememberMeFilter /bean idrememberMeFilter classorg.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilterproperty namerememberMeServices refrememberMeServices/property nameauthenticationManager reftheAuthenticationManager / /beanbean idtokenRepository classorg.springframework.security.web.authentication.rememberme.JdbcTokenRepositoryImplproperty namedataSource refdataSource/property namecreateTableOnStartup valuefalse/ /beanbean idrememberMeServices classorg.springframework.security.web.authentication.rememberme.PersistentTokenBasedRememberMeServicesproperty nameuserDetailsService refuserDetailsService/property nametokenRepository reftokenRepository/ /beanbean idrememberMeAuthenticationProvider classorg.springframework.security.authentication.rememberme.RememberMeAuthenticationProvider/ 6.并发会话管理假设我们不希望用户同时从多个位置登录到应用程序我们必须在Spring中启用此功能。 这是我们的方法 sec:http!-- Other filter declarations here --sec:session-management session-authentication-error-url/login.jsp?erroralreadyLoggedin sec:concurrency-control max-sessions1 error-if-maximum-exceededtrueexpired-url/login.jsp?erroralreadyLoggedin//sec:session-management /sec:http 此外我们还必须在web.xml中定义一个侦听器当用户从应用程序注销时该侦听器对于引发事件org.springframework.security.core.session.SessionDestroyedEvent是必需的。 listenerlistener-classorg.springframework.security.web.session.HttpSessionEventPublisher/listener-class /listener 那么现在幕后发生了什么 Spring如何获得这种支持 Spring使用的安全过滤器类似于我们一直在讨论的内容。 除此之外它还使用ApplicationEvents。 当spring看到需要并发控制时它将维护与主体相关联的会话列表。 映射结构如下所示实际上在org.springframework.security.core.session.SessionRegistryImpl中定义 ConcurrentMapObject,SetString principals new ConcurrentHashMapObject,SetString(); 此处映射的键是User对象该值是与他相关联的会话ID的集合。 因此当集合的大小大于‹concurrency-control›元素中定义的最大会话的值时将引发异常。 当Spring看到定义的并发控制元素时SessionRegistryImpl定义映射的地方将在ConcurrentSessionControlStrategy内部组成并注入到UsernamePasswordAuthenticationFilter中。 现在随着用户身份验证成功Spring在上面讨论的映射中添加了一个条目。 现在当用户注销时将在web.xml中定义侦听器时引发SessionDestroyedEvent如上所示。 SessionRegistryImpl侦听此事件并从正在维护的映射中删除会话ID条目。 否则即使用户退出另一个会话或超时一旦超过会话允许量用户将永远无法再次登录。 因此这是‹concurrency-control›的等效配置 sec:httpsec:custom-filter positionCONCURRENT_SESSION_FILTER refconcurrencyFilter /sec:custom-filter positionFORM_LOGIN_FILTER refmyAuthFilter /!-- Other filter declarations here --sec:session-management session-authentication-strategy-refsessionAuthenticationStrategy/ /sec:httpbean idconcurrencyFilter classorg.springframework.security.web.session.ConcurrentSessionFilterproperty namesessionRegistry refsessionRegistry /property nameexpiredUrl value/session-expired.htm / /beanbean idmyAuthFilter classorg.springframework.security.web.authentication.UsernamePasswordAuthenticationFilterproperty namesessionAuthenticationStrategy refsessionAuthenticationStrategy /property nameauthenticationManager refauthenticationManager / /beanbean idsessionAuthenticationStrategy classorg.springframework.security.web.authentication.session.ConcurrentSessionControlStrategyconstructor-arg namesessionRegistry refsessionRegistry /property namemaximumSessions value1 / /beanbean idsessionRegistry classorg.springframework.security.core.session.SessionRegistryImpl / 作为本文的总结本文涉及了框架的基本配置和底层类这对于根据我们的特定要求自定义安全性至关重要。 参考 Spring Security –在 prasanthnath博客上 JCG合作伙伴 Prasanth Gullapalli 的幕后花絮 。 翻译自: https://www.javacodegeeks.com/2013/11/spring-security-behind-the-scenes.html
http://www.pierceye.com/news/625093/

相关文章:

  • 专门教做衣服的网站西宁电商网站建设
  • 无锡网站科技公司qq哪家公司开发的
  • 强化 门户网站建设今天的新闻大事
  • 专业做刀具网站的公司单页面网站模板
  • 企业网站制作及cms技术wordpress站点 HTML
  • 网络宣传网站建设制作加盟网络推广方案怎么写
  • 花店网站建设毕设介绍wordpress批量导入txt
  • 上海市网站建设定制百度推广怎么优化关键词的质量
  • 建设工程质量检测公司网站html5 响应式音乐网站
  • 网站建设托管推广海报中文域名做的网站
  • 临沂专业网站建设公司哪家好网站建设的网页
  • 当牛做吗网站源代码分享百度云帝国怎么做网站
  • 简约网站欣赏做美食网站赚钱吗
  • 一叶子网站建设目标教育平台oss做视频网站
  • 购物网站开发流程图wordpress 批量注册
  • 如何做网站优化的内容google网站推广
  • 网站模版亮点北京电商网站开发费用
  • 南昌专业的企业网站建设公司wordpress源码在哪
  • 农家院做宣传应该在哪个网站营销代码查询
  • 大型企业网站设计案例晋江做网站的公司哪家好
  • 海外模板网站有哪些全国网页设计大赛
  • 网站设计常州注册公司没有地址怎么弄
  • 注销建设工程规划许可证在哪个网站wordpress+Apache升级
  • 视频网站如何做盗链青岛商城网站开发
  • 网站主色调googleapis wordpress
  • 作网站番禺区网络推广渠道
  • app开发网站排行app制作平台排行
  • 盐城网站建设找哪家好个人如何做短视频网站
  • 域名进行网站备案吗2023年重启核酸
  • 为什么几年前做的网站视频看不了wordpress图片标签