jsf 2 - Spring Security:redirection to a specific page based on roles in JSF -
i work jsf , spring security. use custom login page. have 2 roles : administrator , user. question how redirect different pages different roles. example if user administrator, redirected "dashboard_admin.jsf" , if simple user, redirected "dashboard_user.jsf".
this spring security file :
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:security="http://www.springframework.org/schema/security" 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-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> <security:http auto-config="true" use-expressions="true"> <security:intercept-url pattern="/pages/**" access="hasrole('role_admin')" /> <security:form-login login-page="/login.jsf" authentication-failure-url="/login.jsf?error=true" default-target-url="/pages/admin/dashboard_admin.jsf" /> <security:logout logout-success-url="/login.jsf" delete-cookies="jsessionid" invalidate-session="true" /> <security:session-management invalid-session-url="/login.jsf"> <security:concurrency-control max-sessions="1" error-if-maximum-exceeded="true" /> </security:session-management> </security:http> <security:authentication-manager alias="authenticationmanager"> <security:authentication-provider> <security:user-service> <security:user name="test" password="test" authorities="role_user" /> <security:user name="sam" password="sam" authorities="role_admin" /> </security:user-service> </security:authentication-provider> </security:authentication-manager>
this dologin method:
public string dologin() throws servletexception, ioexception { externalcontext context = facescontext.getcurrentinstance().getexternalcontext(); requestdispatcher dispatcher = ((servletrequest) context.getrequest()) .getrequestdispatcher("/j_spring_security_check?j_username=" + username + "&j_password=" + password); dispatcher.forward((servletrequest) context.getrequest(), (servletresponse) context.getresponse()); facescontext.getcurrentinstance().responsecomplete(); return null; }
i find easy solution without using spring security, , works good. ravi
Comments
Post a Comment