Search in sources :

Example 1 with ProgrammaticLogin

use of com.sun.enterprise.security.ee.auth.login.ProgrammaticLogin in project Payara by payara.

the class MEJBTest method main.

public static void main(String[] args) {
    try {
        final String mejbName = "java:global/mejb/MEJBBean";
        final String username = "admin";
        final String password = "";
        final String realm = "admin-realm";
        System.out.println("Authenticating with \"" + username + "\", \"" + password + "\"");
        final ProgrammaticLogin pm = new ProgrammaticLogin();
        pm.login(username, password, realm, true);
        println("Looking up: " + mejbName);
        final InitialContext initial = new InitialContext();
        final Object objref = initial.lookup(mejbName);
        final ManagementHome home = (ManagementHome) PortableRemoteObject.narrow(objref, ManagementHome.class);
        try {
            final ManagementHome home2 = (ManagementHome) objref;
        } catch (final Exception e) {
            println("WARNING: (ManagementHome)PortableRemoteObject.narrow(objref, ManagementHome.class) works, but (ManagementHome)objref does not!");
        }
        // println("ManagementHome: " + home + " for " + mejbName);
        final Management mejb = (Management) home.create();
        println("Got the MEJB");
        new MEJBTest(mejb).test();
        println("Calling mejb.remove()");
        mejb.remove();
    } catch (Exception ex) {
        System.err.println("Caught an unexpected exception!");
        ex.printStackTrace();
    }
    println("Exiting main() forcibly");
    System.exit(-1);
}
Also used : ManagementHome(javax.management.j2ee.ManagementHome) PortableRemoteObject(javax.rmi.PortableRemoteObject) Management(javax.management.j2ee.Management) ProgrammaticLogin(com.sun.enterprise.security.ee.auth.login.ProgrammaticLogin) InitialContext(javax.naming.InitialContext)

Example 2 with ProgrammaticLogin

use of com.sun.enterprise.security.ee.auth.login.ProgrammaticLogin in project Payara by payara.

the class EjbOverHttpResource method doInvoke.

private Object doInvoke(InvokeMethodRequest request, BiFunction<Type, InvokeMethodResponse, Object> resultMapper) throws Exception {
    return excuteInAppContext(request.jndiName, ejb -> {
        // resource will not be changed.
        if (!request.principal.isEmpty()) {
            new ProgrammaticLogin().login(base64Decode(request.principal), base64Decode(request.credentials), null, true);
        }
        Class<?>[] argTypes = toClasses(request.argTypes);
        Class<?>[] argActualTypes = toClasses(request.argActualTypes);
        Method method = findBusinessMethodDeclaration(ejb, request.method, argTypes);
        Object result = method.invoke(ejb, request.argDeserializer.deserialise(request.argValues, method, argActualTypes, Thread.currentThread().getContextClassLoader()));
        return resultMapper.apply(method.getGenericReturnType(), new InvokeMethodResponse(result));
    });
}
Also used : InvokeMethodResponse(fish.payara.ejb.http.protocol.InvokeMethodResponse) Method(java.lang.reflect.Method) ProgrammaticLogin(com.sun.enterprise.security.ee.auth.login.ProgrammaticLogin)

Example 3 with ProgrammaticLogin

use of com.sun.enterprise.security.ee.auth.login.ProgrammaticLogin in project Payara by payara.

the class InvokeEJBServlet method invokeBeanMethod.

private static Invocation invokeBeanMethod(String beanName, String methodName, JsonArray argTypeNames, JsonArray argValuesJson, String principal, String credentials) throws Exception {
    return excuteInAppContext(beanName, bean -> {
        // Servlet will not be changed.
        if (!principal.isEmpty()) {
            new ProgrammaticLogin().login(base64Decode(principal), base64Decode(credentials), null, true);
        }
        // Actually invoke the target EJB
        Invocation invocation = new Invocation(bean, methodName, argTypeNames);
        invocation.setArgs(argValuesJson);
        invocation.invoke();
        return invocation;
    });
}
Also used : ProgrammaticLogin(com.sun.enterprise.security.ee.auth.login.ProgrammaticLogin)

Aggregations

ProgrammaticLogin (com.sun.enterprise.security.ee.auth.login.ProgrammaticLogin)3 InvokeMethodResponse (fish.payara.ejb.http.protocol.InvokeMethodResponse)1 Method (java.lang.reflect.Method)1 Management (javax.management.j2ee.Management)1 ManagementHome (javax.management.j2ee.ManagementHome)1 InitialContext (javax.naming.InitialContext)1 PortableRemoteObject (javax.rmi.PortableRemoteObject)1