Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在JBoss/JAAS中使用HTTP Request.login_Java_Security_Java Ee 6_Jaas_Jboss6.x - Fatal编程技术网

Java 在JBoss/JAAS中使用HTTP Request.login

Java 在JBoss/JAAS中使用HTTP Request.login,java,security,java-ee-6,jaas,jboss6.x,Java,Security,Java Ee 6,Jaas,Jboss6.x,我已经成功地设置了JBoss安全域,并且可以使用基本身份验证(如web.xml中定义的)进行身份验证。这一切都很好。但是,我不知道如何使用http request.login方法 以下安全域(来自jboss web.xml)用于基本身份验证: <jboss-web> <context-root>/myapp</context-root> <security-domain>java:/jaas/myapp-realm</

我已经成功地设置了JBoss安全域,并且可以使用基本身份验证(如web.xml中定义的)进行身份验证。这一切都很好。但是,我不知道如何使用http request.login方法

以下安全域(来自jboss web.xml)用于基本身份验证:

<jboss-web>  
    <context-root>/myapp</context-root>  
    <security-domain>java:/jaas/myapp-realm</security-domain>  
</jboss-web> 
我得到以下例外情况:

javax.servlet.ServletException: Failed to authenticate a principal
我知道username/pasword很好(使用basicauth可以很好地工作)。我有跟踪级别的登录,而且看起来它甚至没有尝试进行身份验证。我错过了什么


查看是否需要有关我的设置/配置的更多详细信息。我正在使用JBoss6。

它现在正在工作。我确保了基于表单的身份验证有效,一旦有效,我又回到使用request.login,它就有效了?!我通过JRebel使用热部署,因此我可能已经使用BASIC auth进行了身份验证,它在我的会话中留下了一个用户主体,这导致request.login失败(如果您已经通过身份验证,request.login会引发异常)。我发誓我已经硬重启了JBoss,但这是我能想到的唯一合乎逻辑的事情

现在,我对登录名进行了健全检查,如下所示:

public void login() {
    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
    try {
        Principal userPrincipal = request.getUserPrincipal();
        if (request.getUserPrincipal() != null) {
            request.logout();
        }
        request.login(username, password);
        userPrincipal = request.getUserPrincipal();
        authUser = userDao.findByLogin(userPrincipal.getName());
    }
    catch (ServletException ex) {
        java.util.logging.Logger.getLogger(UserLogin.class.getName()).log(Level.SEVERE, null, ex);
    }
public void login() {
    FacesContext context = FacesContext.getCurrentInstance();
    HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();
    try {
        Principal userPrincipal = request.getUserPrincipal();
        if (request.getUserPrincipal() != null) {
            request.logout();
        }
        request.login(username, password);
        userPrincipal = request.getUserPrincipal();
        authUser = userDao.findByLogin(userPrincipal.getName());
    }
    catch (ServletException ex) {
        java.util.logging.Logger.getLogger(UserLogin.class.getName()).log(Level.SEVERE, null, ex);
    }