JBoss Community

security interceptor no access to ejb

created by ich selbst in JBoss AS 7 Development - View the full discussion

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

Start a new discussion in JBoss AS 7 Development at Community