Back Forum Reply New

Changing user back to anonymous on 'logout' ?

Hi,

I have Acegi working with ROLE_USER and ROLE_ANONYMOUS. I want to have a 'logout' which should result in the Authenication object held in the session changing from a specific user back to being the anonymous user. What is the easiest way to do this ?

thanks

:roll: quite simple really:

ContextHolder.setContext(null);

- when using acegi-security-0.8.2.jaror (I believe)

SecurityContextHolder.getContext().setAuthenticati  on(null);

- when using 0.9 or higher

Hi djmh68

But when i call ContextHolder.setContext(null), it generated an exception like this

java.lang.IllegalStateException: ContextHolder invalid: 'null': are your filtersordered correctly? fromSessionContextIntegrationFilter should have already exec
uted by this time (look for it in the stack dump below)

what do you think?
Thanks

Don't know why you're getting an exception. My app 'logsout' without producing an exception, using ContextHolder.setContext(null). This is a copy of my config as it relates to Acegi:

lt;?xml version=quot;1.0quot; encoding=quot;UTF-8quot;?gt;
lt;!DOCTYPE beans PUBLIC quot;-//SPRING//DTD BEAN//ENquot; quot;dtd/spring-beans.dtdquot;gt;

lt;beansgt;
   lt;!-- ======================== FILTER CHAIN ======================= --gt;   lt;bean id=quot;filterChainProxyquot; class=quot;net.sf.acegisecurity.util.FilterChainProxyquot;  gt;       lt;property name=quot;filterInvocationDefinitionSourcequot;gt; lt;valuegt;  CONVERT_ucl_TO_LOWERCASE_BEFORE_COMPARISON  PATTERN_TYPE_APACHE_ANT    /**=fromSessionContextIntegrationFilter,authenticat  ionProcessingFilter,anonymousProcessingFilter,secu  rityEnforcementFilter lt;/valuegt;       lt;/propertygt;   lt;/beangt;     lt;!-- ======================== AUTHENTICATION ======================= --gt;

lt;!-- authenticationManager --gt;   lt;bean id=quot;authenticationManagerquot; class=quot;net.sf.acegisecurity.providers.ProviderMana  gerquot;gt;     lt;property name=quot;providersquot;gt;        lt;listgt;lt;ref bean=quot;daoAuthenticationProviderquot; /gt;lt;ref local=quot;anonymousAuthenticationProviderquot;/gt;        lt;/listgt;     lt;/propertygt;  lt;/beangt;    lt;!-- authenticationDao --gt;  lt;bean id=quot;authenticationDaoquot; class=quot;net.sf.acegisecurity.providers.dao.jdbc.Jdb  cDaoImplquot;gt;     lt;property name=quot;dataSourcequot;gt;lt;ref bean=quot;dataSourcequot; /gt;lt;/propertygt;  lt;/beangt;

lt;!-- daoAuthenticationProvider --gt;  lt;bean id=quot;daoAuthenticationProviderquot; class=quot;net.sf.acegisecurity.providers.dao.DaoAuthe  nticationProviderquot;gt;     lt;property name=quot;authenticationDaoquot;gt;lt;ref bean=quot;authenticationDaoquot; /gt;lt;/propertygt;  lt;/beangt;    lt;!-- Automatically receives AuthenticationEvent messages from DaoAuthenticationProvider --gt;  lt;bean id=quot;loggerListenerquot; class=quot;net.sf.acegisecurity.providers.dao.event.Lo  ggerListenerquot;/gt;    lt;!-- anonymousProcessingFilter --gt;  lt;bean id=quot;anonymousProcessingFilterquot; class=quot;net.sf.acegisecurity.providers.anonymous.An  onymousProcessingFilterquot;gt;     lt;property name=quot;keyquot;gt;lt;valuegt;foobarlt;/valuegt;lt;/propertygt;     lt;property name=quot;userAttributequot;gt;lt;valuegt;anonymousUser,ROLE_ANO  NYMOUSlt;/valuegt;lt;/propertygt;  lt;/beangt;

lt;!-- anonymousAuthenticationProvider --gt;  lt;bean id=quot;anonymousAuthenticationProviderquot; class=quot;net.sf.acegisecurity.providers.anonymous.An  onymousAuthenticationProviderquot;gt;     lt;property name=quot;keyquot;gt;lt;valuegt;foobarlt;/valuegt;lt;/propertygt;  lt;/beangt;    lt;!-- roleVoter --gt;  lt;bean id=quot;roleVoterquot; class=quot;net.sf.acegisecurity.vote.RoleVoterquot; /gt;

lt;!-- accessDecisionManager --gt;  lt;bean id=quot;accessDecisionManagerquot; class=quot;net.sf.acegisecurity.vote.AffirmativeBasedquot;  gt;     lt;property name=quot;allowIfAllAbstainDecisionsquot;gt;lt;valuegt;falselt;/valuegt;lt;/propertygt;     lt;property name=quot;decisionVotersquot;gt;        lt;listgt;lt;ref bean=quot;roleVoterquot; /gt;        lt;/listgt;     lt;/propertygt;  lt;/beangt;    lt;!-- fromSessionContextIntegrationFilter --gt;  lt;bean id=quot;fromSessionContextIntegrationFilterquot; class=quot;net.sf.acegisecurity.context.fromSessionCon  textIntegrationFilterquot;gt;     lt;property name=quot;contextquot;gt;lt;valuegt;net.sf.acegisecurity.context  .security.SecureContextImpllt;/valuegt;lt;/propertygt;  lt;/beangt;    lt;!-- securityEnforcementFilter --gt;  lt;bean id=quot;securityEnforcementFilterquot; class=quot;net.sf.acegisecurity.intercept.web.Security  EnforcementFilterquot;gt;     lt;property name=quot;filterSecurityInterceptorquot;gt;lt;ref bean=quot;filterInvocationInterceptorquot; /gt;lt;/propertygt;     lt;property name=quot;authenticationEntryPointquot;gt;lt;ref bean=quot;authenticationEntryPointquot; /gt;lt;/propertygt;  lt;/beangt;    lt;!-- authenticationProcessingFilter --gt;  lt;bean id=quot;authenticationProcessingFilterquot; class=quot;net.sf.acegisecurity.ui.webapp.Authenticati  onProcessingFilterquot;gt;lt;property name=quot;authenticationFailureuclquot;gt;lt;valuegt;/security/login.html?login_error=truelt;/valuegt;lt;/propertygt;lt;property name=quot;defaultTargetuclquot;gt;lt;valuegt;/home/welcome.htmllt;/valuegt;lt;/propertygt;lt;property name=quot;filterProcessesuclquot;gt;lt;valuegt;/security/j_acegi_security_check.htmllt;/valuegt;lt;/propertygt;lt;property name=quot;authenticationManagerquot;gt;lt;ref bean=quot;authenticationManagerquot;/gt;lt;/propertygt;
lt;/beangt;    lt;!-- authenticationEntryPoint --gt;  lt;bean id=quot;authenticationEntryPointquot; class=quot;net.sf.acegisecurity.ui.webapp.Authenticati  onProcessingFilterEntryPointquot;gt;     lt;property name=quot;loginFormuclquot;gt;lt;valuegt;/security/login.htmllt;/valuegt;lt;/propertygt;  lt;/beangt;    lt;!-- fromRequestAccessDecisionManager --gt;  lt;bean id=quot;fromRequestAccessDecisionManagerquot; class=quot;net.sf.acegisecurity.vote.AffirmativeBasedquot;  gt;     lt;property name=quot;allowIfAllAbstainDecisionsquot;gt;lt;valuegt;falselt;/valuegt;lt;/propertygt;     lt;property name=quot;decisionVotersquot;gt;        lt;listgt;lt;ref bean=quot;roleVoterquot;/gt;        lt;/listgt;     lt;/propertygt;  lt;/beangt;    lt;!-- filterInvocationInterceptor --gt;  lt;bean id=quot;filterInvocationInterceptorquot; class=quot;net.sf.acegisecurity.intercept.web.FilterSe  curityInterceptorquot;gt;     lt;property name=quot;authenticationManagerquot;gt;lt;ref bean=quot;authenticationManagerquot; /gt;lt;/propertygt;     lt;property name=quot;accessDecisionManagerquot;gt;lt;ref bean=quot;accessDecisionManagerquot; /gt;lt;/propertygt;     lt;property name=quot;objectDefinitionSourcequot;gt;        lt;valuegt;
CONVERT_ucl_TO_LOWERCASE_BEFORE_COMPARISON
PATTERN_TYPE_APACHE_ANT
/security/**=ROLE_ANONYMOUS,ROLE_REGISTERED
/home/**=ROLE_ANONYMOUS,ROLE_REGISTERED
/registered/**=ROLE_REGISTERED        lt;/valuegt;     lt;/propertygt;  lt;/beangt;
lt;/beansgt;
¥
Back Forum Reply New