Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Take a look at <code>SecurityContextPersistenceFilter</code> class. It defines how the <code>SecurityContextHolder</code> is populated. By default it uses <code>HttpSessionSecurityContextRepository</code> to store security context in http session. </p> <p>I have implemented this mechanism quite easily, with custom <code>SecurityContextRepository</code>.</p> <p>See the <code>securityContext.xml</code> below:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:sec="http://www.springframework.org/schema/security" xmlns:jee="http://www.springframework.org/schema/jee" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"&gt; &lt;context:annotation-config/&gt; &lt;sec:global-method-security secured-annotations="enabled" pre-post-annotations="enabled"/&gt; &lt;bean id="securityContextRepository" class="com.project.server.security.TokenSecurityContextRepository"/&gt; &lt;bean id="securityContextFilter" class="com.project.server.security.TokenSecurityContextPersistenceFilter"&gt; &lt;property name="repository" ref="securityContextRepository"/&gt; &lt;/bean&gt; &lt;bean id="logoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter"&gt; &lt;constructor-arg value="/login.jsp"/&gt; &lt;constructor-arg&gt; &lt;list&gt; &lt;bean class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler"/&gt; &lt;/list&gt; &lt;/constructor-arg&gt; &lt;/bean&gt; &lt;bean id="formLoginFilter" class="org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter"&gt; &lt;property name="authenticationManager" ref="authenticationManager"/&gt; &lt;property name="authenticationSuccessHandler"&gt; &lt;bean class="com.project.server.security.TokenAuthenticationSuccessHandler"&gt; &lt;property name="defaultTargetUrl" value="/index.html"/&gt; &lt;property name="passwordExpiredUrl" value="/changePassword.jsp"/&gt; &lt;property name="alwaysUseDefaultTargetUrl" value="true"/&gt; &lt;/bean&gt; &lt;/property&gt; &lt;property name="authenticationFailureHandler"&gt; &lt;bean class="com.project.server.modules.security.CustomUrlAuthenticationFailureHandler"&gt; &lt;property name="defaultFailureUrl" value="/login.jsp?failure=1"/&gt; &lt;/bean&gt; &lt;/property&gt; &lt;property name="filterProcessesUrl" value="/j_spring_security_check"/&gt; &lt;property name="allowSessionCreation" value="false"/&gt; &lt;/bean&gt; &lt;bean id="servletApiFilter" class="org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter"/&gt; &lt;bean id="anonFilter" class="org.springframework.security.web.authentication.AnonymousAuthenticationFilter"&gt; &lt;property name="key" value="ClientApplication"/&gt; &lt;property name="userAttribute" value="anonymousUser,ROLE_ANONYMOUS"/&gt; &lt;/bean&gt; &lt;bean id="exceptionTranslator" class="org.springframework.security.web.access.ExceptionTranslationFilter"&gt; &lt;property name="authenticationEntryPoint"&gt; &lt;bean class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"&gt; &lt;property name="loginFormUrl" value="/login.jsp"/&gt; &lt;/bean&gt; &lt;/property&gt; &lt;property name="accessDeniedHandler"&gt; &lt;bean class="org.springframework.security.web.access.AccessDeniedHandlerImpl"&gt; &lt;property name="errorPage" value="/login.jsp?failure=2"/&gt; &lt;/bean&gt; &lt;/property&gt; &lt;property name="requestCache"&gt; &lt;bean id="nullRequestCache" class="org.springframework.security.web.savedrequest.NullRequestCache"/&gt; &lt;/property&gt; &lt;/bean&gt; &lt;alias name="filterChainProxy" alias="springSecurityFilterChain"/&gt; &lt;bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy"&gt; &lt;sec:filter-chain-map path-type="ant"&gt; &lt;sec:filter-chain pattern="/**" filters="securityContextFilter, logoutFilter, formLoginFilter, servletApiFilter, anonFilter, exceptionTranslator, filterSecurityInterceptor"/&gt; &lt;/sec:filter-chain-map&gt; &lt;/bean&gt; &lt;bean id="filterSecurityInterceptor" class="org.springframework.security.web.access.intercept.FilterSecurityInterceptor"&gt; &lt;property name="securityMetadataSource"&gt; &lt;sec:filter-security-metadata-source use-expressions="true"&gt; &lt;sec:intercept-url pattern="/staticresources/**" access="permitAll"/&gt; &lt;sec:intercept-url pattern="/index.html*" access="hasRole('USER_ROLE')"/&gt; &lt;sec:intercept-url pattern="/rpc/*" access="hasRole('USER_ROLE')"/&gt; &lt;sec:intercept-url pattern="/**" access="permitAll"/&gt; &lt;/sec:filter-security-metadata-source&gt; &lt;/property&gt; &lt;property name="authenticationManager" ref="authenticationManager"/&gt; &lt;property name="accessDecisionManager" ref="accessDecisionManager"/&gt; &lt;/bean&gt; &lt;bean id="accessDecisionManager" class="org.springframework.security.access.vote.AffirmativeBased"&gt; &lt;property name="decisionVoters"&gt; &lt;list&gt; &lt;bean class="org.springframework.security.access.vote.RoleVoter"/&gt; &lt;bean class="org.springframework.security.web.access.expression.WebExpressionVoter"/&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="authenticationManager" class="org.springframework.security.authentication.ProviderManager"&gt; &lt;property name="providers"&gt; &lt;list&gt; &lt;bean name="authenticationProvider" class="com.project.server.modules.security.oracle.StoredProcedureBasedAuthenticationProviderImpl"&gt; &lt;property name="dataSource" ref="serverDataSource"/&gt; &lt;property name="userDetailsService" ref="userDetailsService"/&gt; &lt;property name="auditLogin" value="true"/&gt; &lt;property name="postAuthenticationChecks" ref="customPostAuthenticationChecks"/&gt; &lt;/bean&gt; &lt;/list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;bean id="customPostAuthenticationChecks" class="com.project.server.modules.security.CustomPostAuthenticationChecks"/&gt; &lt;bean name="userDetailsService" class="com.project.server.modules.security.oracle.UserDetailsServiceImpl"&gt; &lt;property name="dataSource" ref="serverDataSource"/&gt; &lt;/bean&gt; &lt;/beans&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload