zk 集成jboss jaas

1.首先在login-config.xml配置中增加application-policy。

 

<application-policy name = "zkdemo">
       <authentication>
          <login-module code = "org.jboss.security.auth.spi.DatabaseServerLoginModule"
             flag = "required">
             <module-option name = "unauthenticatedIdentity">guest</module-option>
             <module-option name = "dsJndiName">java:/cnmds</module-option>
             <module-option name = "principalsQuery">SELECT LOGINPWD PASSWORD FROM WS_CUST_LOGIN  WHERE LOGINID=?</module-option>
             <module-option name = "rolesQuery">SELECT ROLENAME,'Roles' FROM VREL_PORTAL_ROLE  WHERE LOGINCODE=?</module-option>
             <module-option name="hashAlgorithm">MD5</module-option>
						 <module-option name="hashEncoding">base64</module-option>
          </login-module>
       </authentication>
    </application-policy>

 

 2.然后在项目中WEB-INF中增加jboss-web.xml

<jboss-web>
   <!-- Uncomment the security-domain to enable security. You will
      need to edit the htmladaptor login configuration to setup the
      login modules used to authentication users.
   -->
	 <class-loading java2ClassLoadingCompliance="false">
	   <loader-repository>
	      zkdemo:loader=zkdemo.war
	      <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
	   </loader-repository>
	 </class-loading>   
   <security-domain>java:/jaas/zkdemo</security-domain>
</jboss-web>

 3.在类中取登陆的用户名

 

final Execution exec = Executions.getCurrent();

if(exec.getUserPrincipal() != null){
    String loginId = exec.getUserPrincipal().getName();//取登陆的用户名

}

 

你可能感兴趣的:(Web,xml,jboss,Security,zk)