How to filter requests in EJB based web applications?

Krishna Chaitanya

we have a web application where we use a LDAP realm to authenticate the user. Then we have to check whether the authenticated user has permissions to open our application or not.

Our application has lots of applications/modules in it. All customer credentials are stored in a LDAP server. But customers will not have access to each and every application. They will purchase and then they get rights to use/access the application.

So I proposed using filters from the servlet api to do autherization part.

We are using EJB 3.0 to develop our service components and other components. Upon the EJB layer we have a REST layer meaning everyone has to access the EJBs from the web services. Is there any component in EJB which will be executed before accessing the EJBs or is there any component in REST which provide the same functionality?

Is it right to use a servlet filter in this case? Or Is there any better approach?

Thank you all in advance. Good day.

Nikos Paraskevopoulos

My suggestion is to secure the thing that must be secured: the implementation of business logic. The business logic resides in the EJBs, so my first option would be to secure this tier.

Why?

A day will come that someone will expose the business logic through another channel; it may be that some other application will need to access the EJBs through RMI; or as a SOAP web service; or whatever. If the security is implemented in the web tier, the other application will have unrestricted access to the logic, unless it has the good will to implement security.

How?

Several things come to mind.

  1. Simplest solution would be to map the rights to use a specific module to a role. When a user pays for that module, he/she is assigned that role. EJB methods will be protected to allow the appropriate set of roles to access them. Sample code:

    @Stateless
    public class ModuleOneBean implements ModuleOne
    {
        @Resource SessionContext ctx;
    
        public void businessMethod() {
            if( !ctx.isCallerInRole("moduleOneRole") ) {
                throw new SecurityException(...);
            }
    
            // business logic as usual
            ...
        }
    }
    
  2. If the authorization logic is more complex than that, EJB interceptors may be useful. They are like the servlet filters but for the EJB tier. A smart implementation of interceptor-based security infrastructure can cope with many more cases than the previous solution, including the case of role-based authorization. A simplified usage, roughly implementing the previous case with interceptors would be:

    @Stateless
    public class ModuleOneBean implements ModuleOne
    {
        @Interceptors(ModuleOneSecurityInterceptor.class)
        public void businessMethod() {
            // business logic as usual
            ...
        }
    }
    

    and:

    public class ModuleOneSecurityInterceptor
    {
        @Resource SessionContext ctx;
    
        @AroundInvoke
        public Object authorize(InvocationContext invctx) {
            if( !ctx.isCallerInRole("moduleOneRole") ) {
                throw new SecurityException(...);
            }
            return ctx.proceed();
        }
    }
    

    Note: Interceptors can also be declared in the ejb-jar.xml (the @Interceptors annotation is not necessary), so as not to burden the code and keep control centralized, especially for security.

  3. Custom solutions (e.g. this using CDI).


If you are pretty sure that the web app will be the only way to access the core, for ever, then a servlet filter will probably be OK. And you may need to add an extra layer of protection to the web app anyway.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to filter HTTP requests based on body before they get to the server?

From Dev

How to parse HTTP requests from a C based web server

From Dev

JPA How to apply filter to EJB criteriaquery

From Dev

What is the use of XML in web-based applications?

From Dev

jpa+ejb how to keep entity attached (managed) for multiple requests?

From Dev

How to perform consecutive web requests based on another request in one Mono in Spring WebFlux?

From Dev

How to throttle requests in a Web Api?

From Dev

How to throttle requests in a Web Api?

From Dev

How to filter in ReactiveX too frequent onSubscribe requests

From Dev

How to filter pull requests on GitHub by commentaries authors?

From Dev

How to filter pull requests on GitHub by commentaries authors?

From Dev

Inject EJB in Jersey filter

From Dev

How are database scenario based applications developed?

From Dev

How to write web applications using Ceylon?

From Dev

How to combine multiple Spring Boot web applications?

From Dev

How to unittest aiohttp.web applications

From Dev

How do Web Applications communicate with a server?

From Dev

How to integrate java applets into web applications

From Dev

how to test web applications for mobile devices on ubuntu?

From Dev

How to transfer data between different web applications

From Dev

How to handle and/or store money values in web applications?

From Java

How to filter a file based on datetime?

From Dev

Django how to filter based on ManyToManyField?

From Dev

How to filter elements based on XPATH?

From Dev

How to filter formulas based on dates?

From Dev

How to filter rows based on value?

From Dev

How to filter based on string in hive

From Dev

How to implement @NamedQuery in Java Web application using JSF and EJB

From Dev

How to direct DHCP requests based on IP

Related Related

  1. 1

    How to filter HTTP requests based on body before they get to the server?

  2. 2

    How to parse HTTP requests from a C based web server

  3. 3

    JPA How to apply filter to EJB criteriaquery

  4. 4

    What is the use of XML in web-based applications?

  5. 5

    jpa+ejb how to keep entity attached (managed) for multiple requests?

  6. 6

    How to perform consecutive web requests based on another request in one Mono in Spring WebFlux?

  7. 7

    How to throttle requests in a Web Api?

  8. 8

    How to throttle requests in a Web Api?

  9. 9

    How to filter in ReactiveX too frequent onSubscribe requests

  10. 10

    How to filter pull requests on GitHub by commentaries authors?

  11. 11

    How to filter pull requests on GitHub by commentaries authors?

  12. 12

    Inject EJB in Jersey filter

  13. 13

    How are database scenario based applications developed?

  14. 14

    How to write web applications using Ceylon?

  15. 15

    How to combine multiple Spring Boot web applications?

  16. 16

    How to unittest aiohttp.web applications

  17. 17

    How do Web Applications communicate with a server?

  18. 18

    How to integrate java applets into web applications

  19. 19

    how to test web applications for mobile devices on ubuntu?

  20. 20

    How to transfer data between different web applications

  21. 21

    How to handle and/or store money values in web applications?

  22. 22

    How to filter a file based on datetime?

  23. 23

    Django how to filter based on ManyToManyField?

  24. 24

    How to filter elements based on XPATH?

  25. 25

    How to filter formulas based on dates?

  26. 26

    How to filter rows based on value?

  27. 27

    How to filter based on string in hive

  28. 28

    How to implement @NamedQuery in Java Web application using JSF and EJB

  29. 29

    How to direct DHCP requests based on IP

HotTag

Archive