2014-05-16 3 views
0

Wildfly, primefaces 및 JAAS를 사용하여 응용 프로그램에 로그인 할 수없는 이유가 있습니다. Wildfly에서 작동하는 것을보고 싶기 때문에 JBoss 7 AS와 같은 다른 버전에서는이 기능을 사용하지 않았습니다.jaas가있는 Wildfly는 항상 로그인 오류가 발생합니다.

j_username에 admin, j_password에 1234를 사용하여 loggin을 시도한 후 로그인 오류 페이지로 리디렉션됩니다. 이유를 이해할 수 없습니다.

MD5 해시는 econding 그것이 작동하고 결론, 바로 내가이 JDNI를 ACESS 및 자바 코드에서 일부 querys를 실행할 수 있습니다 포스트 그레스

에서 생성 된 암호를 사용합니다.

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)

<h:form id="login" onsubmit="document.getElementById('login').action='j_security_check';" prependId="false"> 
    <ul class="nav navbar-nav navbar-right"> 
     <li>  
      <center> 
       <p:inputText name="j_username" placeholder="Usuario" style="margin-top:10px;margin-left:10px;" size="15" id="user" value="#{usuarioBean.usuario.usuario}" rendered="#{empty usuarioBean.usuarioLogado}"></p:inputText> 
      </center> 
     </li> 
     <li> 
      <center> 
       <p:inputText id="j_password" name="j_password" placeholder="Senha" style="margin-top:10px;margin-left:10px;" size="15" type="password" value="#{usuarioBean.usuario.senha}" rendered="#{empty usuarioBean.usuarioLogado}"></p:inputText> 
      </center> 
     </li> 
     <li> 
      <center> 
       <p:commandButton style="margin-top:10px;margin-left:10px;" value="Entrar" rendered="#{empty usuarioBean.usuarioLogado}" ajax="false"></p:commandButton> 
      </center> 
     </li> 
    </ul> 
</h:form> 

보스-의 web.xml :

<?xml version="1.0" encoding="UTF-8"?> 
<jboss-web> 
<security-domain>zephyrplace-security-domain</security-domain> 
</jboss-web> 

standalone.xml :

<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> 

POSTGRES :

01 23,516,
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'); 

의 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> 

답변

1

나는 또한 제이보스를 사용하고 난 독립-full.xml의 보안을 컨피그. 또한 rolesQuery에 나는 질의 결과의 이름에 대해 'Roles'를 주었다. 내 영어로 미안해. 이 방법은 설명하는 것이 좋습니다 :

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

그 이름이 필요하다고 생각합니다. 그것들은 제가 보는 차이입니다.