Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.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
Primefaces 带有jaas的Wildfly总是导致登录错误_Primefaces_Jaas_Java Ee 7_Wildfly_Postgresql 9.3 - Fatal编程技术网

Primefaces 带有jaas的Wildfly总是导致登录错误

Primefaces 带有jaas的Wildfly总是导致登录错误,primefaces,jaas,java-ee-7,wildfly,postgresql-9.3,Primefaces,Jaas,Java Ee 7,Wildfly,Postgresql 9.3,由于某些原因,我无法使用Wildfly、primefaces和JAAS在我的应用程序中登录。我没有在JBoss7等其他版本中尝试它,因为我想看到它在Wildfly上运行 在尝试使用管理员登录j_用户名和1234登录j_密码后,它会重定向到登录错误页面。我不明白为什么 MD5 hash econding使用postgres生成的密码是正确的 我可以访问这个JDNI并从java代码中执行一些查询,从而断定它是有效的 String DATASOURCE_CONTEXT = "java:jboss/da

由于某些原因,我无法使用Wildfly、primefaces和JAAS在我的应用程序中登录。我没有在JBoss7等其他版本中尝试它,因为我想看到它在Wildfly上运行

在尝试使用管理员登录j_用户名和1234登录j_密码后,它会重定向到登录错误页面。我不明白为什么

MD5 hash econding使用postgres生成的密码是正确的

我可以访问这个JDNI并从java代码中执行一些查询,从而断定它是有效的

String DATASOURCE_CONTEXT = "java:jboss/datasources/zephyrplace-ds";

        Connection result = null;
        try {
          Context initialContext = new InitialContext();
          if ( initialContext == null){
            System.out.println("JNDI problem. Cannot get InitialContext.");
          }
          DataSource datasource = (DataSource)initialContext.lookup(DATASOURCE_CONTEXT);
          if (datasource != null) {
            result = datasource.getConnection();
          }
          else {
            System.out.println("Failed to lookup datasource.");
          }
        }
        catch ( NamingException ex ) {
          System.out.println("Cannot get connection: " + ex);
        }
        catch(SQLException ex){
          System.out.println("Cannot get connection: " + ex);
        }
        return result;
login.xhtml(primefaces):

web.xml:

     <!-- Protected Areas -->
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Only admins</web-resource-name>
            <url-pattern>/admin/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>ADMIN</role-name>
        </auth-constraint>
    </security-constraint>
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Users and admins</web-resource-name>
            <url-pattern>/index/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>ADMIN</role-name>
            <role-name>USER</role-name>
        </auth-constraint>
    </security-constraint>


    <!-- Allowed Roles -->
    <security-role>
        <role-name>ADMIN</role-name>
    </security-role>
    <security-role>
        <role-name>USER</role-name>
    </security-role>


  <!-- Login Prompt -->   
  <login-config>           
       <auth-method>FORM</auth-method> 
       <form-login-config>  
            <form-login-page>/login/login.xhtml</form-login-page>  
            <form-error-page>/login/login-error.xhtml</form-error-page>  
       </form-login-config>  
  </login-config>  

只有管理员
/管理员/*
管理
用户和管理员
/索引/*
管理
使用者
管理
使用者
形式
/login/login.xhtml
/login/login-error.xhtml

在我的应用程序中,我还使用了wildfly,并在standalone-full.xml上配置了安全性。同样在rolesQuery中,我给了“Roles”作为查询结果的名称。对不起我的英语。这样更好地解释:

<module-option name="rolesQuery" value="select role_name, 'Roles' from user_roles where user_name = ?"/>

它认为它需要这个名字。这些就是我所看到的差异

<security-domains>
    <security-domain name="zephyrplace-security-domain" cache-type="default">
                        <authentication>
                            <login-module code="Database" flag="required">
                                <module-option name="dsJndiName" value="java:jboss/datasources/zephyrplace-ds"/>
                                <module-option name="principalsQuery" value="select pass from users where name=?"/>
                                <module-option name="rolesQuery" value="select role_name from user_roles where user_name = ?"/>
                                <module-option name="hashAlgorithm" value="MD5"/>
                                <module-option name="hashEncoding" value="base16"/>
                            </login-module>
                        </authentication>
                    </security-domain>
                </security-domains>
CREATE TABLE "users"
(
  "name" character varying(50),
  pass character varying(50)
)
WITH (
  OIDS=FALSE
);
ALTER TABLE "users" OWNER TO postgres;

CREATE TABLE user_roles
(
  user_name character varying(50),
  role_name character varying
)
WITH (
  OIDS=FALSE
);
ALTER TABLE user_roles OWNER TO postgres;

INSERT INTO users("name", pass) VALUES ('admin', MD5('1234'));
INSERT INTO user_roles(user_name, role_name) VALUES ('admin', 'ADMIN');
     <!-- Protected Areas -->
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Only admins</web-resource-name>
            <url-pattern>/admin/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>ADMIN</role-name>
        </auth-constraint>
    </security-constraint>
    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Users and admins</web-resource-name>
            <url-pattern>/index/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
            <role-name>ADMIN</role-name>
            <role-name>USER</role-name>
        </auth-constraint>
    </security-constraint>


    <!-- Allowed Roles -->
    <security-role>
        <role-name>ADMIN</role-name>
    </security-role>
    <security-role>
        <role-name>USER</role-name>
    </security-role>


  <!-- Login Prompt -->   
  <login-config>           
       <auth-method>FORM</auth-method> 
       <form-login-config>  
            <form-login-page>/login/login.xhtml</form-login-page>  
            <form-error-page>/login/login-error.xhtml</form-error-page>  
       </form-login-config>  
  </login-config>  
<module-option name="rolesQuery" value="select role_name, 'Roles' from user_roles where user_name = ?"/>