Dynamically connect to an Oracle database for each JAX-RS request

2

I am developing a project in JBoss Seam to provide some services via JAX-RS in Wildfly 9.

The DBMS used is Oracle 10g, and the services that will be available are form features that the company develops in Oracle Forms.

The procedures, functions and triggers of the legacy system are strongly based on the oracle user variable, because of the audit.

This behavior (register the user who performed the operation) needs to be reflected in the Java services call I am developing.

There is already a parameter sent via header that has information about the user, so I already know which user will log in.

The question is to actually log in with that particular user, since the configuration of the project datasource uses a fixed user.

The datasource is configured in the standalone.xml file

<datasource jta="false" jndi-name="java:jboss/datasources/servicesDS" pool-name="servicesDS" enabled="true" use-ccm="false">
    <connection-url>jdbc:oracle:thin:@<IP>:<Porta>:<SID></connection-url>
    <driver-class>oracle.jdbc.OracleDriver</driver-class>
    <driver>ojdbc6.jar</driver>
    <security>
        <user-name><USER></user-name>
        <password><PASSWORD></password>
    </security>
</datasource>

... and in persistence.xml ...

<persistence-unit name="services">
    <jta-data-source>java:jboss/datasources/servicesDS</jta-data-source>
    <properties>
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.proc.param_null_passing" value="true" />
    </properties>
</persistence-unit>

To produce EntityManagers:

import java.util.logging.Logger;

import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.InjectionPoint;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

public class Resources {

    @Produces
    @PersistenceContext(unitName = "services")
    private EntityManager em;

    @Produces
    public Logger produceLog(InjectionPoint injectionPoint) {
        return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
    }

    @Produces
    @RequestScoped
    public FacesContext produceFacesContext() {
        return FacesContext.getCurrentInstance();
    }

}

I researched the internet and found something about Oracle Proxy, but there were only suggestions for using EclipseLink. However, the project has already been done with JPA / Hibernate.

Have you ever been in this situation (dynamically setting up the connection credentials for each service call)? If so, was it with JPA / Hibernate?

    
asked by anonymous 23.07.2018 / 14:15

0 answers