crm86
crm86

Reputation: 1394

Spring security with oracle credentials (datasource not from properties)

I am trying to find a solution that allows users the possibility to login with their database credentials.

At this moment, I am connecting with a “generic database user” and then I use a USERS table with username and password. I would like to eliminate this table and autheticate the username and password directly with Oracle.

EDIT: EXPLANATION

The users connect through our own user/password saved in a table in our database. However, the client wants to access the application using Oracle usernames. In other words, my current Spring config is established with a username/password for the root user (root root). With that scheme I can access the data inside the database. I autheticate the user/password against a users' table in the database to log users into the app. Nevertheless, I need a kind of pre-authentication that allows me to configure a dynamic datasource or not to config a datasource so users can get into the program with an external username and password (in my case, that would be Oracle ones).

Without Spring config, I can connect to the database every time I wish, because I must log in with a username and password every time I need to get the connection. How can I modify the static Spring datasource (configured by a properties file) to be able to config the datasource the first time the user logs into the platform and save it?

Is it possible?

This is my current connection against the TABLE on the database:

@Autowired
protected void configureGlobal(AuthenticationManagerBuilder registry) throws Exception, BadCredentialsException {
     registry
    .jdbcAuthentication()
    **.dataSource(dataSource)**
    .usersByUsernameQuery("select COD as principal, PASSWORD as credentials, 1 "
            + "from USUARIOS where COD = ?")
    .authoritiesByUsernameQuery("select ROLES_POR_USUARIO.COD, ROLES.NOMBRE "
                + "from ROLES_POR_USUARIO inner join ROLES "
                + "on ROLES.COD = ROLES_POR_USUARIO.COD "
                + "where ROLES_POR_USUARIO.COD = ?");
 }

The static datasource:

db.driver=oracle.jdbc.OracleDriver
db.url=my_oracle_url
db.username=database_user
db.password=database_user_pass

I would like to connect with as many db.username/db.password credentials as there are stored in the database

Thank you!

Upvotes: 1

Views: 874

Answers (1)

Neil McGuigan
Neil McGuigan

Reputation: 48246

Jasig CAS uses the BindModeSearchDatabaseAuthenticationHandler . It tries to connect to the database with the supplied username and password, and if that works, it considers the user to be authenticated.

So you could either use CAS (which Spring Security can integrate with), or implement something similar to BindModeSearchDatabaseAuthenticationHandler in your application.

Upvotes: 1

Related Questions