[jboss-dev-forums] [JBoss AS 7 Development] - security interceptor no access to ejb

ich selbst do-not-reply at jboss.com
Tue Jul 16 03:29:36 EDT 2013


ich selbst [https://community.jboss.org/people/gris12] created the discussion

"security interceptor no access to ejb"

To view the discussion, visit: https://community.jboss.org/message/828132#828132

--------------------------------------------------------------
Hi

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.
Here ist the code of the interceptor:

    @EJB
    KryptoManager kryptoManager;

    @Override
    public boolean accept(Class c, Method method) {
        if (c == null || method == null) return false;
        //class implementing rest service
        return method.getName().equals("restService");

    }

    @Override
    public ServerResponse preProcess(HttpRequest request, ResourceMethod method)
            throws Failure, WebApplicationException {
        ServerResponse response = null;

        String key = kryptoManager.getKryptoInformation();

        ...

        if (error) {
            response = new ServerResponse(LOGINURL, 403, new Headers<Object>());
        }


        return response;
    }

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?
Here is the rest my classes:


The KryptoManager looks like:

@Stateless
public class KryptoManager {

    @EJB
    private KryptoDAO kryptoDAO;

    public KryptoBean getKryptoInformation() {
        return kryptoDAO.getKryptoInformation();
    }

}

@Stateless
public class KryptoDAO {

     @PersistenceContext(unitName = "adb", type = PersistenceContextType.TRANSACTION)
     private EntityManager entityManager;


     public KryptoBean getKryptoInformation() {
         Query query = entityManager.createQuery("SELECT k FROM KryptoBean k");
         return (KryptoBean) query.getResultList().get(0);

     }
}

And the Bean Class looks like:

@XmlRootElement
@Table(name = "krypto")
@Entity(name = "KryptoBean")
public class KryptoBean {

    @Id
    @Column(name = "idkrypto")
    private int idkrypto;

    @Column (name = "hmackey")
    private String hmackey;

    public int getIdkrypto() {
        return idkrypto;
    }

    public void setIdkrypto(int idkrypto) {
        this.idkrypto = idkrypto;
    }

    public String getHmackey() {
        return hmackey;
    }

    public void setHmackey(String hmackey) {
        this.hmackey = hmackey;
    }

}

And the JaxRsActivator looks like:
@ApplicationPath( "/rest" )
public class JaxRsActivator extends Application
{

    @Override
    public Set<Class<?>> getClasses() {
        // TODO Auto-generated method stub
        return super.getClasses();
    }

    @Override
    public Set<Object> getSingletons() {
        // TODO Auto-generated method stub
        return super.getSingletons();
    }

}
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/828132#828132]

Start a new discussion in JBoss AS 7 Development at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2225]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-dev-forums/attachments/20130716/63292eaf/attachment.html 


More information about the jboss-dev-forums mailing list