<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    security interceptor no access to ejb
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/gris12">ich selbst</a> in <i>JBoss AS 7 Development</i> - <a href="https://community.jboss.org/message/828132#828132">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>Hi</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>i'm currently new to Jboss development. I have implemented some REST services and now I want to secure them. I have implemented a SecurityInterceptor, but my problem is, I can't access my EJB's in this class.</p><p>Here ist the code of the interceptor:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; @EJB</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; KryptoManager kryptoManager;</span></p><p>&#160;&#160;&#160; </p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; @Override</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; public boolean accept(Class c, Method method) {</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (c == null || method == null) return false;</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; //class implementing rest service</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; return method.getName().equals("restService");</span></p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; }</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; @Override</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; public ServerResponse preProcess(HttpRequest request, ResourceMethod method)</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throws Failure, WebApplicationException {</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; ServerResponse response = null;</span></p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; String key = kryptoManager.getKryptoInformation();</span></p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; ...</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (error) {</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; response = new ServerResponse(LOGINURL, 403, new Headers&lt;Object&gt;());</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</span></p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160; </p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; return response;</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; }</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: arial,helvetica,sans-serif;">The kryptoManager always is null. I also used this method to access bean Information in a servlet and a REST service, were it is working fine. The bean access the database info and delivers them to the controlers, but in securityinterceptor this is not working, why?</span></p><p><span style="font-family: arial,helvetica,sans-serif;">Here is the rest my classes:</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The KryptoManager looks like:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">@Stateless</span></p><p><span style="font-family: courier new,courier;">public class KryptoManager {</span></p><p>&#160;&#160;&#160; </p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; @EJB</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; private KryptoDAO kryptoDAO;</span></p><p>&#160;&#160;&#160; </p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; public KryptoBean getKryptoInformation() {</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; return kryptoDAO.getKryptoInformation();</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; }</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">@Stateless</span></p><p><span style="font-family: courier new,courier;">public class KryptoDAO {</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160; @PersistenceContext(unitName = "adb", type = PersistenceContextType.TRANSACTION)</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160; private EntityManager entityManager;</span></p><p>&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160; </p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160; public KryptoBean getKryptoInformation() {</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; Query query = entityManager.createQuery("SELECT k FROM KryptoBean k");</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return (KryptoBean) query.getResultList().get(0);</span></p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160; }</span></p><p><span style="font-family: courier new,courier;">}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>And the Bean Class looks like:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">@XmlRootElement</span></p><p><span style="font-family: courier new,courier;">@Table(name = "krypto")</span></p><p><span style="font-family: courier new,courier;">@Entity(name = "KryptoBean")</span></p><p><span style="font-family: courier new,courier;">public class KryptoBean {</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; @Id</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; @Column(name = "idkrypto")</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; private int idkrypto;</span></p><p>&#160;&#160;&#160; </p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; @Column (name = "hmackey")</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; private String hmackey;</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; public int getIdkrypto() {</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; return idkrypto;</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; }</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; public void setIdkrypto(int idkrypto) {</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.idkrypto = idkrypto;</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; }</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; public String getHmackey() {</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; return hmackey;</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; }</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; public void setHmackey(String hmackey) {</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.hmackey = hmackey;</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; }</span></p><p>&#160;&#160;&#160; </p><p><span style="font-family: courier new,courier;">}</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>And the JaxRsActivator looks like:</p><p><span style="font-family: courier new,courier;">@ApplicationPath( "/rest" )</span></p><p><span style="font-family: courier new,courier;">public class JaxRsActivator extends Application</span></p><p><span style="font-family: courier new,courier;">{</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; @Override</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; public Set&lt;Class&lt;?&gt;&gt; getClasses() {</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; // TODO Auto-generated method stub</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; return super.getClasses();</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; }</span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; @Override</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; public Set&lt;Object&gt; getSingletons() {</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; // TODO Auto-generated method stub</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; return super.getSingletons();</span></p><p><span style="font-family: courier new,courier;">&#160;&#160;&#160; }</span></p><p>&#160;&#160;&#160; </p><p><span style="font-family: courier new,courier;">}</span></p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/828132#828132">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss AS 7 Development at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2225">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>