Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The best way to determine the target url based upon roles is to specify a target url in your Spring Security configuration as shown below. This will work in Spring 3.0 or 3.1</p> <pre><code>&lt;http&gt; ... &lt;form-login login-page="/login" default-target-url="/default"/&gt; &lt;/http&gt; </code></pre> <p>Then create a controller that processes the default-target-url. The controller should redirect or forward based upon rolls. Below is an example of using Spring MVC, but any type of controller will work (i.e. Struts, a Servlet, etc).</p> <pre><code>@Controller public class DefaultController { @RequestMapping("/default") public String defaultAfterLogin(HttpServletRequest request) { if (request.isUserInRole("ROLE_ADMIN")) { return "redirect:/users/sessions"; } return "redirect:/messages/inbox"; } } </code></pre> <p>The advantages to this approach are it is not coupled to any specific implementation of Security, it is not coupled to any specific MVC implementation, and it works easily with Spring Security namespace configuration. A full example can be found in the <a href="https://github.com/rwinch/spring-security-samples-securemail" rel="noreferrer">SecureMail</a> project I presented at SpringOne this year.</p> <p>An alternative is that you could create a custom <a href="http://static.springsource.org/spring-security/site/docs/3.1.x/reference/ns-config.html#ns-form-target" rel="noreferrer">AuthenticationSuccessHandler</a>. The implementation might extend SavedRequestAwareAuthenticationSuccessHandler which is the default AuthenticationSuccessHandler. it could then be wired using the namespace as shown below.</p> <pre><code>&lt;sec:http&gt; &lt;sec:form-login authentication-success-handler-ref="authSuccessHandler"/&gt; &lt;/sec:http&gt; &lt;bean:bean class="example.MyCustomAuthenticationSuccessHandler"/&gt; </code></pre> <p>I would not recommend doing this as it is tied to Spring Security API's and it is better to avoid that when possible.</p>
    singulars
    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.
    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