Hi, I want to show the user depending on his Role different pages. I saw different approaches to do this, but nothing really works for me. I guess I am doing something wrong.
Ok my actual approach looks like this :
In my Bean I am having this method to invoke /j_spring_security_check
Code:public String login() throws IOException{ FacesContext.getCurrentInstance().getExternalContext().dispatch("/j_spring_security_check"); FacesContext.getCurrentInstance().responseComplete(); return null; }
applicationContext-security.xml :
MyAuthenticationProcessingFilter.java :Code:<http entry-point-ref="loginUrlAuthenticationEntryPoint" auto-config='false'> <intercept-url pattern="/login.jsf" filters="none" /> <intercept-url pattern="/**" access="IS_AUTHENTICATED_REMEMBERED"/> <custom-filter position="FORM_LOGIN_FILTER" ref="customUsernamePasswordAuthenticationFilter"/> <logout /> </http> <beans:bean id="loginUrlAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint"> <beans:property name="loginFormUrl" value="/login.jsf"/> </beans:bean> <beans:bean id="customUsernamePasswordAuthenticationFilter" class="mywebapp.MyAuthenticationProcessingFilter" > <beans:property name="authenticationManager" ref="authenticationManager"/> <beans:property name="authenticationFailureHandler" ref="failureHandler"/> <beans:property name="authenticationSuccessHandler" ref="successHandler"/> </beans:bean> <beans:bean id="successHandler" class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"> <beans:property name="defaultTargetUrl" value="/success.jsf"/> </beans:bean> <beans:bean id="failureHandler" class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"> <beans:property name="defaultFailureUrl" value="/login.jsf?login_error=true"/> </beans:bean>
Code:public class MyAuthenticationProcessingFilter extends UsernamePasswordAuthenticationFilter{ @Override protected void successfulAuthentication(HttpServletRequest request,HttpServletResponse response, Authentication authResult)throws IOException, ServletException { super.successfulAuthentication(request, response, authResult); String role = authResult.getAuthorities().toString(); if(role.contains("ROLE_ADMIN")){ System.out.println("adminl"); // i want to redirect from here to admin.jsf } else if(role.contains("ROLE_USER")) { System.out.println("user"); } } }
Is this way right to determine which user is logged in and redirecting to the required page ?
Would be nice if someone can help me out of this hell
Incidentally I'm using Spring 3.0.5



Reply With Quote
