Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Finally I was able to resolved my problem. Instead of using filter I have added handler which only invokes for successful login.</p> <p>Following line is added in security.xml</p> <pre><code>&lt;form-login login-page="/" authentication-failure-url="/?login_error=1" default-target-url="/" always-use-default-target="false" authentication-success-handler-ref="authenticationSuccessHandler"/&gt; &lt;logout /&gt; &lt;beans:bean id="authenticationSuccessHandler" class="security.CustomSuccessHandler"/&gt; </code></pre> <p>Also I have added one custom handler which add session attribute.</p> <pre><code>package security; import java.io.IOException; import java.security.GeneralSecurityException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; public class CustomSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) throws IOException, ServletException { super.onAuthenticationSuccess(request, response, authentication); HttpSession session = request.getSession(true); try { if (CurrentUser.isUserInRole("USER")) { session.setAttribute("Flag", "user"); } } catch (Exception e) { logger.error("Error in getting User()", e); } } } </code></pre>
 

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