How do you create an EJB search with application security?

I am trying to find EJB from a standalone Java application. I mean WebSphere Application Server 6.1, but if someone knows how to do this for another application server, this may lead me in the right direction.

What I am doing now:

        initialContext= new InitialContext(env);
    initialContext.lookup("");

    lc = new LoginContext("WSLogin", new WSCallbackHandlerImpl("wasadmin", "defaultWIMFileBasedRealm", "wasadmin"));
    lc.login();
    subject = lc.getSubject();
    WSSubject.setRunAsSubject(subject);

This does not work ... my object is still "/ UNAUTHENTICATED" and I get an error message when I try to find the EJB. I also specify the following parameters for VM when running the application:

-Dcom.ibm.CORBA.ConfigURL = "C: \ was \ profiles \ AppSrv01 \ properties \ sas.client.props" -Djava.security.auth.login.config = "C: \ was \ profiles \ AppSrv01 \ properties \ wsjaas_client.conf "

+3
1

WebSphere 6 EJB (Jersey-RESTful WAR), WebSphere; ,

     Properties prop = new Properties();

    prop.put("org.omg.CORBA.ORBClass", "com.ibm.CORBA.iiop.ORB");   
    prop.put("java.naming.factory.initial", "com.ibm.websphere.naming.WsnInitialContextFactory");
    prop.put("java.naming.provider.url", "corbaloc:iiop:localhost:9810");
    prop.put("com.ibm.CORBA.securityEnabled", "true");
    prop.put("com.ibm.CORBA.validateBasicAuth", "true");


    Context ctx;
    try {
        ctx = new InitialContext(prop);

        System.out.println("Resolved Inital Context");
        Object ejbHome = ctx.lookup("");
        System.out.println("Resolved Home OperationManagerEJB");
        logger.info("So far so good, tryining to Login ");
        LoginContext lc;
        lc = new LoginContext("WSLogin",new WSCallbackHandlerImpl("username","password"));
        lc.login();

        logger.info("Login Suceeded with omc_user");
        WSSubject.setRunAsSubject(lc.getSubject()); //This is one key call 
        logger.info("Setting the authorization sibject");

http://pic.dhe.ibm.com/infocenter/wasinfo/v6r1/index.jsp?topic=%2Fcom.ibm.websphere.express.doc%2Finfo%2Fexp%2Fae%2Frtrb_secprobs.html

http://pic.dhe.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=%2Fcom.ibm.websphere.express.doc%2Finfo%2Fexp%2Fae%2Fxsec_jaas.html

http://pic.dhe.ibm.com/infocenter/wasinfo/v6r0/index.jsp?topic=%2Fcom.ibm.websphere.express.doc%2Finfo%2Fexp%2Fae%2Fxsec_jaas.html

+1

Source: https://habr.com/ru/post/1708589/


All Articles