connect to different database without service builder in liferay - spring

I want to connect to different database (other than liferay default database) without service builder. Also I want to use spring jdbc template to fetch the data from database.

Related

How to configure database connection runtime in Spring Boot?

I made a new Spring Boot project using the Spring Initializr. I'm building an On-premise backend so what I'm trying to achieve is that when the user opens the jar executable and the server starts, he should be able to configure the database connection by going to localhost:8080/ in his web browser. Basically the index.html will have a form with 4 fields for IP Address, Database Name, UserName and Password. When the form is submitted spring will try to connect to the database with the provided information.
I have all my entities, repositories and controllers but currently the only way i can connect to a database is with the application.properties file, but since the user wont have access to the source, there should be a way for him to configure his database.
Thanks for your time!
I would suggest to use the Spring cloud Config server to store database related properties which is capable of picking up configuration at run time. Although it is typically configured with a Git repository, you can store them locally as pointed out in this thread.

Runtime database connection using Spring JDBC in Spring boot

I have a requirement wherein a user enters database connection details through a UI, and then from the application I connect to this database, extract the data, and import into my current application.
Users can enter any database connection information, hence these details are dynamic at a user level. I am using Spring boot and Spring JDBC currently, however I was looking for options to connect to other relational databases dynamically during runtime in order to extract data and import to my application database.

how to get tomcat session attribute from oracle

I have a web application made using Oracle Apex that implements the session management itself transparently, and I have implemented two-way SSL configuration in tomcat.
So my basic configuration is following
database: oracle 11g
application server: tomcat 7
apex 5.1
Now I need to add a token-based authentication so I have added a filter in the "ORDS" (Oracle Rest Data Service) configuration files and added a Java class. Now I have my token attribute added to the tomcat sessions:
But I need to access those attributes from inside my Oracle Database (in Java or PL/SQL) so I can do the authentication with it.
The Session.getAttribute doesn't seem to work there because all I have (sent via cookie) from tomcat session is just its jsessionid

Spring-boot JPA connect to postgres where database and schema are provided at runtime

I am building a multi-tenant application, where the tenant database configuration are stored in Redis. Based on the request, I will query the Redis to get the database and schema configured for that tenant, this application is built on spring boot.
I took a look at spring boot's JPA sample, and did some more google to find a suitable solution for this, unfortunately, I couldn't find one.
Is this really possible to use JPA sample provided here ?
https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-data-jpa
Please suggest me any other best possible way to tackle this problem
Thanks
Spring Data JPA uses JPA annotations to define domain model. These JPA entities define schema for your database. Obviously you can't change these entities, nor DB schema on runtime.
So no, updating schema on runtime is not possible with Spring Boot + Spring Data JPA combo.
Database connection (e.g. DB URL, username password) could be more flexible. You would need to create DataSource beans programmatically and somehow programatically define which data source to use for each query per tenant. But this wasn't requirement of Spring nor JPA ecosystem, therefore you may face lot of issues.
I was working on such system before, but we were using plain SQL queries via JDBC and were creating DB connection programatically to achieve schema changes on runtime.

Spring Security default database authentication schema

I've been working with the default database model provided by Spring Security to authenticate users. I've realized that Spring Security looks for these tables in the default schema configured for the database engine.
Now, suppose the following:
You are working with PostgreSQL and you have 2 schema: schemaOne and schemaTwo, where schemaOne is configured as the dafault one for the engine. Then, suppose that you have an application that uses schemaTwo, then you will need Spring Security database model to be in that schema. So, once you try to run your application, Spring Security will try to look for the authentication model in schemaOne.
So, my question is: is there a way to push Spring Security to use a different schema than the default one configured for the database engine?.
Thank you.
Well, you can configure custom JDBC queries, for example:
With XML - override authorities-by-username-query, etc.
With JavaConfig - set authoritiesByUsernameQuery(String), etc.
But, I don't think you can just set the schema name.

Resources