This content has been marked as final.
Show 1 reply
-
1. Re: AS6 LoginContext and PolicyContext
bwallis42 Jan 12, 2014 7:29 PM (in response to bwallis42)To answer my own question, PolicyContext doesn't seem to work outside of a JEE container.
So, I've wrapped my code that is executed from the RMI call inside a stateless EJB and authenticate before invoking the EJB using the "client-login" domain. Something like this is working:
InitialContext context = new InitialContext(); String jndiName = "udr-ear/EJBCommandExecuter/no-interface"; final EJBCommandExecuter executer = (EJBCommandExecuter) context.lookup(jndiName); LoginContext loginCtx = null; try { // This is usually set from a servlet filter (UserSessionFilter) for http connections, // we need to do it here using the client info from the RMI connection. Audit trail // log messages require that the client IP is available. UserSessionUtility.setCurrentUserIP(getClientHost()); LoginCallbackHandler handler = new LoginCallbackHandler(userName, password); loginCtx = new LoginContext("client-login", handler); loginCtx.login(); executer.execute(new EJBCommandObject() { @Override public void run() throws Exception { // execute code that requires JEE security setup } }); } finally { if(loginCtx != null) { loginCtx.logout(); } }
where EJBCommandObject is
public interface EJBCommandObject { public void run() throws Exception; }
and EJBCommandExecuter is
@Stateless @TransactionManagement(TransactionManagementType.BEAN) // legacy code manages its own transactions @SecurityDomain("CPF") public class EJBCommandExecuter { public void execute(EJBCommandObject object) throws Exception { object.run(); } }