Announcement Announcement Module
Collapse
No announcement yet.
Accessing SPRING_SECURITY_LAST_USERNAME in the view Page Title Module
Move Remove Collapse
This topic is closed
X
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing SPRING_SECURITY_LAST_USERNAME in the view

    I got a little familiar with Acegi for a side project and took some time off from the project. Now Spring Security is out and I'm trying to move to the simpler configuration.

    However, I'm having trouble accessing SPRING_SECURITY_LAST_USERNAME in the AuthenticationProcessingFilter. How do I add AuthenticationProcessingFilter to my configuration and get access to it within my Freemarker templates?

    I'm relatively new to Freemarker, Spring, and Spring Security in general so I could be missing something obvious. Complicating matters is that I switched from Acegi & Velocity to Spring Security and Freemarker at the same time.

    Somehow, I need to expose org.springframework.security.ui.webapp.Authenticat ionProcessingFilter in the Freemarker template. Is there something I can do in the XML configuration?

    This is my current config:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <b:beans xmlns="http://www.springframework.org/schema/security"
        xmlns:b="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-2.0.xsd
                            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd">
    
      <!--  Authentication/Authorization -->
      <http auto-config='true'>
        <intercept-url pattern="/admin" access="ROLE_ADMIN"/>
        <intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
        <form-login login-page="/login.htm" authentication-failure-url="/login.htm?login_failed=1"/>
        <logout logout-success-url="/"/>
      </http>
      
      <authentication-provider>  
        <jdbc-user-service data-source-ref="dataSource"  
        users-by-username-query="SELECT username, pass, enabled FROM account WHERE username=?"  
        authorities-by-username-query="SELECT a.username, r.role AS authority FROM account a INNER JOIN account_roles ar ON a.id = ar.account_id INNER JOIN role r ON ar.role_id = r.id WHERE a.username = ?    
        "/>  
      </authentication-provider>  
    
    
      <b:bean id="authenticationProcessingFilter" class="org.springframework.security.ui.webapp.AuthenticationProcessingFilter">
        <custom-filter position="AUTHENTICATION_PROCESSING_FILTER"/>
        <b:property name="defaultTargetUrl" value="/"/>
        <b:property name="authenticationManager" ref="authenticationManager"/>
      </b:bean>
      
      <authentication-manager alias="authenticationManager"/>
    
      <!-- This bean is optional; it isn't used by any other bean as it only listens and logs -->
      <b:bean id="loggerListener" class="org.springframework.security.event.authentication.LoggerListener"/>
    </b:beans>
    Thanks.

  • #2
    Spring Security doesn't know anything about how your login page is rendered, so you can't set anything freemarker related in your security config. Why can't you just store the value in the model you are passing to freemarker?

    Comment

    Working...
    X