ProgrammaticLogin doesnt work in arquillian tests

六眼飞鱼酱① 提交于 2019-12-10 21:39:05

问题


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());
    }

i'm getting the following exception:

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)

I've added a properties file users.properties that contains the login and the password.


回答1:


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.



来源:https://stackoverflow.com/questions/17649566/programmaticlogin-doesnt-work-in-arquillian-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!