jaas通过wildfly

qaxu7uf2  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(217)

我想通过wildfly(8.2.0)在java应用程序中使用jaas身份验证。
我尝试了几种方法和配置…但是在登录(logincontext)时仍然出现错误。
我已经开始配置standalone.xml(wildfly):
使用jaas身份验证创建了一个新的安全领域“tprealm”:

<security-realm name="TPRealm">
     <authentication>
         <jaas name="TPLogin"/>
     </authentication>
</security-realm>

将域设置为默认值?:

<subsystem xmlns="urn:jboss:domain:remoting:2.0">
     <endpoint worker="default"/>
        <http-connector name="http-remoting-connector" connector-ref="default" security-realm="TPRealm"/>
</subsystem>

最后,我用登录模块创建了一个安全域“tplogin”:

<security-domain name="TPLogin" cache-type="default">
    <authentication>
        <login-module code="Database" flag="required">
            <module-option name="dsJndiName" value="java:jboss/datasources/TourPlanningDS"/>
            <module-option name="principalsQuery" value="select passwordHash from TaUser where login=?"/>
        </login-module>
    </authentication>
<security-domain>

在java中:

String username = "Admin";
String password = "admin";

PasswordClientCallbackHandler handler = new PasswordClientCallbackHandler(username, "TPRealm", password.toCharArray());

try {
      LoginContext loginContext = new LoginContext("TPRealm", handler);
      loginContext.login();
} catch (LoginException e) {
      System.out.println("Login failed");
      return;
}

在“newlogincontext(…)”中,我得到以下错误

javax.security.auth.login.LoginException: No LoginModules configured for TPRealm

我经常读到,需要一个配置文件(jaas.config):

TPRealm {
      org.jboss.security.auth.spi.TPLogin required;  // I dont know, what exactly have to stay here
}

我将此文件添加到system.properties。

System.setProperty("java.security.auth.login.config", jaasConfig)  //jaasConfig = path to file

有了这个,我可以编译“new logincontext(…)”,但是编译在logincontext.login()的下一行失败:

javax.security.auth.login.LoginException: unable to find LoginModule class: org.jboss.security.auth.spi.TPLogin

我还观看了wildfly的日志,希望在运行代码时记录任何内容,但没有记录任何内容。
在java应用程序中,我还添加了以下属性:

Properties ejbProps = new Properties();
ejbProps.put("endpoint.name", "client-endpoint");
ejbProps.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
ejbProps.put("remote.connections", "default");
ejbProps.put("remote.connection.default.host", "localhost");
ejbProps.put("remote.connection.default.port", "8080");                                                  
ejbProps.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");

EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(ejbProps);
ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(cc);
EJBClientContext.setSelector(selector);

我需要设置更多属性吗?我应该注意别的事情吗?
如果有人能帮我,我会很高兴的。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题