Best way to keep ldap in sync with sql database - django

We are using an LDAP for user administration and authorization/authentication for a set of applications.
But there are also some applications were we need to have the LDAP user/group data accessible in an sql db2.
I'm using django to connect all these datasources and I was planning to use django celery to keep the LDAP and db2 in sync, where LDAP should be leading.
The following applies:
- The db2 user/groups tables cannot be written to, except from the scheduled celery task.
- The ldap model and db2 model both use "userid" as the primary key.
- The db2 table will insert if a userid cannot be found, and update only the changed fields, which are different on ldap then are on db2.
I was thinking of hashing the fields on LDAP and DB2 into a saved field, to check if the objects are in sync?
But what are the best practices to keep data integrity in this example?

Related

How to Map table views of a legacy Database in Oracle to django models?

I am working on a project that requires connecting to an existing remote Oracle database. the problem is that the client has not given full access to the database. instead i'm only given accesss to some views(Relational Database View) of the database. the table names are not provided.
I'm able to perfrom raw sql queries to the legacydb in my django view.
But it would be very much more easier if i could generate the models for these views and use django ORM. is there any way to accomplish this? What I'm expecting is to use some commands like inspectdb to generate the models from the view provided by the oracle legacy database.

Wso2 Userstore migration from LDAP to DB (Custom user store)

We are using WSO2 identity server with LDAP as a user store. Now we would like to replace LDAP with database because of huge load (> 10 Millions) and growing. I have migrated the users but how tenant details in wso2 core database could be set with the new user store. That is the user store xml details are stored in their tenant table. How this could be migrated. Or what are all the changes, configurations, needs to be set in wso2 identity server level.
At the moment we don't have exact mechanism to migrate data from one DB type to another. What we have is upgrading one version to another using same DB.
But you can do this migrating data from an LDAP to any DB like MySQL manually. If you can write an shell script to convert LDAP data toa csv file, its easy for you to move to a MySQL like DB in one import command.
Furthermore, I was able to find out some similar articles which can help you to migrate content from LDAP to MySQL [2],[3],[4]
The table structures of DB types can be found from [1].
Once you migrate the data to JDBC, you can change the custom-userstore.xml file with new connection values and restart the server. If you changed your primary user store, you need to change the user store configurations in user-mgt.xml file.
Please let me know if you need further help in migrating.
[1]https://docs.wso2.com/display/IS550/Data+Dictionary
[2] https://social.msdn.microsoft.com/Forums/sqlserver/en-US/dfae020f-a3bf-4e9b-9614-eccf7890f8c6/how-to-extract-data-from-ldap-and-then-import-it-into-sql-database-for-quicker-retrieval?forum=transactsql
[3]Active Directory data into SQL table
[4] https://www.egnyte.com/blog/2014/01/how-we-migrated-millions-of-users-from-ldap-to-mysql-using-feature-flags/

Migrate users from database to another on Django

I already have an existing website running and want to transfer just the users (usernames, passwords and emails) to another database for a separate Django website as I am rebuilding it.
You can configure both databases in your django configuration file. select the user data from one database and then put the records in the other.
Multiple Databases in Django.
Moving an object from one database to another

Django multi-database, one model

In my Django project, I would like two databases but only one model.
For example, an expert database and an exploit database. The router allows me to write in the exploit database or the expert database according to the users groups and permissions.
But how to duplicate the project model (described in model.py) in both bases?
You need to run migrate on each database. Use this switch to specify the database:
--database DATABASE Nominates a database to synchronize. Defaults to the
"default" database.
DATABASE in this case is the settings key that you are using in your settings.py field to configure each database.

Using DB without modifying it - Django

I need to connect to a Postgresql server in my Django project. But I'm under strict instructions NOT to make any modifications to the database or tables.
If I'm not wrong, simply adding this DB to settings.py and running syncdb would create and add some django specific tables to the database.
How can I get around this issue? If I add another (local) sqlite DB to settings.py under default and my remote postresql server separately; can I be sure of Django not creating any tables in my server? I couldn't find this info in the documentation.
Thanks
Configure two databases in settings.py, and a create database router to route your queries to the appropriate database.
Route all the Django admin / users stuff to your sqlite database (make it the default database, and make sure that is indeed the one your router returns by default), and single out your application queries that need to go to the Postgres database.
Routers also have a method to locate a DB for writes and one for reads, so you can use this as a failsafe: just make sure db_for_write never returns your Postgres database, and you're good to go.