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