0

I have a JDBC client calling a servlet.

Here's my client :

String query = "select * FROM Table";
int port = 8080;
String user = "user";
String password = "passwd";
String jdbcAvaticaURL = "jdbc:avatica:remote:url=http://localhost:"+port+";authentication=BASIC;serialization=JSON";
Connection connection = DriverManager.getConnection(jdbcAvaticaURL, user, password); // ,info);

executeQuery(connection,query);

connection.close();

And here's my servlet :

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    request.getParameter("user"); // returns NULL
    Enumeration<String> params = request.getParameterNames(); // Empty Collection
    response.setContentType("application/json;charset=utf-8");
    response.setStatus(HttpServletResponse.SC_OK);
    // DO THINGS
}

is there a way to retrieve the user and password from DriverManager.getConnection(jdbcAvaticaURL, user, password); in the servlet ?

I already tried String auth = request.getHeader("Authorization"); when I put the parameters in the JDBC URL, it's working, I can retrieve the user and the password, but this is not what I want.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Didi
  • 248
  • 2
  • 18
  • See if this one helps or not : [check this](https://stackoverflow.com/questions/3341563/javahow-to-pass-value-from-class-bean-to-servlet) – Amit Kumar Jun 21 '18 at 15:04
  • you could add it to the url: `YourServlet?user=xxx&password=xxx` – Jonathan Laliberte Jun 21 '18 at 17:13
  • @AmitKumar : This is interesting to know the structure it should have. However my problem is different, In my servlet I'm already connecting to JDBC number 2 to make database request. My JDBC number 1 is the one wanting to connect to the servlet to gather information from JDBC number 2. @JonathanLaliberte : I already said in my post that I managed to do it in the URL but this is not what I want. I want to retrieve the user and password from the `getConnection(jdbcURL, user, password)` but thanks for your help – Didi Jun 22 '18 at 06:26

1 Answers1

0

It's fine, after trying to get the attributes, parameters, etc... of the request, turns out the credentials were just in the request...

Doing this in the servlet let me access the user and password used for the connection in the client (after some JSON parsing) :

String myRequest = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));

Didi
  • 248
  • 2
  • 18