Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Like Mike Braun answer suggest, this is <strong>not</strong> possible according to JavaEE specifications.</p> <p>And that is unfortunate. But, what is a little less unfortunate is that there is some code to do that kind of things (application-server specific), hidden in that application server implementation of <code>@RunAs</code>. In Glassfish, that particular code is in the <a href="http://www.jarvana.com/jarvana/view/org/glassfish/security/security/3.1.1/security-3.1.1-sources.jar!/com/sun/enterprise/security/auth/login/LoginContextDriver.java?format=ok" rel="nofollow"><code>com.sun.enterprise.security.auth.login.LoginContextDriver</code></a> class, and particularly in its <code>LoginContextDriver#loginPrincipal</code> method.</p> <p>So, to have one part of code using a specific principal, I defined an interface </p> <pre><code>public interface Sudoer { public &lt;Result&gt; Result sudo(String user, SudoOperation&lt;Result&gt; operation); } </code></pre> <p>which I implemented for Glassfish as so :</p> <pre><code>public class GlassfishSudoer implements Sudoer { @Override public &lt;Result&gt; Result sudo(String user, SudoOperation&lt;Result&gt; operation) { try { LoginContextDriver.loginPrincipal(user, "autocat"); return operation.perform(); } catch (Exception e) { throw new UnableToSudoException(e); } finally { LoginContextDriver.logout(); } } } </code></pre> <p>And when using it, the part which wants to have some code "sudoed" only has to provide an implementation of the SudoOperation, like</p> <pre><code> component.sudo(userLogin, new SudoOperation&lt;Void&gt;() { public Void perform() { /* do some sudoed code */ return null; } }); </code></pre> <p>Advantage of this method is that, provided the given application server has some code to handle <code>@RunAs</code>, you can use that code to implement your own sudoer (I'm thinking about extracting that into a sudo-ejb library ...).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload