I am developing a JSF application with Apache Shiro. I assure the user of Shiro and redirect it to the home page, there is no problem with this. After authentication, when I try to access the login page, it does not redirect me to the home page. I can log in again, even if the user is already registered. I am doing a Programmatic Login , as BalusC mentioned in his blog post.
[main] credentialsMatcher = org.apache.shiro.authc.credential.PasswordMatcher myRealm = com.example.security.myRealm myRealm.credentialsMatcher = $credentialsMatcher securityManager.realms = $myRealm user = com.example.web.filter.FacesAjaxAwareUserFilter user.loginUrl = /login.xhtml [urls] /login.xhtml = user
This filter is written from a blog post.
public class FacesAjaxAwareUserFilter extends UserFilter { private static final String FACES_REDIRECT_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<partial-response><redirect url=\"%s\"></redirect></partial-response>"; @Override protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException { HttpServletRequest req = (HttpServletRequest) request; if ("partial/ajax".equals(req.getHeader("Faces-Request"))) { response.setContentType("text/xml"); response.setCharacterEncoding("UTF-8"); response.getWriter().printf(FACES_REDIRECT_XML, req.getContextPath() + getLoginUrl()); } else { super.redirectToLogin(request, response); } }
}
What is the problem and how can I redirect the user if she has already authenticated?
EDIT:. Now I use the PostConstruct annotation to redirect if the user has already authenticated. I am open to any good decision.
source share