ProgrammaticLogin在Arquillian测试中不起作用 [英] ProgrammaticLogin doesnt work in arquillian tests
问题描述
我正在尝试在嵌入式玻璃鱼的Arquillian测试中使用ProgrammaticLogin类模拟登录. 我的代码如下:
I'm trying to simulate a login using the ProgrammaticLogin class in my arquillian tests in an embedded glassfish. my code is the following:
System.setProperty("java.security.auth.login.config","path/login.config")
com.sun.appserv.security.ProgrammaticLogin loginP = new ProgrammaticLogin();
try{
loginP.login("user1","password","fileRealm",true);
}
catch (Exception e){
System.out.println(e.getMessage());
}
我遇到以下异常:
SEVERE: SEC9050: Programmatic login failed
com.sun.enterprise.security.auth.login.common.LoginException: Login failed: Failed file login for user1.
at com.sun.enterprise.security.auth.login.LoginContextDriver.doPasswordLogin(LoginContextDriver.java:394)
at com.sun.enterprise.security.auth.login.LoginContextDriver.login(LoginContextDriver.java:240)
at com.sun.enterprise.security.auth.login.LoginContextDriver.login(LoginContextDriver.java:153)
at com.sun.appserv.security.ProgrammaticLogin$1.run(ProgrammaticLogin.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.appserv.security.ProgrammaticLogin.login(ProgrammaticLogin.java:168)
at com.sun.appserv.security.ProgrammaticLogin.login(ProgrammaticLogin.java:239)
at com.sun.appserv.security.ProgrammaticLogin.login(ProgrammaticLogin.java:211)
我添加了一个属性文件users.properties,其中包含登录名和密码.
I've added a properties file users.properties that contains the login and the password.
推荐答案
如果glassfish容器在其自己的进程中运行,则使用System.setProperty()定义的属性不可用.它仅在测试内部可用,该测试以不同的过程运行.也许您应该在部署中添加一个使用@PostConstruct设置属性的bean.
If the glassfish container runs in it's own process, the property you define using System.setProperty() is not available. It's only available inside the test, which runs in a different process. Maybe you should add a bean to your deployment that sets the property using @PostConstruct.
这篇关于ProgrammaticLogin在Arquillian测试中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!