如何限制对未登录用户的某些页面的访问? (JSF 2.0)

| 我正在实现自己的身份验证机制,我想知道我在做什么,如果正确,那么我怎么能正确地做到这一点。 首先请解释一下我的身份验证机制如何工作: -我的用户的详细信息位于一个名为Role的对象内。该对象包含3个字段: 电子邮件:
String
密码:
String
userType:
Enum
-当用户访问系统时,对象角色将保存到会话中。 我的问题是:如何根据用户的“ 3”字段来限制对某些页面的访问? 这是我的工作,但不起作用。 首先,我有一个托管bean,它检查usser是否已记录。
@ManagedBean
@RequestScoped
public class SecurityController {

    //Some attributes...


    public String redirectNotBuyer() {
        Role role = (Role) FacesContext.getCurrentInstance()
                .getExternalContext().getSessionMap().get(\"userRole\");
        //Checks if user is logged
        if (role == null) {         
            // Please login
            //Add message to authentification
            return \"login.xhtml\";           
        } else if (role != null) {
            if (!role.getType().toString().equalsIgnoreCase(\"BUYER\")) {
                // Buyer not authorized
                return \"main.xhtml\";
            }
        }       
        return null;
    }

    public String redirectNotSeller() {
        Role role = (Role) FacesContext.getCurrentInstance()
                .getExternalContext().getSessionMap().get(\"userRole\");
        if (role == null) {
            // Please login
            //Add message to authentification
            return \"login.xhtml\";           
        } else if (role != null) {
            if (!role.getType().toString().equalsIgnoreCase(\"SELLERs\")) {
                // Buyer not authorized
                return \"main.xhtml\";
            }
        }       
        return null;
    }

//Getters, setters...
如果用户不是买方,而用户不是卖方,则上述两种方法会重定向。 所以现在我要做的是在我不希望用户进入的页面中,我调用了这些方法之一,因此用户被重定向到了主页。 示例:未经授权的用户输入一个名为buyOffer.xhtml的页面,只有买方可以访问:
<html xmlns=\"http://www.w3.org/1999/xhtml\"
    xmlns:ui=\"http://java.sun.com/jsf/facelets\"
    xmlns:h=\"http://java.sun.com/jsf/html\"
    xmlns:f=\"http://java.sun.com/jsf/core\">


<ui:composition template=\"WEB-INF/templates/BasicTemplate.xhtml\">
    <!-- THE REGISTRATION FORM -->
    <ui:define name=\"buyOfferForm\">
       <h2>Buy offer</h2>
       #{SecurityController.redirectNotBuyer()}
    </ui:define>            
</ui:composition>

</html>
出于某种原因,当我以未登录用户或不具有BUYER作为userType的用户访问此页面时,它不会重定向到main.xhtml页面。这是为什么?     
已邀请:
适当的机制是使用ѭ6。 看到 jsf中的基本安全性     

要回复问题请先登录注册